Coverage for moptipyapps/prodsched/mfc_generator.py: 89%

176 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-13 02:48 +0000

1""" 

2Methods for generating MFC instances. 

3 

4In the module :mod:`~moptipyapps.prodsched.instance`, we provide the class 

5:class:`~moptipyapps.prodsched.instance.Instance`. Objects of this class 

6represent a fully deterministic production scheduling scenario. They prescribe 

7demands (:class:`~moptipyapps.prodsched.instance.Demand`) arriving at fixed 

8points in time in the system and work stations that need fixed amounts of 

9work times per product during certain time periods. 

10This allows us to create fully reproducible simulations 

11(:mod:`~moptipyapps.prodsched.simulation`) that show what a factory would do 

12to satisfy the demands. 

13 

14But where does such instance data come from? 

15 

16In the existing research on material flow control, no such fixed instances 

17exist. We invented them. Instead, the existing research [1] uses fixed numbers 

18of products and machines, fixed routes of products through machines, and 

19random distributions to generate demands and work times. 

20 

21So we create the function :func:`~default_stations` that creates the standard 

22work time distributions for the standard work stations. We also create the 

23function :func:`~default_products` that creates the default distributions 

24for the default products. 

25 

26The function :func:`sample_mfc_instance` then creates a material flow instance 

27following these distributions based on a given random seed. 

28This allows us to create scenarios that follow the same structure and random 

29distributions as prescribed in the paper [1] by Thürer et al. 

30However, our instances are fully deterministic. 

31 

32Once could not create a certain number of such instances and average 

33performance metrics over simulations on them. This would likely yield metrics 

34of reasonable accuracy, while allowing us to reproduce, analyze, and trace 

35every single production decision if need be. 

36 

37>>> from moptipyapps.utils.sampling import Gamma 

38>>> inst = sample_mfc_instance([ 

39... Product(0, (0, 1), Gamma.from_alpha_beta(3, 0.26))], [ 

40... Station(0, Gamma.from_k_and_mean(3, 10)), 

41... Station(1, Gamma.from_k_and_mean(2, 10))], 

42... time_end_measure=100, seed=123) 

43 

44>>> inst.name 

45'mfc_1_2_100_0x7b' 

46 

47>>> inst.n_demands 

487 

49 

50>>> inst.demands 

51(Demand(arrival=5.213885878801001, deadline=5.213885878801001, demand_id=0,\ 

52 customer_id=0, product_id=0, amount=1, measure=False),\ 

53 Demand(arrival=25.872387132411287, deadline=25.872387132411287, demand_id=1,\ 

54 customer_id=1, product_id=0, amount=1, measure=False),\ 

55 Demand(arrival=43.062182155666896, deadline=43.062182155666896, demand_id=2,\ 

56 customer_id=2, product_id=0, amount=1, measure=True),\ 

57 Demand(arrival=49.817978344678004, deadline=49.817978344678004, demand_id=3,\ 

58 customer_id=3, product_id=0, amount=1, measure=True),\ 

59 Demand(arrival=58.21166922638016, deadline=58.21166922638016, demand_id=4,\ 

60 customer_id=4, product_id=0, amount=1, measure=True),\ 

61 Demand(arrival=69.09054693162531, deadline=69.09054693162531, demand_id=5,\ 

62 customer_id=5, product_id=0, amount=1, measure=True),\ 

63 Demand(arrival=88.804579148131, deadline=88.804579148131, demand_id=6,\ 

64 customer_id=6, product_id=0, amount=1, measure=True)) 

65 

66>>> len(inst.station_product_unit_times[0][0]) 

671600 

68 

69>>> len(inst.station_product_unit_times[1][0]) 

701600 

71 

72>>> inst.time_end_measure 

73100.0 

74 

75>>> inst.time_end_warmup 

7630.0 

77 

78>>> d = dict(inst.infos) 

79>>> del d["info_generated_on"] 

80>>> del d["info_generator_version"] 

81>>> d 

82{'info_generator': 'moptipyapps.prodsched.mfc_generator',\ 

83 'info_rand_seed_src': 'USER_PROVIDED',\ 

84 'info_rand_seed': '0x7b',\ 

85 'info_time_end_measure_src': 'USER_PROVIDED',\ 

86 'info_time_end_measure': '100',\ 

87 'info_time_end_warmup_src': 'SAMPLED',\ 

88 'info_time_end_warmup': '30',\ 

89 'info_name_src': 'SAMPLED',\ 

90 'info_product_interarrival_times[0]':\ 

91 'Erlang(k=3, theta=3.846153846153846)',\ 

92 'info_product_route[0]': 'USER_PROVIDED',\ 

93 'info_station_processing_time[0]':\ 

94 'Erlang(k=3, theta=3.3333333333333335)',\ 

95 'info_station_processing_time_window_length[0]': 'Const(v=0.125)',\ 

96 'info_station_processing_time[1]': 'Erlang(k=2, theta=5)',\ 

97 'info_station_processing_time_window_length[1]': 'Const(v=0.125)'} 

98 

99>>> inst = sample_mfc_instance(seed=23445) 

100>>> inst.name 

101'mfc_10_13_10000_0x5b95' 

102 

103>>> inst.n_demands 

1049922 

105 

106>>> len([dem for dem in inst.demands if dem.product_id == 0]) 

107959 

108 

109>>> len([dem for dem in inst.demands if dem.product_id == 1]) 

1101055 

111 

112>>> [len(k[0]) for k in inst.station_product_unit_times] 

113[160000, 160000, 0, 160000, 0, 0, 0, 0, 160000, 160000, 160000, 0, 0] 

114 

1151. Matthias Thürer, Nuno O. Fernandes, Hermann Lödding, and Mark Stevenson. 

116 Material Flow Control in Make-to-Stock Production Systems: An Assessment of 

117 Order Generation, Order Release and Production Authorization by Simulation 

118 Flexible Services and Manufacturing Journal. 37(1):1-37. March 2025. 

119 doi:<https://doi.org/10.1007/s10696-024-09532-2> 

120""" 

121import datetime as dt 

122from dataclasses import dataclass 

123from typing import Callable, Final, Iterable 

124 

125from moptipy.utils.nputils import ( 

126 rand_generator, 

127 rand_seed_generate, 

128) 

129from moptipy.utils.strings import sanitize_name 

130from numpy.random import Generator 

131from pycommons.math.int_math import try_int 

132from pycommons.strings.string_conv import num_to_str 

133from pycommons.types import check_int_range, type_error 

134 

135from moptipyapps.prodsched.instance import ( 

136 KEY_IDX_END, 

137 KEY_IDX_START, 

138 MAX_VALUE, 

139 Demand, 

140 Instance, 

141) 

142from moptipyapps.utils.sampling import ( 

143 AtLeast, 

144 Const, 

145 Distribution, 

146 Erlang, 

147 Gamma, 

148 Uniform, 

149) 

150from moptipyapps.version import __version__ 

151 

152#: the "now" function 

153__DTN: Final[Callable[[], dt.datetime]] = dt.datetime.now 

154 

155 

156#: The information key for interarrival times 

157INFO_PRODUCT_INTERARRIVAL_TIME_DIST: Final[str] = \ 

158 "info_product_interarrival_times" 

159 

160#: The generator key 

161INFO_GENERATOR: Final[str] = "info_generator" 

162#: The generator version 

163INFO_GENERATOR_VERSION: Final[str] = "info_generator_version" 

164#: When was the instance generated? 

165INFO_GENERATED_ON: Final[str] = "info_generated_on" 

166#: The information key for interarrival times 

167INFO_PRODUCT_ROUTE: Final[str] = "info_product_route" 

168#: a fixed structure 

169INFO_USER_PROVIDED: Final[str] = "USER_PROVIDED" 

170#: a sampled structure 

171INFO_SAMPLED: Final[str] = "SAMPLED" 

172#: The information key for the processing time distribution 

173INFO_STATION_PROCESSING_TIME: Final[str] = "info_station_processing_time" 

174#: The information key for the processing time window length distribution 

175INFO_STATION_PROCESSING_WINDOW_LENGTH: Final[str] = \ 

176 "info_station_processing_time_window_length" 

177#: the random seed 

178INFO_RAND_SEED: Final[str] = "info_rand_seed" 

179#: the random seed source 

180INFO_RAND_SEED_SRC: Final[str] = f"{INFO_RAND_SEED}_src" 

181#: the name source 

182INFO_NAME_SRC: Final[str] = "info_name_src" 

183#: the warmup time end 

184INFO_TIME_END_WARMUP: Final[str] = "info_time_end_warmup" 

185#: the source of the warmup time end 

186INFO_TIME_END_WARMUP_SRC: Final[str] = f"{INFO_TIME_END_WARMUP}_src" 

187#: the measurement time end 

188INFO_TIME_END_MEASURE: Final[str] = "info_time_end_measure" 

189#: the source of the measurement time end 

190INFO_TIME_END_MEASURE_SRC: Final[str] = f"{INFO_TIME_END_MEASURE}_src" 

191 

192 

193@dataclass(order=True, frozen=True) 

194class Product: 

195 """The product sampling definition.""" 

196 

197 #: the product ID 

198 product_id: int 

199 #: the routing of the product 

200 routing: tuple[int, ...] 

201 #: the interarrival distribution 

202 interarrival_times: Distribution 

203 

204 def __init__(self, product_id: int, routing: Iterable[int], 

205 interarrival_times: int | float | Distribution) -> None: 

206 """ 

207 Create the product sampling instruction. 

208 

209 :param product_id: the product id 

210 :param routing: the routing information 

211 :param interarrival_times: the interarrival time distribution 

212 """ 

213 object.__setattr__(self, "product_id", check_int_range( 

214 product_id, "product_id", 0, 1_000_000)) 

215 route: tuple[int, ...] = tuple(routing) 

216 n_route: int = tuple.__len__(route) 

217 if n_route <= 0: 

218 raise ValueError("Route cannot be empty!") 

219 for k in route: 

220 check_int_range(k, "station", 0, 1_000_000) 

221 object.__setattr__(self, "routing", route) 

222 object.__setattr__( 

223 self, "interarrival_times", AtLeast.greater_than_zero( 

224 interarrival_times).simplify()) 

225 

226 def log_info(self, infos: dict[str, str]) -> None: 

227 """ 

228 Log the sampling information of this product to the infos `dict`. 

229 

230 :param infos: the information dictionary 

231 """ 

232 key: Final[str] = f"{KEY_IDX_START}{self.product_id}{KEY_IDX_END}" 

233 infos[f"{INFO_PRODUCT_INTERARRIVAL_TIME_DIST}{key}"] = repr( 

234 self.interarrival_times) 

235 infos[f"{INFO_PRODUCT_ROUTE}{key}"] = INFO_USER_PROVIDED 

236 

237 

238@dataclass(order=True, frozen=True) 

239class Station: 

240 """The station sampling definition.""" 

241 

242 #: the product ID 

243 station_id: int 

244 #: the processing time distribution 

245 processing_time: Distribution 

246 #: the processing window distribution 

247 processing_windows: Distribution 

248 

249 def __init__( 

250 self, station_id: int, 

251 processing_time: int | float | Distribution, 

252 processing_windows: int | float | Distribution | None = None) \ 

253 -> None: 

254 """ 

255 Create the station sampling instruction. 

256 

257 :param station_id: the station id 

258 :param processing_time: the processing time distribution 

259 :param processing_windows: the processing time window length 

260 distribution 

261 """ 

262 object.__setattr__(self, "station_id", check_int_range( 

263 station_id, "station_id", 0, 1_000_000)) 

264 object.__setattr__( 

265 self, "processing_time", 

266 AtLeast.greater_than_zero(processing_time).simplify()) 

267 

268 if processing_windows is None: 

269 processing_windows = Const(1 / 8) 

270 object.__setattr__( 

271 self, "processing_windows", 

272 AtLeast.greater_than_zero(processing_windows).simplify()) 

273 

274 def log_info(self, infos: dict[str, str]) -> None: 

275 """ 

276 Log the sampling information of this product to the infos `dict`. 

277 

278 :param infos: the information dictionary 

279 """ 

280 key: Final[str] = f"{KEY_IDX_START}{self.station_id}{KEY_IDX_END}" 

281 infos[f"{INFO_STATION_PROCESSING_TIME}{key}"] = repr( 

282 self.processing_time) 

283 infos[f"{INFO_STATION_PROCESSING_WINDOW_LENGTH}{key}"] = repr( 

284 self.processing_windows) 

285 

286 

287def _sample_demands(random: Generator, 

288 products: Iterable[Product], 

289 time_end_warmup: int | float, 

290 time_end_measure: int | float)\ 

291 -> tuple[tuple[Demand, ...], int]: 

292 """ 

293 Sample demands using the default generator. 

294 

295 :param random: the random number generator 

296 :param products: the iterable of products 

297 :param time_end_warmup: the end of the warmup period 

298 :param time_end_measure: the end of the measurement period 

299 :return: the tuple with all demands 

300 """ 

301 demands: Final[list[Demand]] = [] 

302 current_id: int = 0 

303 for product in products: 

304 time: float = 0.0 

305 while True: 

306 until = product.interarrival_times.sample(random) 

307 time += until 

308 if time >= time_end_measure: 

309 break 

310 demands.append( 

311 Demand( 

312 arrival=time, 

313 deadline=time, 

314 demand_id=current_id, 

315 customer_id=current_id, 

316 product_id=product.product_id, 

317 amount=1, 

318 measure=time_end_warmup <= time, 

319 ), 

320 ) 

321 current_id += 1 

322 return tuple(sorted(demands)), current_id 

323 

324 

325# pylint: disable=R0914,R0912,R0915 

326def sample_mfc_instance(products: Iterable[Product] | None = None, 

327 stations: Iterable[Station] | None = None, 

328 time_end_warmup: int | float | None = None, 

329 time_end_measure: int | float | None = None, 

330 name: str | None = None, 

331 seed: int | None = None) -> Instance: 

332 """ 

333 Sample an MFC instance. 

334 

335 :param products: the products 

336 :param stations: the work stations 

337 :param time_end_warmup: the end of the warmup period 

338 :param time_end_measure: the end of the measurement period 

339 :param name: the instance name 

340 :param seed: the random seed, if any 

341 :return: the instance 

342 """ 

343 generator: str = str(__file__) 

344 idx: int = str.rfind(generator, "moptipyapps") 

345 if idx >= 0: 

346 generator = str.removesuffix(generator[idx:].replace("/", "."), ".py") 

347 else: 

348 generator = "mfc_generator" 

349 infos: Final[dict[str, str]] = { 

350 INFO_GENERATOR: generator, 

351 INFO_GENERATOR_VERSION: __version__, 

352 INFO_GENERATED_ON: str(__DTN()), 

353 } 

354 

355 if products is None: 

356 products = default_products() 

357 products = sorted(products) 

358 n_products: Final[int] = list.__len__(products) 

359 if n_products <= 0: 

360 raise ValueError(f"Cannot have {n_products} products.") 

361 

362 ids: Final[set[int]] = set() 

363 used_stations: Final[set[int]] = set() 

364 for product in products: 

365 if not isinstance(product, Product): 

366 raise type_error(product, "product", Product) 

367 ids.add(product.product_id) 

368 used_stations.update(product.routing) 

369 if (set.__len__(ids) != n_products) or ( 

370 max(ids) - min(ids) + 1 != n_products): 

371 raise ValueError("Inconsistent product ids.") 

372 

373 n_stations: Final[int] = set.__len__(used_stations) 

374 if not 0 < n_stations < 1_000_000: 

375 raise ValueError(f"Invalid number {n_stations} of stations.") 

376 if stations is None: 

377 if n_stations == 13: 

378 stations = default_stations() 

379 else: 

380 raise ValueError( 

381 "Can only use default settings with 13 stations, " 

382 f"but got {n_stations}.") 

383 

384 stations = sorted(stations) 

385 n_stations_real: int = list.__len__(stations) 

386 if n_stations_real != n_stations: 

387 raise ValueError( 

388 f"Products use {n_stations} stations," 

389 f" but {n_stations_real} are provided.") 

390 

391 ids.clear() 

392 for station in stations: 

393 if not isinstance(station, Station): 

394 raise type_error(station, "station", Station) 

395 ids.add(station.station_id) 

396 min_id: int = min(ids) 

397 max_id: int = max(ids) 

398 if (set.__len__(ids) != n_stations) or ( 

399 max_id - min_id + 1 != n_stations): 

400 raise ValueError("Inconsistent station ids.") 

401 if ids != used_stations: 

402 raise ValueError( 

403 f"Station ids are {min_id}...{max_id}, but products use " 

404 f"stations {sorted(used_stations)}.") 

405 

406 if seed is None: 

407 infos[INFO_RAND_SEED_SRC] = INFO_SAMPLED 

408 seed = rand_seed_generate() 

409 else: 

410 infos[INFO_RAND_SEED_SRC] = INFO_USER_PROVIDED 

411 if not isinstance(seed, int): 

412 raise type_error(seed, "seed", int) 

413 infos[INFO_RAND_SEED] = hex(seed) 

414 

415 if time_end_measure is None: 

416 time_end_measure = 10_000 if (time_end_warmup is None) or ( 

417 time_end_warmup <= 0) else max( 

418 time_end_warmup + 1, (10 * time_end_warmup) / 3) 

419 infos[INFO_TIME_END_MEASURE_SRC] = INFO_SAMPLED 

420 else: 

421 infos[INFO_TIME_END_MEASURE_SRC] = INFO_USER_PROVIDED 

422 time_end_measure = try_int(time_end_measure) 

423 if not 0 < time_end_measure < MAX_VALUE: 

424 raise ValueError( 

425 f"Invalid time_end_measure={time_end_measure}.") 

426 infos[INFO_TIME_END_MEASURE] = num_to_str(time_end_measure) 

427 

428 if time_end_warmup is None: 

429 time_end_warmup = (3 * time_end_measure) / 10 

430 infos[INFO_TIME_END_WARMUP_SRC] = INFO_SAMPLED 

431 else: 

432 infos[INFO_TIME_END_WARMUP_SRC] = INFO_USER_PROVIDED 

433 time_end_warmup = try_int(time_end_warmup) 

434 if not 0 <= time_end_warmup < time_end_measure: 

435 raise ValueError(f"Invalid time_end_warmup={time_end_warmup} " 

436 f"for time_end_measure={time_end_measure}.") 

437 infos[INFO_TIME_END_WARMUP] = num_to_str(time_end_warmup) 

438 

439 if name is None: 

440 infos[INFO_NAME_SRC] = INFO_SAMPLED 

441 s: str = num_to_str(time_end_measure).replace(".", "d") 

442 name = f"mfc_{n_products}_{n_stations}_{s}_{seed:#x}" 

443 else: 

444 infos[INFO_NAME_SRC] = INFO_USER_PROVIDED 

445 uname: str = sanitize_name(name) 

446 if uname != name: 

447 raise ValueError(f"Invalid name {name!r}.") 

448 

449 random: Final[Generator] = rand_generator(seed) 

450 

451 # sample the demands 

452 demands, current_id = _sample_demands( 

453 random, products, time_end_warmup, time_end_measure) 

454 

455 #: sample the working times 

456 production_times: Final[list[list[list[float]]]] = [] 

457 for station in stations: 

458 times: list[float] = [] 

459 time = 0.0 

460 while True: 

461 processing = station.processing_time.sample(random) 

462 window = station.processing_windows.sample(random) 

463 time += window 

464 times.extend((processing, time)) 

465 if time >= time_end_measure: 

466 break 

467 production_times.append([ 

468 times if station.station_id in product.routing else [] 

469 for product in products]) 

470 

471 # log the information 

472 for product in products: 

473 product.log_info(infos) 

474 for station in stations: 

475 station.log_info(infos) 

476 

477 return Instance( 

478 name=name, n_products=n_products, 

479 n_customers=current_id, n_stations=n_stations, 

480 n_demands=current_id, 

481 time_end_warmup=time_end_warmup, time_end_measure=time_end_measure, 

482 routes=(product.routing for product in products), 

483 demands=demands, warehous_at_t0=[0] * n_products, 

484 station_product_unit_times=production_times, 

485 infos=infos) 

486 

487 

488def __s1t0(s: Iterable[int]) -> tuple[int, ...]: 

489 """ 

490 Convert stations from 1 to 0-based index. 

491 

492 :param s: the stations 

493 :return: the index 

494 

495 >>> __s1t0((1, 2, 3)) 

496 (0, 1, 2) 

497 """ 

498 return tuple(x - 1 for x in s) 

499 

500 

501def default_products() -> tuple[Product, ...]: 

502 """ 

503 Create the default product sequence as used in [1]. 

504 

505 :return: the default product sequence 

506 

507 >>> default_products() 

508 (Product(product_id=0, routing=(0, 1, 3, 1, 8, 9, 10), \ 

509interarrival_times=Erlang(k=3, theta=3.3333333333333335)), \ 

510Product(product_id=1, routing=(0, 1, 4, 1, 7, 8, 9, 10), \ 

511interarrival_times=Erlang(k=2, theta=5)), \ 

512Product(product_id=2, routing=(0, 1, 5, 3, 1, 8, 11, 10), \ 

513interarrival_times=Uniform(low=5, high=15)), \ 

514Product(product_id=3, routing=(0, 1, 6, 3, 1, 8, 9, 10), \ 

515interarrival_times=Erlang(k=3, theta=3.3333333333333335)), \ 

516Product(product_id=4, routing=(0, 1, 3, 11, 1, 8, 1, 12), \ 

517interarrival_times=Erlang(k=4, theta=2.5)), \ 

518Product(product_id=5, routing=(0, 1, 4, 11, 1, 8, 6, 12), \ 

519interarrival_times=Erlang(k=2, theta=5)), \ 

520Product(product_id=6, routing=(0, 1, 5, 11, 1, 7, 1, 12), \ 

521interarrival_times=Erlang(k=4, theta=2.5)), \ 

522Product(product_id=7, routing=(0, 1, 2, 6, 3, 11, 1, 7, 5, 8, 1, 12), \ 

523interarrival_times=Uniform(low=5, high=15)), \ 

524Product(product_id=8, routing=(0, 1, 2, 4, 3, 5, 11, 1, 7, 1, 9, 5, 12), \ 

525interarrival_times=Erlang(k=4, theta=2.5)), \ 

526Product(product_id=9, routing=(0, 1, 2, 5, 1, 3, 11, 6, 1, 8, 10, 4, 12), \ 

527interarrival_times=Erlang(k=2, theta=5))) 

528 

529 Now we reproduce the data from Table 2 of the paper: 

530 

531 >>> for i, p in enumerate(default_products()): 

532 ... itat = p.interarrival_times 

533 ... s = str(itat) 

534 ... s = f"{i + 1}: {s[:s.index(',')]}, mean={itat.mean()})" 

535 ... s += f"; routing: {','.join(str(j + 1) for j in p.routing)}" 

536 ... print(s) 

537 1: Erlang(k=3, mean=10); routing: 1,2,4,2,9,10,11 

538 2: Erlang(k=2, mean=10); routing: 1,2,5,2,8,9,10,11 

539 3: Uniform(low=5, mean=10); routing: 1,2,6,4,2,9,12,11 

540 4: Erlang(k=3, mean=10); routing: 1,2,7,4,2,9,10,11 

541 5: Erlang(k=4, mean=10); routing: 1,2,4,12,2,9,2,13 

542 6: Erlang(k=2, mean=10); routing: 1,2,5,12,2,9,7,13 

543 7: Erlang(k=4, mean=10); routing: 1,2,6,12,2,8,2,13 

544 8: Uniform(low=5, mean=10); routing: 1,2,3,7,4,12,2,8,6,9,2,13 

545 9: Erlang(k=4, mean=10); routing: 1,2,3,5,4,6,12,2,8,2,10,6,13 

546 10: Erlang(k=2, mean=10); routing: 1,2,3,6,2,4,12,7,2,9,11,5,13 

547 

548 1. Matthias Thürer, Nuno O. Fernandes, Hermann Lödding, and Mark 

549 Stevenson. Material Flow Control in Make-to-Stock Production Systems: 

550 An Assessment of Order Generation, Order Release and Production 

551 Authorization by Simulation Flexible Services and Manufacturing 

552 Journal. 37(1):1-37. March 2025. 

553 doi: https://doi.org/10.1007/s10696-024-09532-2 

554 """ 

555 return ( 

556 Product(0, __s1t0((1, 2, 4, 2, 9, 10, 11)), 

557 Erlang.from_k_and_mean(3, 10)), 

558 Product(1, __s1t0((1, 2, 5, 2, 8, 9, 10, 11)), 

559 Erlang.from_k_and_mean(2, 10)), 

560 Product(2, __s1t0((1, 2, 6, 4, 2, 9, 12, 11)), 

561 Uniform(5, 15)), 

562 Product(3, __s1t0((1, 2, 7, 4, 2, 9, 10, 11)), 

563 Erlang.from_k_and_mean(3, 10)), 

564 Product(4, __s1t0((1, 2, 4, 12, 2, 9, 2, 13)), 

565 Erlang.from_k_and_mean(4, 10)), 

566 Product(5, __s1t0((1, 2, 5, 12, 2, 9, 7, 13)), 

567 Erlang.from_k_and_mean(2, 10)), 

568 Product(6, __s1t0((1, 2, 6, 12, 2, 8, 2, 13)), 

569 Erlang.from_k_and_mean(4, 10)), 

570 Product(7, __s1t0((1, 2, 3, 7, 4, 12, 2, 8, 6, 9, 2, 13)), 

571 Uniform(5, 15)), 

572 Product(8, __s1t0((1, 2, 3, 5, 4, 6, 12, 2, 8, 2, 10, 6, 13)), 

573 Erlang.from_k_and_mean(4, 10)), 

574 Product(9, __s1t0((1, 2, 3, 6, 2, 4, 12, 7, 2, 9, 11, 5, 13)), 

575 Erlang.from_k_and_mean(2, 10))) 

576 

577 

578def default_stations() -> tuple[Station, ...]: 

579 """ 

580 Create the default station sequence as used in [1]. 

581 

582 :return: the default product station 

583 

584 >>> default_stations() 

585 (Station(station_id=0, processing_time=Erlang(k=3, theta=0.26),\ 

586 processing_windows=Const(v=0.125)),\ 

587 Station(station_id=1, processing_time=Erlang(k=3, theta=0.12),\ 

588 processing_windows=Const(v=0.125)),\ 

589 Station(station_id=2, processing_time=Erlang(k=2, theta=1.33),\ 

590 processing_windows=Const(v=0.125)),\ 

591 Station(station_id=3,\ 

592 processing_time=AtLeast(lb=5e-324, d=Exponential(eta=1.06)),\ 

593 processing_windows=Const(v=0.125)),\ 

594 Station(station_id=4, processing_time=Erlang(k=3, theta=0.67),\ 

595 processing_windows=Const(v=0.125)),\ 

596 Station(station_id=5, processing_time=Erlang(k=4, theta=0.35),\ 

597 processing_windows=Const(v=0.125)),\ 

598 Station(station_id=6, processing_time=Erlang(k=3, theta=0.59),\ 

599 processing_windows=Const(v=0.125)),\ 

600 Station(station_id=7, processing_time=Erlang(k=3, theta=0.63),\ 

601 processing_windows=Const(v=0.125)),\ 

602 Station(station_id=8, processing_time=Erlang(k=2, theta=0.59),\ 

603 processing_windows=Const(v=0.125)),\ 

604 Station(station_id=9, processing_time=Erlang(k=3, theta=0.6),\ 

605 processing_windows=Const(v=0.125)),\ 

606 Station(station_id=10,\ 

607 processing_time=AtLeast(lb=5e-324, d=Exponential(eta=1.44)),\ 

608 processing_windows=Const(v=0.125)),\ 

609 Station(station_id=11, processing_time=Erlang(k=4, theta=0.29),\ 

610 processing_windows=Const(v=0.125)),\ 

611 Station(station_id=12, processing_time=Erlang(k=3, theta=0.48),\ 

612 processing_windows=Const(v=0.125))) 

613 

614 Now we reproduce the data from Table 3 of the paper: 

615 

616 >>> from moptipyapps.utils.sampling import Exponential, AtLeast 

617 >>> from numpy import array 

618 >>> from numpy.random import default_rng 

619 >>> g = default_rng(seed=11) 

620 >>> for i, p in enumerate(default_stations()): 

621 ... pti = p.processing_time 

622 ... if isinstance(pti, AtLeast): 

623 ... pti = pti.d 

624 ... use_pti = pti 

625 ... if isinstance(use_pti, Exponential): 

626 ... use_pti = Gamma(1, use_pti.eta) 

627 ... elif isinstance(use_pti, Erlang): 

628 ... use_pti = Gamma(use_pti.k, use_pti.theta) 

629 ... s = str(use_pti) 

630 ... vals = array([pti.sample(g) for _ in range(100000)]) 

631 ... cov = vals.std() / vals.mean() 

632 ... s = f"{i + 1}: {s}, {cov:.2f}; {use_pti.simplify() == pti}" 

633 ... print(s) 

634 1: Gamma(k=3, theta=0.26), 0.58; True 

635 2: Gamma(k=3, theta=0.12), 0.58; True 

636 3: Gamma(k=2, theta=1.33), 0.71; True 

637 4: Gamma(k=1, theta=1.06), 1.00; True 

638 5: Gamma(k=3, theta=0.67), 0.58; True 

639 6: Gamma(k=4, theta=0.35), 0.50; True 

640 7: Gamma(k=3, theta=0.59), 0.58; True 

641 8: Gamma(k=3, theta=0.63), 0.58; True 

642 9: Gamma(k=2, theta=0.59), 0.71; True 

643 10: Gamma(k=3, theta=0.6), 0.58; True 

644 11: Gamma(k=1, theta=1.44), 1.00; True 

645 12: Gamma(k=4, theta=0.29), 0.50; True 

646 13: Gamma(k=3, theta=0.48), 0.58; True 

647 

648 1. Matthias Thürer, Nuno O. Fernandes, Hermann Lödding, and Mark 

649 Stevenson. Material Flow Control in Make-to-Stock Production Systems: 

650 An Assessment of Order Generation, Order Release and Production 

651 Authorization by Simulation Flexible Services and Manufacturing 

652 Journal. 37(1):1-37. March 2025. 

653 doi: https://doi.org/10.1007/s10696-024-09532-2 

654 """ 

655 return ( 

656 Station(0, Gamma(3, 0.26)), 

657 Station(1, Gamma(3, 0.12)), 

658 Station(2, Gamma(2, 1.33)), 

659 Station(3, Gamma(1, 1.06)), 

660 Station(4, Gamma(3, 0.67)), 

661 Station(5, Gamma(4, 0.35)), 

662 Station(6, Gamma(3, 0.59)), 

663 Station(7, Gamma(3, 0.63)), 

664 Station(8, Gamma(2, 0.59)), 

665 Station(9, Gamma(3, 0.6)), 

666 Station(10, Gamma(1, 1.44)), 

667 Station(11, Gamma(4, 0.29)), 

668 Station(12, Gamma(3, 0.48)))