21 private readonly SupplyChainValidator _structuralValidator;
28 : this(new SupplyChainValidator())
36 SupplyChainValidator structuralValidator)
38 _structuralValidator =
39 structuralValidator ??
40 throw new ArgumentNullException(
41 nameof(structuralValidator));
50 ArgumentNullException.ThrowIfNull(instance);
53 new List<InstanceDiagnostic>();
55 AppendStructuralDiagnostics(
59 AppendInstanceIdentityDiagnostics(
63 AppendDemandDiagnostics(
67 AppendKnownResultDiagnostics(
75 private void AppendStructuralDiagnostics(
77 ICollection<InstanceDiagnostic> diagnostics)
80 SupplyChainValidator.ValidationIssue> issues =
81 _structuralValidator.Validate(
85 SupplyChainValidator.ValidationIssue issue
90 SupplyChainValidator.ValidationSeverity.Error
101 message: issue.Message,
103 "Correct the underlying supply-chain data " +
104 "before classification or solving."));
108 private static void AppendInstanceIdentityDiagnostics(
109 LotSizingInstance instance,
110 ICollection<InstanceDiagnostic> diagnostics)
112 if (instance.HasInstanceId)
118 new InstanceDiagnostic(
119 code:
"LSDM-SEM-001",
122 path:
"instance.instanceId",
124 "The instance has no stable identifier.",
126 "Assign a stable instance identifier before " +
127 "publishing or exchanging the instance."));
130 private static void AppendDemandDiagnostics(
131 LotSizingInstance instance,
132 ICollection<InstanceDiagnostic> diagnostics)
134 if (instance.SupplyChain.Demands.Count == 0)
137 new InstanceDiagnostic(
138 code:
"LSDM-SEM-010",
141 path:
"instance.supplyChain.demands",
143 "The instance contains no external demand record.",
145 "Confirm that a demand-free planning problem is " +
150 bool hasPositiveDemand =
false;
152 foreach (var demand
in instance.SupplyChain.Demands)
156 period <= demand.PlanningHorizon;
159 if (demand.GetQuantity(period) > 0.0)
161 hasPositiveDemand =
true;
166 if (hasPositiveDemand)
172 if (!hasPositiveDemand)
175 new InstanceDiagnostic(
176 code:
"LSDM-SEM-011",
179 path:
"instance.supplyChain.demands",
181 "Demand records exist but all demand quantities " +
184 "Confirm that the zero-demand instance is " +
189 private static void AppendKnownResultDiagnostics(
190 LotSizingInstance instance,
191 ICollection<InstanceDiagnostic> diagnostics)
193 if (!instance.HasBestKnownResultId ||
194 instance.HasBestKnownResult)
200 new InstanceDiagnostic(
201 code:
"LSDM-SEM-020",
204 path:
"instance.bestKnownResultId",
206 "The selected best-known-result identifier does not " +
207 "refer to an existing known result.",
209 new Dictionary<string, string>(
210 StringComparer.Ordinal)
212 [
"bestKnownResultId"] =
213 instance.BestKnownResultId
216 "Select an existing known result or clear the " +
217 "best-known-result identifier."));