LotSizingDataModel.Instance 2.0.1
Lot-sizing instance representation, descriptors and problem characterization.
Loading...
Searching...
No Matches
LotSizingInstance.ClosedLoop.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Xml.Serialization;
6
8
9/// <summary>
10/// Adds explicit closed-loop return streams to a lot-sizing
11/// instance without changing the historical SupplyChain schema.
12/// </summary>
13public sealed partial class LotSizingInstance
14{
15 [XmlArray("closedLoopReturnStreams")]
16 [XmlArrayItem("closedLoopReturnStream")]
17 public List<ClosedLoopReturnStream>
19 {
20 get;
21 } =
22 new();
23
24 [XmlIgnore]
26 ClosedLoopReturnStreams.Count > 0;
27
30 {
31 ArgumentNullException.ThrowIfNull(
32 stream);
33
35 existing =>
36 existing.Id ==
37 stream.Id))
38 {
39 throw new InvalidOperationException(
40 $"Closed-loop return-stream identifier '{stream.Id}' is already used.");
41 }
42
43 stream.ResizeTimeSeries(
45
46 stream.EnsureValid();
47
49 stream);
50
51 OnPropertyChanged(
53
54 OnPropertyChanged(
56 }
57
59 {
60 foreach (ClosedLoopReturnStream stream
62 {
63 stream.ResizeTimeSeries(
65 }
66
67 OnPropertyChanged(
69 }
70
72 {
73 var streamIdentifiers =
74 new HashSet<int>();
75
76 foreach (ClosedLoopReturnStream stream
78 {
79 ArgumentNullException.ThrowIfNull(
80 stream);
81
82 stream.EnsureValid();
83
84 if (!streamIdentifiers.Add(
85 stream.Id))
86 {
87 throw new InvalidOperationException(
88 $"Closed-loop return-stream identifier '{stream.Id}' is duplicated.");
89 }
90
91 if (stream.PlanningHorizon !=
93 {
94 throw new InvalidOperationException(
95 $"Closed-loop return stream '{stream.Id}' uses horizon {stream.PlanningHorizon}, expected {PlanningHorizon}.");
96 }
97
98 if (!SupplyChain.Items.Any(
99 item =>
100 item.Id ==
101 stream.ItemId))
102 {
103 throw new InvalidOperationException(
104 $"Closed-loop return stream '{stream.Id}' references unknown item '{stream.ItemId}'.");
105 }
106
107 if (!SupplyChain.DistributionCenters.Any(
108 distributionCenter =>
109 distributionCenter.Id ==
110 stream.DistributionCenterId))
111 {
112 throw new InvalidOperationException(
113 $"Closed-loop return stream '{stream.Id}' references unknown distribution center '{stream.DistributionCenterId}'.");
114 }
115
116 bool hasTargetInventory =
117 SupplyChain.Inventories.Any(
118 inventory =>
119 inventory.ItemId ==
120 stream.ItemId &&
121 inventory.Warehouse.Kind ==
122 stream.RecoveryWarehouse.Kind &&
123 inventory.Warehouse.ReferenceId ==
124 stream.RecoveryWarehouse.ReferenceId);
125
126 if (!hasTargetInventory)
127 {
128 throw new InvalidOperationException(
129 $"Closed-loop return stream '{stream.Id}' has no matching target inventory for recovered item '{stream.ItemId}'.");
130 }
131 }
132 }
133}
Describes one exogenous stream of returned units and its recovery/disposal alternatives.
void AddClosedLoopReturnStream(ClosedLoopReturnStream stream)
SupplyChain SupplyChain
Gets or sets the supply-chain model represented by the instance.
int PlanningHorizon
Gets the planning horizon of the supply-chain model.
LotSizingInstance()
Initializes an empty lot-sizing problem instance.