2using System.Collections.Generic;
4using System.Xml.Serialization;
5using LotSizingDataModel.Core.Common;
24[XmlType(TypeName =
"lotSizingProblemClassification")]
34 private string _primaryProblemTypeCode =
37 private string _primaryProblemTypeName =
40 private string _classifierVersion =
43 private string _catalogName =
46 private string _catalogVersion =
49 private DateTime? _classifiedAtUtc;
51 private string _supplyChainFingerprint =
54 private string _comment =
79 ArgumentNullException.ThrowIfNull(features);
87 [XmlAttribute(
"status")]
97 NotifyDerivedProperties();
106 [XmlElement(
"features")]
137 [XmlAttribute(
"primaryProblemTypeCode")]
140 get => _primaryProblemTypeCode;
144 ref _primaryProblemTypeCode,
145 NormalizeProblemTypeCode(value)))
147 NotifyPrimaryMatchProperties();
156 [XmlAttribute(
"primaryProblemTypeName")]
159 get => _primaryProblemTypeName;
163 ref _primaryProblemTypeName,
164 value?.Trim() ??
string.Empty))
166 NotifyPrimaryMatchProperties();
175 [XmlAttribute(
"classifierVersion")]
178 get => _classifierVersion;
182 ref _classifierVersion,
183 value?.Trim() ??
string.Empty))
195 [XmlAttribute(
"catalogName")]
203 value?.Trim() ??
string.Empty))
215 [XmlAttribute(
"catalogVersion")]
218 get => _catalogVersion;
223 value?.Trim() ??
string.Empty))
239 [XmlElement(
"classifiedAtUtc", IsNullable =
true)]
242 get => _classifiedAtUtc;
247 ? ConvertToUtc(value.Value)
251 ref _classifiedAtUtc,
268 [XmlAttribute(
"supplyChainFingerprint")]
271 get => _supplyChainFingerprint;
275 ref _supplyChainFingerprint,
276 value?.Trim() ??
string.Empty))
292 [XmlArray(
"matches")]
293 [XmlArrayItem(
"knownProblemTypeMatch")]
294 public List<KnownProblemTypeMatch>
Matches {
get; } =
305 [XmlArray(
"unclassifiedFeatureCodes")]
306 [XmlArrayItem(
"featureCode")]
314 [XmlArray(
"warnings")]
315 [XmlArrayItem(
"warning")]
324 [XmlArrayItem(
"error")]
332 [XmlElement(
"comment")]
340 value?.Trim() ??
string.Empty))
363 !
string.IsNullOrWhiteSpace(
372 !
string.IsNullOrWhiteSpace(
381 !
string.IsNullOrWhiteSpace(
390 !
string.IsNullOrWhiteSpace(
392 !
string.IsNullOrWhiteSpace(
401 !
string.IsNullOrWhiteSpace(
418 !
string.IsNullOrWhiteSpace(
438 match.IsDirectMatch);
448 match.IsExactMatch &&
449 !match.HasBlockingMismatches);
495 UnclassifiedFeatureCodes.Count > 0;
551 .PartiallyClassified ||
579 match.ProblemTypeCode,
581 StringComparison.OrdinalIgnoreCase))
584 match.AppliesToCompleteProblem)
604 ArgumentNullException.ThrowIfNull(match);
608 NotifyMatchProperties();
621 IEnumerable<KnownProblemTypeMatch> matches)
623 ArgumentNullException.ThrowIfNull(matches);
628 if (normalizedMatches.Any(
632 throw new ArgumentException(
633 "The match collection cannot contain a " +
639 Matches.AddRange(normalizedMatches);
641 NotifyMatchProperties();
654 NotifyMatchProperties();
671 ArgumentNullException.ThrowIfNull(match);
675 throw new InvalidOperationException(
676 "The primary match must belong to the " +
677 "classification match collection.");
680 if (
string.IsNullOrWhiteSpace(
683 throw new InvalidOperationException(
684 "The primary match must have a known " +
685 "problem-type code.");
715 IEnumerable<string> featureCodes)
717 ReplaceNormalizedStrings(
720 nameof(featureCodes));
736 IEnumerable<string> warnings)
738 ReplaceNormalizedStrings(
757 IEnumerable<string> errors)
759 ReplaceNormalizedStrings(
786 string currentFingerprint)
788 if (
string.IsNullOrWhiteSpace(
789 currentFingerprint) ||
795 return string.Equals(
797 currentFingerprint.Trim(),
798 StringComparison.Ordinal);
861 NotifyMatchProperties();
872 NotifyDerivedProperties();
878 string primaryDescription =
881 :
"no primary family";
884 $
"{Status}; {primaryDescription}; " +
885 $
"{MatchCount} match(es)";
888 private static string NormalizeProblemTypeCode(
893 .ToUpperInvariant() ??
897 private static void ReplaceNormalizedStrings(
898 ICollection<string> destination,
899 IEnumerable<string> source,
900 string parameterName)
902 ArgumentNullException.ThrowIfNull(source);
904 string[] normalizedValues =
908 !
string.IsNullOrWhiteSpace(
914 StringComparer.OrdinalIgnoreCase)
918 StringComparer.OrdinalIgnoreCase)
923 foreach (
string value
in normalizedValues)
925 destination.Add(value);
929 private static DateTime ConvertToUtc(
932 return value.Kind
switch
937 DateTimeKind.Local =>
938 value.ToUniversalTime(),
941 DateTime.SpecifyKind(
947 private void NotifyPrimaryMatchProperties()
962 private void NotifyMatchProperties()
995 private void NotifyDerivedProperties()
Represents a detected correspondence between a lot-sizing instance and a known problem family.
string ProblemTypeName
Gets or sets the human-readable name of the known lot-sizing problem family.
string ProblemTypeCode
Gets or sets the stable code identifying the known lot-sizing problem family.
void ClearMatches()
Removes all known-problem-family matches and clears the selected primary family.
override string ToString()
void ReplaceErrors(IEnumerable< string > errors)
Replaces all classification errors.
bool HasClassifierVersion
Gets a value indicating whether the classifier version has been recorded.
bool HasComment
Gets a value indicating whether an explanatory comment has been recorded.
bool HasSupplyChainFingerprint
Gets a value indicating whether a supply-chain fingerprint has been recorded.
bool HasWarnings
Gets a value indicating whether at least one warning was produced.
bool HasCatalogInformation
Gets a value indicating whether both catalog name and catalog version have been recorded.
string CatalogName
Gets or sets the human-readable name of the problem-type catalog used during classification.
KnownProblemTypeMatch? PrimaryMatch
Gets the match corresponding to the selected primary problem-family code.
void SetPrimaryMatch(KnownProblemTypeMatch match)
Selects one existing match as the primary recognized problem family.
int DirectMatchCount
Gets the number of direct exact or known-extension matches without blocking conditions.
LotSizingProblemFeatures Features
Gets or sets the factual lot-sizing problem features used during classification.
bool HasUnclassifiedFeatures
Gets a value indicating whether unclassified features remain after classification.
void ClearClassificationResult()
Clears all generated classification information while preserving the current feature object.
bool HasPrimaryProblemTypeName
Gets a value indicating whether the primary problem-family name has been recorded.
void AddMatch(KnownProblemTypeMatch match)
Adds one known-problem-family match.
int RelaxationMatchCount
Gets the number of recognized relaxations.
string CatalogVersion
Gets or sets the version of the problem-type catalog used during classification.
void ReplaceUnclassifiedFeatureCodes(IEnumerable< string > featureCodes)
Replaces the globally unclassified feature codes.
void ClearPrimaryProblemType()
Removes the currently selected primary problem-family information.
bool HasUsableFeatures
Gets a value indicating whether the extracted feature profile contains the minimum information requir...
bool CanBeUsedForMethodSelection
Gets a value indicating whether the classification can currently contribute to method selection.
string Comment
Gets or sets an optional human-readable comment about the complete classification.
bool MatchesSupplyChainFingerprint(string currentFingerprint)
Determines whether the stored classification was produced from the supplied supply-chain fingerprint.
List< string > Warnings
Gets the warnings produced during feature extraction or problem classification.
int SubproblemMatchCount
Gets the number of recognized subproblems.
LotSizingProblemClassification(LotSizingProblemFeatures features)
Initializes a lot-sizing problem classification with an extracted feature profile.
int MatchCount
Gets the total number of reported problem-family matches.
int ExactMatchCount
Gets the number of exact matches.
bool HasErrors
Gets a value indicating whether at least one error was produced.
bool HasMatches
Gets a value indicating whether at least one problem-family match has been reported.
LotSizingProblemClassification()
Initializes an empty lot-sizing problem classification.
List< KnownProblemTypeMatch > Matches
Gets all known-problem-family matches detected for the analyzed instance.
void MarkAsOutdated()
Marks the stored classification as outdated.
List< string > Errors
Gets the errors produced during feature extraction or problem classification.
void ReplaceMatches(IEnumerable< KnownProblemTypeMatch > matches)
Replaces all known-problem-family matches.
string ClassifierVersion
Gets or sets the version of the software classifier that produced this result.
string SupplyChainFingerprint
Gets or sets the fingerprint of the supply-chain data used to produce this classification.
void ReplaceWarnings(IEnumerable< string > warnings)
Replaces all classification warnings.
bool HasBeenAnalyzed
Gets a value indicating whether a completed analysis date has been recorded.
string PrimaryProblemTypeName
Gets or sets the human-readable name of the primary recognized problem family.
ProblemClassificationStatus Status
Gets or sets the current global classification status.
bool HasDirectMatches
Gets a value indicating whether at least one direct known-family match has been reported.
bool HasPrimaryProblemType
Gets a value indicating whether a primary problem-family code has been selected.
List< string > UnclassifiedFeatureCodes
Gets the codes of detected features that are not adequately represented by any reported family match.
string PrimaryProblemTypeCode
Gets or sets the stable code of the primary recognized problem family.
bool IsOutdated
Gets a value indicating whether the stored classification is marked as outdated.
DateTime? ClassifiedAtUtc
Gets or sets the UTC date and time at which the classification was produced.
bool IsInvalid
Gets a value indicating whether classification failed because the analyzed instance was invalid.
Describes the factual structural and modeling features detected in a lot-sizing supply-chain instance...
ProblemMatchKind
Identifies how a supply-chain instance matches a known lot-sizing problem family.
ProblemClassificationStatus
Indicates the current status of the automatic classification of a lot-sizing problem instance.
@ Ambiguous
Several known problem families match the instance equally well and no unique primary classification c...
@ Classified
The complete problem has been associated with a known lot-sizing family or with a clearly identified ...