"""Experimental design of the dataset. Every episode belongs to one *cell* of a full factorial design over five factors: topology family × nominal size × traffic profile × load level × dynamics level Episode ``e`` maps deterministically to cell ``e mod n_cells`` and replicate ``e div n_cells``, so any prefix of the episode range — and therefore any partially generated or resumed dataset — covers all cells evenly. Replicates are assigned to train / validation / test splits (60 / 20 / 20). The level definitions below are the design; ``SimConfig`` selects which levels to generate. """ from __future__ import annotations from dataclasses import dataclass from itertools import product from typing import Dict, List, Tuple TOPOLOGIES = ("barabasi_albert", "watts_strogatz", "erdos_renyi", "waxman", "fat_tree") SIZES = (32, 64, 128, 256) # nominal node count (fat-tree: k = 4, 6, 8, 10 → 36, 99, 208, 375 nodes) SPLITS = ("train", "train", "train", "validation", "test") # by replicate mod 5 @dataclass(frozen=True) class TrafficProfile: """Two-state Markov-modulated Poisson process, parameterised by its mean rate m. With burst duty cycle d = mean_burst_steps / (mean_idle_steps + mean_burst_steps): idle_rate = m / ((1 − d) + d · peak_ratio), burst_rate = peak_ratio · idle_rate, so the long-run mean rate equals m for every profile. """ peak_ratio: float # burst_rate / idle_rate (1 = stationary Poisson) mean_idle_steps: float mean_burst_steps: float @property def duty(self) -> float: return self.mean_burst_steps / (self.mean_idle_steps + self.mean_burst_steps) def rates(self, mean_rate: float) -> Tuple[float, float]: idle = mean_rate / ((1.0 - self.duty) + self.duty * self.peak_ratio) return idle, self.peak_ratio * idle TRAFFIC_PROFILES: Dict[str, TrafficProfile] = { "poisson": TrafficProfile(peak_ratio=1.0, mean_idle_steps=100.0, mean_burst_steps=100.0), "microburst": TrafficProfile(peak_ratio=16.0, mean_idle_steps=100.0, mean_burst_steps=15.0), "sustained": TrafficProfile(peak_ratio=4.0, mean_idle_steps=100.0, mean_burst_steps=100.0), } # Offered load ρ = Σ_f m_f · hops_f / Σ_links capacity: the fraction of the network's directed link # capacity that the flows would occupy on their shortest paths. Per-flow mean rates m_f are log-normal # (σ = 0.75, "elephants and mice") and rescaled so that every episode meets its level exactly. LOAD_LEVELS: Dict[str, float] = { "light": 0.01, "moderate": 0.03, "heavy": 0.10, } RATE_SIGMA = 0.75 @dataclass(frozen=True) class Dynamics: link_failure_rate: float # per-step probability that a non-bridge link fails node_degradation_rate: float # per-step probability that a node degrades duration_range: Tuple[int, int] # event duration, steps factor_range: Tuple[float, float] # capacity multiplier of a degraded node's links DYNAMICS_LEVELS: Dict[str, Dynamics] = { "static": Dynamics(0.0, 0.0, (0, 0), (1.0, 1.0)), "moderate": Dynamics(0.002, 0.002, (50, 200), (0.1, 0.5)), "severe": Dynamics(0.01, 0.01, (100, 400), (0.1, 0.5)), } @dataclass(frozen=True) class Cell: topology: str size: int traffic_profile: str load_level: str dynamics_level: str @property def profile(self) -> TrafficProfile: return TRAFFIC_PROFILES[self.traffic_profile] @property def load(self) -> float: return LOAD_LEVELS[self.load_level] @property def dynamics(self) -> Dynamics: return DYNAMICS_LEVELS[self.dynamics_level] def cells(topologies, sizes, traffic_profiles, load_levels, dynamics_levels) -> List[Cell]: return [Cell(*levels) for levels in product(topologies, sizes, traffic_profiles, load_levels, dynamics_levels)] def locate(episode_id: int, n_cells: int) -> Tuple[int, int, str]: """(cell index, replicate, split) of an episode.""" replicate = episode_id // n_cells return episode_id % n_cells, replicate, SPLITS[replicate % len(SPLITS)]