Coverage for moptipyapps / prodsched / objectives / max_stocklevel.py: 44%

16 statements  

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

1"""An objective function for minimizing the maximal stocklevel.""" 

2 

3from math import inf 

4 

5from moptipy.api.objective import Objective 

6 

7from moptipyapps.prodsched.multistatistics import MultiStatistics 

8 

9 

10class MaxStockLevel(Objective): 

11 """Compute the worst stock level.""" 

12 

13 def evaluate(self, x: MultiStatistics) -> int | float: 

14 """ 

15 Get the worst (largest) stocklevel. 

16 

17 :param x: the multi-statistics 

18 :return: the worst stock level 

19 """ 

20 max_sl: int | float = 0 

21 for stat in x.per_instance: 

22 sl = stat.stock_level 

23 if (sl is None) or not (0 <= sl <= 1_000_000_000): 

24 return inf 

25 max_sl = max(max_sl, sl) 

26 return max_sl 

27 

28 def lower_bound(self) -> int: 

29 """ 

30 Get the lower bound of the maximum storage level. 

31 

32 :retval 0: always 

33 """ 

34 return 0 

35 

36 def __str__(self) -> str: 

37 """ 

38 Get the name of the objective function. 

39 

40 :return: `maxStorageLevel` 

41 :retval "maxStorageLevel": always 

42 """ 

43 return "maxStorageLevel"