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
« 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."""
3from math import inf
5from moptipy.api.objective import Objective
7from moptipyapps.prodsched.multistatistics import MultiStatistics
10class MaxStockLevel(Objective):
11 """Compute the worst stock level."""
13 def evaluate(self, x: MultiStatistics) -> int | float:
14 """
15 Get the worst (largest) stocklevel.
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
28 def lower_bound(self) -> int:
29 """
30 Get the lower bound of the maximum storage level.
32 :retval 0: always
33 """
34 return 0
36 def __str__(self) -> str:
37 """
38 Get the name of the objective function.
40 :return: `maxStorageLevel`
41 :retval "maxStorageLevel": always
42 """
43 return "maxStorageLevel"