Coverage for moptipyapps / prodsched / rop_multisimulation.py: 92%
25 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-13 08:40 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-13 08:40 +0000
1"""
2A simulator for multiple runs of the ROP scenario.
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.
8A simulation in this scenario is implemented in
9:mod:`~moptipyapps.prodsched.rop_simulation` as class
10:class:`~moptipyapps.prodsched.rop_simulation.ROPSimulation`.
12This module here provides the functionality to simulate this ROP-approach
13over *multiple* instances (:class:`~moptipyapps.prodsched.instance.Instance`).
14It acts as an :class:`~moptipy.api.encoding.Encoding` that converts a re-order
15point into an instance of
16:class:`~moptipyapps.prodsched.multistatistics.MultiStatistics` which can then
17be used as basis to compute the values of (potentially multiple)
18objective functions, such as those given in package
19:mod:`~moptipyapps.prodsched.objectives`.
21Now, doing a multi-simulation is costly.
22It takes from half a second to several seconds.
23It is unlikely that we can do more than a million in any run of an
24optimization algorithm.
25Therefore, we use an internal caching mechanism to store all the input
26vectors and output statistics.
27This may consume quite some memory, but it might be faster.
29>>> from moptipyapps.prodsched.mfc_generator import sample_mfc_instance
30>>> from moptipyapps.prodsched.mfc_generator import Product
31>>> from moptipyapps.prodsched.mfc_generator import Station
32>>> from moptipyapps.utils.sampling import Gamma
33>>> from moptipyapps.prodsched.multistatistics import to_stream
35>>> inst1 = sample_mfc_instance(seed=100)
36>>> inst2 = sample_mfc_instance(seed=200)
38>>> instances = (inst1, inst2)
39>>> space = MultiStatisticsSpace(instances)
40>>> ms = ROPMultiSimulation(space)
42>>> x1 = np.array([4, 6, 3, 4, 4, 6, 3, 5, 6, 10])
43>>> y = space.create()
44>>> ms.decode(x1, y)
45>>> data = list(to_stream(y))
46>>> for s in data:
47... if "time" not in s:
48... print(s)
49-------- Instance 0: 'mfc_10_13_10000_0x64' -------
50stat;total;product_0;product_1;product_2;product_3;product_4;product_5;\
51product_6;product_7;product_8;product_9
52trp.min;5.2184145757182705;5.2184145757182705;8.901258396714184;\
539.297175556856018;7.298761505635412;8.93985302431065;12.606621860129053;\
547.656178022299173;20.904266810249283;19.5732602761791;20.522703426695443
55trp.mean;32.405411220867336;22.45718865883824;29.222031978321247;\
5625.136275651698107;25.884250065648388;27.37383814423524;32.10269885414455;\
5721.905835255853667;45.11627023942567;44.78387873021794;49.465651426661886
58trp.max;101.42283298962138;56.30942379913131;74.17811849023519;\
5958.955465373336665;60.209164983262326;60.66621167329777;74.4357130671624;\
6047.944841355481;83.29062031809917;96.5279603056706;101.42283298962138
61trp.sd;14.352456423754838;8.966715472534952;10.260311480773648;\
628.824583884361449;9.375043161957333;9.776116378207652;10.962890512009123;\
636.691465594834237;12.613587720623373;12.30244975508726;13.52381481631245
64cwt.min;0.026454757136889384;0.026454757136889384;2.30483638259102;\
650.054286282554130594;0.16648942892061314;0.1385205442725237;\
662.2444075501571206;0.16694429707604286;0.2360807359827959;0.2894682031374032;\
670.7020815078112719
68cwt.mean;8.296470547393602;4.437533958350662;12.615320110639914;\
694.7164029806433545;6.611310521050654;8.350460109042185;7.55452574755307;\
705.82304931358363;9.068938196877168;17.21719619156937;6.710247622764048
71cwt.max;37.76460269749805;11.383554877750612;25.02207987420161;\
7216.22657205109499;24.355088852856625;23.499199642416897;24.507644884798083;\
7327.834403782263507;29.068687291493006;37.76460269749805;12.188275706294007
74cwt.sd;8.072214752396842;3.8478370296451603;9.569679438559595;\
754.197433045217076;7.324722986150041;6.142260031783497;6.213481379280693;\
767.142777751769366;7.629569041217826;11.995928244823393;5.761419012759379
77fill.rate;0.9475719810915342;0.9673295454545454;0.9869565217391304;\
780.9121037463976945;0.9595808383233533;0.93033381712627;0.9775280898876404;\
790.9477401129943502;0.8531073446327684;0.9452449567723343;0.9957983193277311
80stocklevel.mean;29.106301317812118;2.760696025360742;4.137393715988243;\
811.5507610335648132;2.5500355305055966;2.3659654563794095;3.7559706390001586;\
821.811228677305335;1.5668982789103876;2.657874734996926;5.949477225800507
83fulfilled.rate;1;1;1;1;1;1;1;1;1;1;1
84-------- Instance 1: 'mfc_10_13_10000_0xc8' -------
85stat;total;product_0;product_1;product_2;product_3;product_4;product_5;\
86product_6;product_7;product_8;product_9
87trp.min;6.530138861169689;6.530138861169689;9.628902017961991;\
888.559079500931148;9.008831732480758;8.17345928487157;10.857776143797764;\
897.1989408754006945;20.221688833546978;20.764475417566246;18.683929092542712
90trp.mean;31.011119751546097;20.636089799689874;27.67447485260846;\
9123.897005119242046;24.208477302980572;25.25418917347286;29.761302044694876;\
9223.04493364417017;43.39775607053671;45.37848659776272;46.77244686997264
93trp.max;82.04580382289168;45.2064686844069;55.755010710267015;\
9447.241916696964836;46.46518160018422;56.86270345999128;58.305458902948885;\
9552.54891087334727;80.98768370429207;80.62246465566932;82.04580382289168
96trp.sd;12.96227404463328;6.684031626500774;7.995431160774385;\
977.132422793760531;7.239745166217043;8.109774006790918;8.249688118912145;\
987.915621083543569;10.500873112173776;10.750658149592526;10.934157433002026
99cwt.min;0.011249992165176081;0.5337058348654864;0.8014497560352538;\
1000.2827261678148716;1.4241222500077129;0.011249992165176081;7.901938969392177;\
1010.041148101390717784;0.08459428467904218;0.10726475210685749;
102cwt.mean;7.183224986008803;1.9535417603494485;0.8014497560352538;\
1034.619753737796203;9.370441335605987;7.744917661655692;7.901938969392177;\
1048.052111019031262;8.505184343659167;5.922113521223626;
105cwt.max;31.446190263142853;5.290086057329063;0.8014497560352538;\
10610.883639956720799;25.608040164921476;24.178558590047942;7.901938969392177;\
10731.446190263142853;21.35684648685401;16.312679904455308;
108cwt.sd;6.15364337829274;1.7473126971982065;;3.440991075922831;\
1096.485559248771155;6.715154696592823;;7.703968965710594;6.633960138504885;\
1103.8259446158453017;
111fill.rate;0.9628522630230573;0.9901408450704225;0.9985569985569985;\
1120.9544159544159544;0.9635343618513323;0.9702127659574468;0.998546511627907;\
1130.9175108538350217;0.9149855907780979;0.919831223628692;1
114stocklevel.mean;30.090461520030797;2.907712049060156;4.261495763524114;\
1151.6231331746350672;2.565318363579915;2.472060544282644;4.079218485848546;\
1161.786007080448915;1.7664180248890007;2.4348085700118425;6.194289463750593
117fulfilled.rate;1;1;1;1;1;1;1;1;1;1;1
119>>> y2 = space.create()
120>>> y2 = y2.from_stream(data)
121>>> for s in to_stream(y2):
122... if "time" not in s:
123... print(s)
124-------- Instance 0: 'mfc_10_13_10000_0x64' -------
125stat;total;product_0;product_1;product_2;product_3;product_4;product_5;\
126product_6;product_7;product_8;product_9
127trp.min;5.2184145757182705;5.2184145757182705;8.901258396714184;\
1289.297175556856018;7.298761505635412;8.93985302431065;12.606621860129053;\
1297.656178022299173;20.904266810249283;19.5732602761791;20.522703426695443
130trp.mean;32.405411220867336;22.45718865883824;29.222031978321247;\
13125.136275651698107;25.884250065648388;27.37383814423524;32.10269885414455;\
13221.905835255853667;45.11627023942567;44.78387873021794;49.465651426661886
133trp.max;101.42283298962138;56.30942379913131;74.17811849023519;\
13458.955465373336665;60.209164983262326;60.66621167329777;74.4357130671624;\
13547.944841355481;83.29062031809917;96.5279603056706;101.42283298962138
136trp.sd;14.352456423754838;8.966715472534952;10.260311480773648;\
1378.824583884361449;9.375043161957333;9.776116378207652;10.962890512009123;\
1386.691465594834237;12.613587720623373;12.30244975508726;13.52381481631245
139cwt.min;0.026454757136889384;0.026454757136889384;2.30483638259102;\
1400.054286282554130594;0.16648942892061314;0.1385205442725237;\
1412.2444075501571206;0.16694429707604286;0.2360807359827959;0.2894682031374032;\
1420.7020815078112719
143cwt.mean;8.296470547393602;4.437533958350662;12.615320110639914;\
1444.7164029806433545;6.611310521050654;8.350460109042185;7.55452574755307;\
1455.82304931358363;9.068938196877168;17.21719619156937;6.710247622764048
146cwt.max;37.76460269749805;11.383554877750612;25.02207987420161;\
14716.22657205109499;24.355088852856625;23.499199642416897;24.507644884798083;\
14827.834403782263507;29.068687291493006;37.76460269749805;12.188275706294007
149cwt.sd;8.072214752396842;3.8478370296451603;9.569679438559595;\
1504.197433045217076;7.324722986150041;6.142260031783497;6.213481379280693;\
1517.142777751769366;7.629569041217826;11.995928244823393;5.761419012759379
152fill.rate;0.9475719810915342;0.9673295454545454;0.9869565217391304;\
1530.9121037463976945;0.9595808383233533;0.93033381712627;0.9775280898876404;\
1540.9477401129943502;0.8531073446327684;0.9452449567723343;0.9957983193277311
155stocklevel.mean;29.106301317812118;2.760696025360742;4.137393715988243;\
1561.5507610335648132;2.5500355305055966;2.3659654563794095;3.7559706390001586;\
1571.811228677305335;1.5668982789103876;2.657874734996926;5.949477225800507
158fulfilled.rate;1;1;1;1;1;1;1;1;1;1;1
159-------- Instance 1: 'mfc_10_13_10000_0xc8' -------
160stat;total;product_0;product_1;product_2;product_3;product_4;product_5;\
161product_6;product_7;product_8;product_9
162trp.min;6.530138861169689;6.530138861169689;9.628902017961991;\
1638.559079500931148;9.008831732480758;8.17345928487157;10.857776143797764;\
1647.1989408754006945;20.221688833546978;20.764475417566246;18.683929092542712
165trp.mean;31.011119751546097;20.636089799689874;27.67447485260846;\
16623.897005119242046;24.208477302980572;25.25418917347286;29.761302044694876;\
16723.04493364417017;43.39775607053671;45.37848659776272;46.77244686997264
168trp.max;82.04580382289168;45.2064686844069;55.755010710267015;\
16947.241916696964836;46.46518160018422;56.86270345999128;58.305458902948885;\
17052.54891087334727;80.98768370429207;80.62246465566932;82.04580382289168
171trp.sd;12.96227404463328;6.684031626500774;7.995431160774385;\
1727.132422793760531;7.239745166217043;8.109774006790918;8.249688118912145;\
1737.915621083543569;10.500873112173776;10.750658149592526;10.934157433002026
174cwt.min;0.011249992165176081;0.5337058348654864;0.8014497560352538;\
1750.2827261678148716;1.4241222500077129;0.011249992165176081;7.901938969392177;\
1760.041148101390717784;0.08459428467904218;0.10726475210685749;
177cwt.mean;7.183224986008803;1.9535417603494485;0.8014497560352538;\
1784.619753737796203;9.370441335605987;7.744917661655692;7.901938969392177;\
1798.052111019031262;8.505184343659167;5.922113521223626;
180cwt.max;31.446190263142853;5.290086057329063;0.8014497560352538;\
18110.883639956720799;25.608040164921476;24.178558590047942;7.901938969392177;\
18231.446190263142853;21.35684648685401;16.312679904455308;
183cwt.sd;6.15364337829274;1.7473126971982065;;3.440991075922831;\
1846.485559248771155;6.715154696592823;;7.703968965710594;6.633960138504885;\
1853.8259446158453017;
186fill.rate;0.9628522630230573;0.9901408450704225;0.9985569985569985;\
1870.9544159544159544;0.9635343618513323;0.9702127659574468;0.998546511627907;\
1880.9175108538350217;0.9149855907780979;0.919831223628692;1
189stocklevel.mean;30.090461520030797;2.907712049060156;4.261495763524114;\
1901.6231331746350672;2.565318363579915;2.472060544282644;4.079218485848546;\
1911.786007080448915;1.7664180248890007;2.4348085700118425;6.194289463750593
192fulfilled.rate;1;1;1;1;1;1;1;1;1;1;1
195>>> x2 = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
196>>> ms.decode(x2, y)
197>>> for s in to_stream(y):
198... if "time" not in s:
199... print(s)
200-------- Instance 0: 'mfc_10_13_10000_0x64' -------
201stat;total;product_0;product_1;product_2;product_3;product_4;product_5;\
202product_6;product_7;product_8;product_9
203trp.min;7.663287715103252;7.663287715103252;9.095457148523565;\
2047.766240497990111;8.562181846958993;9.316040128631357;10.985466232731596;\
2057.918294809653162;21.60147394131036;17.547777378904357;21.955240879517987
206trp.mean;32.182938074849496;22.140701244808632;28.47300655868274;\
20725.03367526681401;25.540081292675946;27.45355145426555;31.790509174952756;\
20822.848381852082664;44.52135481443732;44.628532680799054;48.780078255964575
209trp.max;90.86353698620042;59.31124925844961;67.52985535834341;\
21053.98557871595767;59.61194121202789;59.45241944832833;67.31898313910006;\
21156.0614850141219;81.02729637887933;80.10102521519639;90.86353698620042
212trp.sd;13.55080270389196;8.168678848316368;9.338600023998156;\
2138.450479951599732;8.617636871353389;9.348284373344056;10.208637939870723;\
2147.518466597403155;10.930234897788171;10.544143459268716;12.157006455407252
215cwt.min;0.011910352755876374;0.052322628985166375;0.011910352755876374;\
2160.10146378360695962;0.0524298188602188;0.025453817918787536;\
2170.05183870049131656;0.019666362641146407;0.08505119605797518;\
2180.041104098391770094;0.35634199392734445
219cwt.mean;17.582567285448004;9.404399139690337;13.569942297813908;\
2209.604699962010896;10.98311819636398;13.02578680799254;16.36199335629276;\
2219.05433728777719;24.801083270074987;24.958902762745797;30.451958550810023
222cwt.max;77.9385378023253;38.626600188006705;53.98496252245468;\
22338.07134509071511;42.09266935074265;47.99381408201043;48.82502650356764;\
22444.910304177168655;61.19671763574479;61.32131436097461;77.9385378023253
225cwt.sd;12.680595891084934;6.984547071390763;9.43383821564051;\
2267.012918522038577;7.891903498485814;9.033444211571616;9.757435017677162;\
2277.598286359665955;11.356538993918976;11.731098098924933;14.099099363785335
228fill.rate;0.2175906030654634;0.40767045454545453;0.2492753623188406;\
2290.3314121037463977;0.3158682634730539;0.28156748911465895;\
2300.17134831460674158;0.3714689265536723;0.002824858757062147;\
2310.018731988472622477;0.0350140056022409
232stocklevel.mean;1.6302006108805502;0.3367466779925779;0.19929696858529114;\
2330.15581052878690257;0.27567206398796995;0.2210582880452966;\
2340.14995708383534714;0.261766524058465;0.00048013843604374936;\
2350.006324013813991379;0.02308832333866472
236fulfilled.rate;0.9982810485603781;0.9985795454545454;1;1;0.9985029940119761;\
2370.9985486211901307;0.9929775280898876;1;0.9971751412429378;\
2380.9985590778097982;0.9985994397759104
239-------- Instance 1: 'mfc_10_13_10000_0xc8' -------
240stat;total;product_0;product_1;product_2;product_3;product_4;product_5;\
241product_6;product_7;product_8;product_9
242trp.min;6.456526072982342;6.456526072982342;10.280447092151007;\
2436.8487732247867825;7.0104482929637015;6.928763679217354;10.310002410918969;\
2446.5546482603685945;18.98639893585596;20.305760878712135;19.684816736973517
245trp.mean;30.62233294764437;20.55618285379736;26.886775958390697;2\
2463.309369645366303;23.990410121167177;25.071330781848836;29.668457645437183;\
24722.39107965050359;43.25662277895463;44.56350867653903;46.348319919246514
248trp.max;78.42550095496154;50.8966871369812;54.1070436589971;\
24948.669180978890836;52.42258290758127;55.73600798325697;57.290713516881624;\
25053.713961902238225;78.26718994789553;78.42550095496154;76.74843649876311
251trp.sd;13.071194037915653;7.013910120253621;8.186009510157717;\
2527.519377794772064;7.702542096043028;8.526420667544688;8.8970364463244;\
2537.682875953156183;10.548987944489301;10.828886793958864;10.898005970008226
254cwt.min;0.0004850386339967372;0.00456283385574352;0.056539264354796614;\
2550.005326168571627932;0.008960725403085235;0.08762150885104347;\
2560.01698932920680818;0.0004850386339967372;0.2800049970701366;\
2570.31679782128776424;0.12185953505104408
258cwt.mean;16.459929680370593;8.156568809736969;12.374646871831668;\
2598.300740034967504;10.371317340036168;10.931842774336376;14.222659911890325;\
2609.16345905328603;23.137826511457558;25.434148525686762;27.66379761065284
261cwt.max;60.919637988946306;29.480300784184692;35.16766467176876;\
26236.653507062645986;39.00025180235298;45.453680537177206;43.580941370786604;\
26345.28946949821329;56.024945551713245;59.28160733189452;60.919637988946306
264cwt.sd;12.118506999914882;6.044408962707157;7.728932055062374;\
2656.268950876605313;7.854789647395754;7.732399117687471;8.863583544578608;\
2667.7525558824150504;11.241315012712777;12.118136175485233;12.596354952532373
267fill.rate;0.24110446911471678;0.44084507042253523;0.2712842712842713;\
2680.36182336182336183;0.3394109396914446;0.32340425531914896;\
2690.21075581395348839;0.4196816208393632;0.002881844380403458;\
2700.01969057665260197;0.025034770514603615
271stocklevel.mean;1.8113476672429796;0.3802859636659473;0.23439669327549575;\
2720.19451906423091544;0.2559188646462229;0.2206691076289149;0.1935442874513864;\
2730.3124656055438941;0.00017487014444265826;0.008074900603352099;\
2740.011298310052408007
275fulfilled.rate;0.9987190435525192;1;0.9985569985569985;1;1;1;1;1;\
2760.9985590778097982;0.9929676511954993;0.9972183588317107
278Now the caching kicks in:
280>>> x2 = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
281>>> ms.decode(x2, y)
282>>> for s in to_stream(y):
283... if "time" not in s:
284... print(s)
285-------- Instance 0: 'mfc_10_13_10000_0x64' -------
286stat;total;product_0;product_1;product_2;product_3;product_4;product_5;\
287product_6;product_7;product_8;product_9
288trp.min;7.663287715103252;7.663287715103252;9.095457148523565;\
2897.766240497990111;8.562181846958993;9.316040128631357;10.985466232731596;\
2907.918294809653162;21.60147394131036;17.547777378904357;21.955240879517987
291trp.mean;32.182938074849496;22.140701244808632;28.47300655868274;\
29225.03367526681401;25.540081292675946;27.45355145426555;31.790509174952756;\
29322.848381852082664;44.52135481443732;44.628532680799054;48.780078255964575
294trp.max;90.86353698620042;59.31124925844961;67.52985535834341;\
29553.98557871595767;59.61194121202789;59.45241944832833;67.31898313910006;\
29656.0614850141219;81.02729637887933;80.10102521519639;90.86353698620042
297trp.sd;13.55080270389196;8.168678848316368;9.338600023998156;\
2988.450479951599732;8.617636871353389;9.348284373344056;10.208637939870723;\
2997.518466597403155;10.930234897788171;10.544143459268716;12.157006455407252
300cwt.min;0.011910352755876374;0.052322628985166375;0.011910352755876374;\
3010.10146378360695962;0.0524298188602188;0.025453817918787536;\
3020.05183870049131656;0.019666362641146407;0.08505119605797518;\
3030.041104098391770094;0.35634199392734445
304cwt.mean;17.582567285448004;9.404399139690337;13.569942297813908;\
3059.604699962010896;10.98311819636398;13.02578680799254;16.36199335629276;\
3069.05433728777719;24.801083270074987;24.958902762745797;30.451958550810023
307cwt.max;77.9385378023253;38.626600188006705;53.98496252245468;\
30838.07134509071511;42.09266935074265;47.99381408201043;48.82502650356764;\
30944.910304177168655;61.19671763574479;61.32131436097461;77.9385378023253
310cwt.sd;12.680595891084934;6.984547071390763;9.43383821564051;\
3117.012918522038577;7.891903498485814;9.033444211571616;9.757435017677162;\
3127.598286359665955;11.356538993918976;11.731098098924933;14.099099363785335
313fill.rate;0.2175906030654634;0.40767045454545453;0.2492753623188406;\
3140.3314121037463977;0.3158682634730539;0.28156748911465895;\
3150.17134831460674158;0.3714689265536723;0.002824858757062147;\
3160.018731988472622477;0.0350140056022409
317stocklevel.mean;1.6302006108805502;0.3367466779925779;0.19929696858529114;\
3180.15581052878690257;0.27567206398796995;0.2210582880452966;\
3190.14995708383534714;0.261766524058465;0.00048013843604374936;\
3200.006324013813991379;0.02308832333866472
321fulfilled.rate;0.9982810485603781;0.9985795454545454;1;1;0.9985029940119761;\
3220.9985486211901307;0.9929775280898876;1;0.9971751412429378;\
3230.9985590778097982;0.9985994397759104
324-------- Instance 1: 'mfc_10_13_10000_0xc8' -------
325stat;total;product_0;product_1;product_2;product_3;product_4;product_5;\
326product_6;product_7;product_8;product_9
327trp.min;6.456526072982342;6.456526072982342;10.280447092151007;\
3286.8487732247867825;7.0104482929637015;6.928763679217354;10.310002410918969;\
3296.5546482603685945;18.98639893585596;20.305760878712135;19.684816736973517
330trp.mean;30.62233294764437;20.55618285379736;26.886775958390697;2\
3313.309369645366303;23.990410121167177;25.071330781848836;29.668457645437183;\
33222.39107965050359;43.25662277895463;44.56350867653903;46.348319919246514
333trp.max;78.42550095496154;50.8966871369812;54.1070436589971;\
33448.669180978890836;52.42258290758127;55.73600798325697;57.290713516881624;\
33553.713961902238225;78.26718994789553;78.42550095496154;76.74843649876311
336trp.sd;13.071194037915653;7.013910120253621;8.186009510157717;\
3377.519377794772064;7.702542096043028;8.526420667544688;8.8970364463244;\
3387.682875953156183;10.548987944489301;10.828886793958864;10.898005970008226
339cwt.min;0.0004850386339967372;0.00456283385574352;0.056539264354796614;\
3400.005326168571627932;0.008960725403085235;0.08762150885104347;\
3410.01698932920680818;0.0004850386339967372;0.2800049970701366;\
3420.31679782128776424;0.12185953505104408
343cwt.mean;16.459929680370593;8.156568809736969;12.374646871831668;\
3448.300740034967504;10.371317340036168;10.931842774336376;14.222659911890325;\
3459.16345905328603;23.137826511457558;25.434148525686762;27.66379761065284
346cwt.max;60.919637988946306;29.480300784184692;35.16766467176876;\
34736.653507062645986;39.00025180235298;45.453680537177206;43.580941370786604;\
34845.28946949821329;56.024945551713245;59.28160733189452;60.919637988946306
349cwt.sd;12.118506999914882;6.044408962707157;7.728932055062374;\
3506.268950876605313;7.854789647395754;7.732399117687471;8.863583544578608;\
3517.7525558824150504;11.241315012712777;12.118136175485233;12.596354952532373
352fill.rate;0.24110446911471678;0.44084507042253523;0.2712842712842713;\
3530.36182336182336183;0.3394109396914446;0.32340425531914896;\
3540.21075581395348839;0.4196816208393632;0.002881844380403458;\
3550.01969057665260197;0.025034770514603615
356stocklevel.mean;1.8113476672429796;0.3802859636659473;0.23439669327549575;\
3570.19451906423091544;0.2559188646462229;0.2206691076289149;0.1935442874513864;\
3580.3124656055438941;0.00017487014444265826;0.008074900603352099;\
3590.011298310052408007
360fulfilled.rate;0.9987190435525192;1;0.9985569985569985;1;1;1;1;1;\
3610.9985590778097982;0.9929676511954993;0.9972183588317107
363>>> x1 = np.array([4, 6, 3, 4, 4, 6, 3, 5, 6, 10])
364>>> y = space.create()
365>>> ms.decode(x1, y)
366>>> for s in to_stream(y):
367... if "time" not in s:
368... print(s)
369-------- Instance 0: 'mfc_10_13_10000_0x64' -------
370stat;total;product_0;product_1;product_2;product_3;product_4;product_5;\
371product_6;product_7;product_8;product_9
372trp.min;5.2184145757182705;5.2184145757182705;8.901258396714184;\
3739.297175556856018;7.298761505635412;8.93985302431065;12.606621860129053;\
3747.656178022299173;20.904266810249283;19.5732602761791;20.522703426695443
375trp.mean;32.405411220867336;22.45718865883824;29.222031978321247;\
37625.136275651698107;25.884250065648388;27.37383814423524;32.10269885414455;\
37721.905835255853667;45.11627023942567;44.78387873021794;49.465651426661886
378trp.max;101.42283298962138;56.30942379913131;74.17811849023519;\
37958.955465373336665;60.209164983262326;60.66621167329777;74.4357130671624;\
38047.944841355481;83.29062031809917;96.5279603056706;101.42283298962138
381trp.sd;14.352456423754838;8.966715472534952;10.260311480773648;\
3828.824583884361449;9.375043161957333;9.776116378207652;10.962890512009123;\
3836.691465594834237;12.613587720623373;12.30244975508726;13.52381481631245
384cwt.min;0.026454757136889384;0.026454757136889384;2.30483638259102;\
3850.054286282554130594;0.16648942892061314;0.1385205442725237;\
3862.2444075501571206;0.16694429707604286;0.2360807359827959;0.2894682031374032;\
3870.7020815078112719
388cwt.mean;8.296470547393602;4.437533958350662;12.615320110639914;\
3894.7164029806433545;6.611310521050654;8.350460109042185;7.55452574755307;\
3905.82304931358363;9.068938196877168;17.21719619156937;6.710247622764048
391cwt.max;37.76460269749805;11.383554877750612;25.02207987420161;\
39216.22657205109499;24.355088852856625;23.499199642416897;24.507644884798083;\
39327.834403782263507;29.068687291493006;37.76460269749805;12.188275706294007
394cwt.sd;8.072214752396842;3.8478370296451603;9.569679438559595;\
3954.197433045217076;7.324722986150041;6.142260031783497;6.213481379280693;\
3967.142777751769366;7.629569041217826;11.995928244823393;5.761419012759379
397fill.rate;0.9475719810915342;0.9673295454545454;0.9869565217391304;\
3980.9121037463976945;0.9595808383233533;0.93033381712627;0.9775280898876404;\
3990.9477401129943502;0.8531073446327684;0.9452449567723343;0.9957983193277311
400stocklevel.mean;29.106301317812118;2.760696025360742;4.137393715988243;\
4011.5507610335648132;2.5500355305055966;2.3659654563794095;3.7559706390001586;\
4021.811228677305335;1.5668982789103876;2.657874734996926;5.949477225800507
403fulfilled.rate;1;1;1;1;1;1;1;1;1;1;1
404-------- Instance 1: 'mfc_10_13_10000_0xc8' -------
405stat;total;product_0;product_1;product_2;product_3;product_4;product_5;\
406product_6;product_7;product_8;product_9
407trp.min;6.530138861169689;6.530138861169689;9.628902017961991;\
4088.559079500931148;9.008831732480758;8.17345928487157;10.857776143797764;\
4097.1989408754006945;20.221688833546978;20.764475417566246;18.683929092542712
410trp.mean;31.011119751546097;20.636089799689874;27.67447485260846;\
41123.897005119242046;24.208477302980572;25.25418917347286;29.761302044694876;\
41223.04493364417017;43.39775607053671;45.37848659776272;46.77244686997264
413trp.max;82.04580382289168;45.2064686844069;55.755010710267015;\
41447.241916696964836;46.46518160018422;56.86270345999128;58.305458902948885;\
41552.54891087334727;80.98768370429207;80.62246465566932;82.04580382289168
416trp.sd;12.96227404463328;6.684031626500774;7.995431160774385;\
4177.132422793760531;7.239745166217043;8.109774006790918;8.249688118912145;\
4187.915621083543569;10.500873112173776;10.750658149592526;10.934157433002026
419cwt.min;0.011249992165176081;0.5337058348654864;0.8014497560352538;\
4200.2827261678148716;1.4241222500077129;0.011249992165176081;7.901938969392177;\
4210.041148101390717784;0.08459428467904218;0.10726475210685749;
422cwt.mean;7.183224986008803;1.9535417603494485;0.8014497560352538;\
4234.619753737796203;9.370441335605987;7.744917661655692;7.901938969392177;\
4248.052111019031262;8.505184343659167;5.922113521223626;
425cwt.max;31.446190263142853;5.290086057329063;0.8014497560352538;\
42610.883639956720799;25.608040164921476;24.178558590047942;7.901938969392177;\
42731.446190263142853;21.35684648685401;16.312679904455308;
428cwt.sd;6.15364337829274;1.7473126971982065;;3.440991075922831;\
4296.485559248771155;6.715154696592823;;7.703968965710594;6.633960138504885;\
4303.8259446158453017;
431fill.rate;0.9628522630230573;0.9901408450704225;0.9985569985569985;\
4320.9544159544159544;0.9635343618513323;0.9702127659574468;0.998546511627907;\
4330.9175108538350217;0.9149855907780979;0.919831223628692;1
434stocklevel.mean;30.090461520030797;2.907712049060156;4.261495763524114;\
4351.6231331746350672;2.565318363579915;2.472060544282644;4.079218485848546;\
4361.786007080448915;1.7664180248890007;2.4348085700118425;6.194289463750593
437fulfilled.rate;1;1;1;1;1;1;1;1;1;1;1
438"""
439from typing import Final
441import numpy as np
442from moptipy.api.encoding import Encoding
443from pycommons.types import type_error
445from moptipyapps.prodsched.multistatistics import (
446 MultiStatistics,
447 MultiStatisticsSpace,
448)
449from moptipyapps.prodsched.rop_simulation import ROPSimulation
450from moptipyapps.prodsched.statistics_collector import StatisticsCollector
453class ROPMultiSimulation(Encoding):
454 """A multi-simulation that caches the results for reuse."""
456 def __init__(self, space: MultiStatisticsSpace) -> None:
457 """
458 Instantiate the multi-statistics decoding.
460 :param instances: the packing instance
461 """
462 if not isinstance(space, MultiStatisticsSpace):
463 raise type_error(space, "space", MultiStatisticsSpace)
464 #: the statistics collectors
465 col: Final[tuple[StatisticsCollector, ...]] = tuple(
466 StatisticsCollector(inst) for inst in space.instances)
467 #: the simulations and collectors
468 self.__simulations: Final[tuple[tuple[
469 ROPSimulation, StatisticsCollector], ...]] = tuple(
470 (ROPSimulation(inst, col[i]), col[i])
471 for i, inst in enumerate(space.instances))
472 #: the internal space
473 self.__space: Final[MultiStatisticsSpace] = space
475 def decode(self, x: np.ndarray, y: MultiStatistics) -> None:
476 """
477 Map a ROP setting to a multi-statistics.
479 This method uses an internal cache: The same re-order points will
480 yield the same statistics.
482 :param x: the array
483 :param y: the Gantt chart
484 """
485 # First we map the vector to a tuple of integers.
486 x_tuple: Final[tuple[int, ...]] = tuple(map(int, x))
488 # If we get here, the ROP is new.
489 # So we simulate it.
490 for i, (sim, col) in enumerate(self.__simulations):
491 col.set_dest(y.per_instance[i])
492 sim.ctrl_reset()
493 sim.set_rop(x_tuple)
494 sim.ctrl_run()
496 # The simulation is completed. We can now cache the result.
497 cached: Final[MultiStatistics] = self.__space.create()
498 self.__space.copy(cached, y)
500 def __str__(self) -> str:
501 """
502 Get the name of this decoding.
504 :return: `"rms"`
505 :rtype: str
506 """
507 return "rms"