LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
GlspMicroPeriodSetupStateDecisionMapper.cs
Go to the documentation of this file.
1using LotSizingDataModel.Core.DecisionModel.Scheduling;
2using LotSizingDataModel.Core.PhysicalModel;
3using LotSizingDataModel.Solution;
4using LotSizingDataModel.Solution.Decisions;
7
9
11{
13
14 protected override void MapValue(
16 LotSizingSolution solution,
17 MathematicalDomainKey domainKey,
18 MathematicalVariableValue variableValue)
19 {
20 ArgumentNullException.ThrowIfNull(context);
21 ArgumentNullException.ThrowIfNull(solution);
22 ArgumentNullException.ThrowIfNull(domainKey);
23 ArgumentNullException.ThrowIfNull(variableValue);
24
25 if (variableValue.Value < 0.5) return;
26
28 int workCenterId = domainKey.GetRequiredInt32(MathematicalDomainKeySegment.WorkCenter);
29 int routingId = domainKey.GetRequiredInt32(MathematicalDomainKeySegment.Routing);
32 int microPeriodIndex = domainKey.GetRequiredInt32(MathematicalDomainKeySegment.MicroPeriod);
33
34 WorkCenterSchedulingDecision? schedule =
35 solution.WorkCenterSchedulingDecisions.SingleOrDefault(existing =>
36 existing.WorkCenter.PlantId == plantId &&
37 existing.WorkCenter.WorkCenterId == workCenterId);
38
39 if (schedule is null)
40 {
41 schedule = new WorkCenterSchedulingDecision(
42 new WorkCenterReference(plantId, workCenterId),
43 solution.PlanningHorizon);
44 solution.AddWorkCenterSchedulingDecision(schedule);
45 }
46
47 ProductionMicroPeriodDecision? decision =
48 schedule.MicroPeriods.SingleOrDefault(existing =>
49 existing.MicroPeriod.MacroPeriod == period &&
50 existing.MicroPeriod.MicroPeriodIndex == microPeriodIndex);
51
52 if (decision is null)
53 {
54 decision = new ProductionMicroPeriodDecision(
55 new ProductionMicroPeriodReference(period, microPeriodIndex),
56 setupItemId: itemId);
57 schedule.AddMicroPeriodDecision(decision);
58 }
59 else if (decision.SetupItemId != itemId)
60 {
61 throw new InvalidOperationException(
62 "Two active GLSP setup states were mapped to the same micro-period.");
63 }
64
65 string productionKey =
67 plantId, workCenterId, routingId, itemId, decision.MicroPeriod);
68
69 if (context.TryGetValue(productionKey, out MathematicalVariableValue? productionValue) &&
70 productionValue is not null)
71 {
72 double quantity =
73 Math.Abs(productionValue.Value) <= context.Options.ZeroTolerance
74 ? 0.0
75 : productionValue.Value;
76
77 if (quantity > 0.0)
78 {
79 decision.RoutingId = routingId;
80 decision.Quantity = quantity;
81 }
82 }
83 }
84}
Stores the value returned by a solver for one mathematical decision variable.
double Value
Gets or sets the value returned by the solver.
static string CreateMicroProductionKey(int plantId, int workCenterId, int routingId, int itemId, ProductionMicroPeriodReference microPeriod)
override string Category
Gets the mathematical domain-key category handled by this mapper.
override void MapValue(MathematicalSolutionMappingContext context, LotSizingSolution solution, MathematicalDomainKey domainKey, MathematicalVariableValue variableValue)
Provides the canonical mathematical domain-key categories used to identify lot-sizing decision famili...
Provides a reusable base implementation for mathematical decision mappers handling one domain-key cat...
Represents a parsed mathematical-model business-domain key.
int GetRequiredInt32(string name)
Gets a required integer segment.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...
Provides the shared state and lookup services required while mapping a mathematical solver result bac...
bool TryGetValue(string domainKey, out MathematicalVariableValue? variableValue)
Attempts to get a solver value by business-domain key.