Coverage for moptipyapps / prodsched / objectives / worst_and_mean_fill_rate.py: 41%
17 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"""Maximize the worst and average immediate rates."""
4from moptipy.api.objective import Objective
6from moptipyapps.prodsched.multistatistics import MultiStatistics
9class WorstAndMeanFillRate(Objective):
10 """Compute the worst immediate rate and return `1 -` of it."""
12 def evaluate(self, x: MultiStatistics) -> int | float:
13 """
14 Get the negated worst immediate rate.
16 :param x: the multi-statistics
17 :return: the worst stock level
18 """
19 min_imm: int | float = 1
20 avg_imm: int | float = 1
21 for stat in x.per_instance:
22 for sl in stat.immediate_rates:
23 min_imm = 0 if sl is None else min(min_imm, sl)
24 avg_imm = 0 if stat.immediate_rate is None else min(
25 avg_imm, stat.immediate_rate)
26 return (1 - min_imm) * 100 + (1 - avg_imm)
28 def lower_bound(self) -> int:
29 """
30 Get the lower bound of the inverted minimum immediate rate.
32 :retval 0: always
33 """
34 return 0
36 def upper_bound(self) -> int:
37 """
38 Get the upper bound of the inverted minimum immediate rate.
40 :retval 1: always
41 """
42 return 101
44 def __str__(self) -> str:
45 """
46 Get the name of the objective function.
48 :return: `worstMinAndMeanFillRate`
49 :retval "worstMinAndMeanFillRate": always
50 """
51 return "worstAndMeanFillRate"