Coverage for moptipyapps / prodsched / objectives / worst_fill_rate.py: 41%

17 statements  

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

1"""An objective function for maximizing the worst immediate rate.""" 

2 

3 

4from moptipy.api.objective import Objective 

5 

6from moptipyapps.prodsched.multistatistics import MultiStatistics 

7 

8 

9class WorstFillRate(Objective): 

10 """Compute the worst immediate rate and return `1 -` of it.""" 

11 

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

13 """ 

14 Get the negated worst immediate rate. 

15 

16 :param x: the multi-statistics 

17 :return: the worst stock level 

18 """ 

19 min_imm: int | float = 1 

20 for stat in x.per_instance: 

21 for sl in stat.immediate_rates: 

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

23 return 1 

24 min_imm = min(min_imm, sl) 

25 return 1 - min_imm 

26 

27 def lower_bound(self) -> int: 

28 """ 

29 Get the lower bound of the inverted minimum immediate rate. 

30 

31 :retval 0: always 

32 """ 

33 return 0 

34 

35 def upper_bound(self) -> int: 

36 """ 

37 Get the upper bound of the inverted minimum immediate rate. 

38 

39 :retval 1: always 

40 """ 

41 return 1 

42 

43 def __str__(self) -> str: 

44 """ 

45 Get the name of the objective function. 

46 

47 :return: `worstFillRate` 

48 :retval "worstFillRate": always 

49 """ 

50 return "worstFillRate"