Coverage for moptipyapps / prodsched / rop_multisimulation.py: 55%

22 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-11 04:40 +0000

1""" 

2A simulator for multiple runs of the ROP scenario. 

3 

4Re-Order-Point (ROP) scenarios are such that for each product, a value `X` is 

5provided. Once there are no more than `X` elements of that product in the 

6warehouse, one new unit is ordered to be produced. 

7Therefore, we have `n_products` such `X` values. 

8 

9This module provides the functionality to simulate this scenario over multiple 

10instances. 

11""" 

12from typing import Final, Iterable 

13 

14import numpy as np 

15from moptipy.api.encoding import Encoding 

16from pycommons.types import type_error 

17 

18from moptipyapps.prodsched.instance import ( 

19 Instance, 

20) 

21from moptipyapps.prodsched.multistatistics import MultiStatistics 

22from moptipyapps.prodsched.rop_simulation import ROPSimulation 

23from moptipyapps.prodsched.statistics_collector import StatisticsCollector 

24 

25 

26class ROPMultiSimulation(Encoding): 

27 """A multi-simulation.""" 

28 

29 def __init__(self, instances: Iterable[Instance]) -> None: 

30 """ 

31 Instantiate the multi-statistics decoding. 

32 

33 :param instances: the packing instance 

34 """ 

35 if not isinstance(instances, Iterable): 

36 raise type_error(instances, "instances", Iterable) 

37 #: the statistics collectors 

38 col: Final[tuple[StatisticsCollector, ...]] = tuple( 

39 StatisticsCollector(inst) for inst in instances) 

40 #: the simulations and collectors 

41 self.__simulations: Final[tuple[tuple[ 

42 ROPSimulation, StatisticsCollector], ...]] = tuple( 

43 (ROPSimulation(inst, col[i]), col[i]) 

44 for i, inst in enumerate(instances)) 

45 

46 def decode(self, x: np.ndarray, y: MultiStatistics) -> None: 

47 """ 

48 Map a ROP setting to a multi-statistics. 

49 

50 :param x: the array 

51 :param y: the Gantt chart 

52 """ 

53 for i, (sim, col) in enumerate(self.__simulations): 

54 col.set_dest(y.per_instance[i]) 

55 sim.ctrl_reset() 

56 sim.set_rop(x) 

57 sim.ctrl_run() 

58 

59 def __str__(self) -> str: 

60 """ 

61 Get the name of this decoding. 

62 

63 :return: `"rms"` 

64 :rtype: str 

65 """ 

66 return "rms"