3using System.Security.Cryptography;
6using System.Xml.Serialization;
7using LotSizingDataModel.Core;
118 SupplyChain supplyChain,
123 bool analyzeProductStructure =
true,
124 bool classifyProblem =
true,
125 string createdBy =
"",
126 double numericalTolerance =
130 if (
string.IsNullOrWhiteSpace(instanceId))
132 throw new ArgumentException(
133 "A lot-sizing instance identifier is required.",
137 ArgumentNullException.ThrowIfNull(supplyChain);
139 ValidateNumericalTolerance(
142 string supplyChainFingerprint =
163 declaredProductStructureType)
166 if (analyzeProductStructure)
170 instance.SupplyChain,
173 instance.ProductStructure,
175 supplyChainFingerprint:
176 supplyChainFingerprint);
186 instance.ProblemClassification =
189 instance.SupplyChain,
194 supplyChainFingerprint:
195 supplyChainFingerprint,
228 SupplyChain supplyChain,
232 string createdBy =
"")
244 declaredProductStructureType:
245 declaredProductStructureType,
250 analyzeProductStructure:
300 bool analyzeProductStructure =
true,
301 bool classifyProblem =
true,
302 double numericalTolerance =
304 .DefaultNumericalTolerance)
306 ArgumentNullException.ThrowIfNull(instance);
308 ValidateNumericalTolerance(
311 string supplyChainFingerprint =
315 if (analyzeProductStructure)
324 supplyChainFingerprint:
325 supplyChainFingerprint);
329 MarkProductStructureAsOutdatedWhenRequired(
331 supplyChainFingerprint);
341 instance.ProblemClassification =
349 supplyChainFingerprint:
350 supplyChainFingerprint,
357 MarkClassificationAsOutdatedWhenRequired(
359 supplyChainFingerprint);
364 instance.ModifiedAtUtc =
367 return supplyChainFingerprint;
384 ArgumentNullException.ThrowIfNull(instance);
398 supplyChainFingerprint:
403 instance.ModifiedAtUtc =
432 double numericalTolerance =
434 .DefaultNumericalTolerance)
436 ArgumentNullException.ThrowIfNull(instance);
438 ValidateNumericalTolerance(
458 supplyChainFingerprint:
464 instance.ProblemClassification =
469 instance.ModifiedAtUtc =
472 return classification;
504 SupplyChain supplyChain)
506 ArgumentNullException.ThrowIfNull(supplyChain);
508 byte[] serializedData =
509 SerializeSupplyChainForFingerprint(
514 using (SHA256 sha256 =
523 $
"{FingerprintScheme}:" +
524 Convert.ToHexString(hash);
527 private static byte[]
528 SerializeSupplyChainForFingerprint(
529 SupplyChain supplyChain)
533 typeof(SupplyChain));
536 new XmlSerializerNamespaces();
543 new XmlWriterSettings
547 encoderShouldEmitUTF8Identifier:
557 NewLineHandling.None,
568 using (XmlWriter writer =
573 serializer.Serialize(
579 return stream.ToArray();
581 catch (InvalidOperationException exception)
583 throw new InvalidOperationException(
584 "The supply-chain model could not be " +
585 "serialized for fingerprint generation.",
591 MarkProductStructureAsOutdatedWhenRequired(
592 ProductStructureDescriptor descriptor,
593 string currentFingerprint)
601 bool fingerprintMatches =
602 !
string.IsNullOrWhiteSpace(
607 StringComparison.Ordinal);
609 if (!fingerprintMatches)
616 MarkClassificationAsOutdatedWhenRequired(
617 LotSizingProblemClassification classification,
618 string currentFingerprint)
620 if (classification.
Status ==
627 .MatchesSupplyChainFingerprint(
634 private static void ValidateNumericalTolerance(
635 double numericalTolerance)
637 if (!
double.IsFinite(numericalTolerance) ||
638 numericalTolerance < 0.0)
640 throw new ArgumentOutOfRangeException(
641 nameof(numericalTolerance),
643 "The numerical tolerance must be finite " +
644 "and non-negative.");
Represents the detailed result of an automatic analysis of a product bill-of-materials graph.
Analyzes the bill-of-materials graph of a supply-chain instance and determines its product-structure ...
static ProductStructureAnalysis AnalyzeAndUpdate(SupplyChain supplyChain, ProductStructureDescriptor descriptor, string supplyChainFingerprint="")
Analyzes a supply-chain product structure and applies the result to a persistent descriptor.
Creates predefined catalogs of known lot-sizing problem-family definitions.
static KnownProblemTypeCatalog CreateStandardCatalog()
Creates the standard catalog of known lot-sizing problem families.
Stores known lot-sizing problem-family definitions and the reusable rules used to recognize them.
Stores the persistent result of the automatic classification of a lot-sizing problem instance.
void MarkAsOutdated()
Marks the stored classification as outdated.
ProblemClassificationStatus Status
Gets or sets the current global classification status.
Classifies lot-sizing supply-chain instances using a catalog of known problem-family definitions.
static LotSizingProblemClassification Classify(SupplyChain supplyChain, KnownProblemTypeCatalog catalog, string supplyChainFingerprint="", double numericalTolerance=LotSizingProblemFeatureExtractor .DefaultNumericalTolerance)
Classifies a supply-chain instance using a known problem-type catalog.
Creates lot-sizing problem instances and initializes their automatically derived metadata.
static LotSizingInstance CreateUnanalyzed(string instanceId, SupplyChain supplyChain, string name="", ProductStructureType declaredProductStructureType=ProductStructureType.Unknown, string createdBy="")
Creates a lot-sizing instance without automatically analyzing or classifying it.
static ProductStructureAnalysis RefreshProductStructure(LotSizingInstance instance)
Recalculates only the persistent product-structure analysis of an instance.
const string FingerprintScheme
Gets the identifier of the fingerprint algorithm and serialization convention used by this factory.
static LotSizingInstance Create(string instanceId, SupplyChain supplyChain, string name="", ProductStructureType declaredProductStructureType=ProductStructureType.Unknown, KnownProblemTypeCatalog? catalog=null, bool analyzeProductStructure=true, bool classifyProblem=true, string createdBy="", double numericalTolerance=LotSizingProblemFeatureExtractor .DefaultNumericalTolerance)
Creates and automatically analyzes a lot-sizing problem instance.
static string RefreshDerivedData(LotSizingInstance instance, KnownProblemTypeCatalog? catalog=null, bool analyzeProductStructure=true, bool classifyProblem=true, double numericalTolerance=LotSizingProblemFeatureExtractor .DefaultNumericalTolerance)
Recalculates the product-structure analysis and problem classification of an existing instance.
static string ComputeSupplyChainFingerprint(SupplyChain supplyChain)
Calculates a SHA-256 fingerprint of a supply-chain object using its compact XML serialization.
static LotSizingProblemClassification RefreshProblemClassification(LotSizingInstance instance, KnownProblemTypeCatalog? catalog=null, double numericalTolerance=LotSizingProblemFeatureExtractor .DefaultNumericalTolerance)
Recalculates only the problem classification of an instance.
Adds explicit closed-loop return streams to a lot-sizing instance without changing the historical Sup...
LotSizingProblemClassification ProblemClassification
Gets or sets the automatic lot-sizing problem classification.
void ClearSolutionMethodRecommendationReport()
Clears the complete solution-method recommendation report.
SupplyChain SupplyChain
Gets or sets the supply-chain model represented by the instance.
ProductStructureDescriptor ProductStructure
Gets or sets the product-structure descriptor associated with the supply-chain model.
ProblemClassificationStatus
Indicates the current status of the automatic classification of a lot-sizing problem instance.
ProductStructureType
Identifies the structural category of a product bill-of-materials graph.