LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
InitialInventoryDecisionMapper.cs
Go to the documentation of this file.
1using LotSizingDataModel.Core.PhysicalModel;
2using LotSizingDataModel.Solution;
3using LotSizingDataModel.Solution.Decisions;
5
7
8/// <summary>
9/// Maps a mathematical period-zero inventory value to the normalized solution.
10/// </summary>
11public sealed class InitialInventoryDecisionMapper :
13{
14 public override string Category =>
16
17 protected override void MapValue(
19 LotSizingSolution solution,
20 MathematicalDomainKey domainKey,
21 MathematicalVariableValue variableValue)
22 {
23 ArgumentNullException.ThrowIfNull(context);
24 ArgumentNullException.ThrowIfNull(solution);
25 ArgumentNullException.ThrowIfNull(domainKey);
26 ArgumentNullException.ThrowIfNull(variableValue);
27
28 int itemId =
29 domainKey.GetRequiredInt32(
31
32 WarehouseReference warehouse =
33 ResolveWarehouse(domainKey);
34
35 InventoryDecision? decision =
36 solution.InventoryDecisions.FirstOrDefault(
37 existing =>
38 existing.ItemId == itemId &&
39 existing.Warehouse.Kind == warehouse.Kind &&
40 existing.Warehouse.ReferenceId == warehouse.ReferenceId);
41
42 if (decision is null)
43 {
44 decision =
45 new InventoryDecision(
46 itemId,
47 warehouse,
48 solution.PlanningHorizon);
49
50 solution.AddInventoryDecision(decision);
51 }
52
53 decision.InitialInventoryLevel =
54 variableValue.Value;
55 }
56
57 private static WarehouseReference ResolveWarehouse(
58 MathematicalDomainKey domainKey)
59 {
60 bool hasStandalone =
61 domainKey.TryGetInt32(
63 out int warehouseId);
64
65 bool hasPlant =
66 domainKey.TryGetInt32(
68 out int plantId);
69
70 if (hasStandalone == hasPlant)
71 {
72 throw new InvalidOperationException(
73 "An initial-inventory key must identify exactly one warehouse.");
74 }
75
76 return hasStandalone
77 ? WarehouseReference.ForStandaloneWarehouse(warehouseId)
78 : WarehouseReference.ForPlantWarehouse(plantId);
79 }
80}
Stores the value returned by a solver for one mathematical decision variable.
double Value
Gets or sets the value returned by the solver.
Maps a mathematical period-zero inventory value to the normalized solution.
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.
bool TryGetInt32(string name, out int value)
Attempts to get an 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...