LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
MathematicalFormulationScientificProfile.cs
Go to the documentation of this file.
1using LotSizingDataModel.Core.DecisionModel.Objectives;
2using LotSizingDataModel.Instance.ProblemClasses;
3
5
6/// <summary>
7/// Scientific capability contract for one solver-independent formulation.
8/// </summary>
9/// <remarks>
10/// Supported and known-unsupported extensions are explicit. Any extension
11/// absent from both sets is intentionally Undetermined.
12/// </remarks>
14{
15 private readonly IReadOnlyCollection<CanonicalLotSizingProblemClassId>
16 _supportedProblemClasses;
17
18 private readonly IReadOnlyCollection<LotSizingProblemClassExtensionKind>
19 _supportedExtensions;
20
21 private readonly IReadOnlyCollection<LotSizingProblemClassExtensionKind>
22 _knownUnsupportedExtensions;
23
24 private readonly IReadOnlyCollection<OptimizationObjectiveKind>
25 _supportedObjectiveKinds;
26
28 string formulationId,
29 string formulationFamily,
30 IEnumerable<CanonicalLotSizingProblemClassId>
31 supportedProblemClasses,
32 IEnumerable<LotSizingProblemClassExtensionKind>?
33 supportedExtensions = null,
34 IEnumerable<LotSizingProblemClassExtensionKind>?
35 knownUnsupportedExtensions = null,
36 IEnumerable<OptimizationObjectiveKind>?
37 supportedObjectiveKinds = null,
38 IEnumerable<string>? evidence = null)
39 {
40 if (string.IsNullOrWhiteSpace(formulationId))
41 {
42 throw new ArgumentException(
43 "A formulation identifier is required.",
44 nameof(formulationId));
45 }
46
47 if (string.IsNullOrWhiteSpace(formulationFamily))
48 {
49 throw new ArgumentException(
50 "A formulation family is required.",
51 nameof(formulationFamily));
52 }
53
54 ArgumentNullException.ThrowIfNull(supportedProblemClasses);
55
56 FormulationId = formulationId.Trim();
57 FormulationFamily = formulationFamily.Trim();
58
59 _supportedProblemClasses =
60 supportedProblemClasses
61 .Distinct()
62 .OrderBy(value => (int)value)
63 .ToArray();
64
65 _supportedExtensions =
66 (supportedExtensions ??
67 Array.Empty<LotSizingProblemClassExtensionKind>())
68 .Distinct()
69 .OrderBy(value => (int)value)
70 .ToArray();
71
72 _knownUnsupportedExtensions =
73 (knownUnsupportedExtensions ??
74 Array.Empty<LotSizingProblemClassExtensionKind>())
75 .Distinct()
76 .OrderBy(value => (int)value)
77 .ToArray();
78
79 _supportedObjectiveKinds =
80 (supportedObjectiveKinds ??
81 new[]
82 {
83 OptimizationObjectiveKind.Economic
84 })
85 .Where(
86 value =>
87 value != OptimizationObjectiveKind.Unknown)
88 .Distinct()
89 .OrderBy(value => (int)value)
90 .ToArray();
91
92 LotSizingProblemClassExtensionKind[] overlap =
93 _supportedExtensions
94 .Intersect(_knownUnsupportedExtensions)
95 .ToArray();
96
97 if (overlap.Length > 0)
98 {
99 throw new ArgumentException(
100 "A formulation extension cannot be both supported and " +
101 "known unsupported: " +
102 string.Join(",", overlap));
103 }
104
105 Evidence =
106 (evidence ?? Array.Empty<string>())
107 .Where(value => !string.IsNullOrWhiteSpace(value))
108 .Select(value => value.Trim())
109 .Distinct(StringComparer.Ordinal)
110 .ToArray();
111 }
112
113 public string FormulationId { get; }
114 public string FormulationFamily { get; }
115
116 public IReadOnlyCollection<CanonicalLotSizingProblemClassId>
118 _supportedProblemClasses;
119
120 public IReadOnlyCollection<LotSizingProblemClassExtensionKind>
122 _supportedExtensions;
123
124 public IReadOnlyCollection<LotSizingProblemClassExtensionKind>
126 _knownUnsupportedExtensions;
127
128 public IReadOnlyCollection<OptimizationObjectiveKind>
130 _supportedObjectiveKinds;
131
132 public IReadOnlyList<string> Evidence { get; }
133
135 CanonicalLotSizingProblemClassId problemClass) =>
136 _supportedProblemClasses.Contains(problemClass);
137
139 LotSizingProblemClassExtensionKind extension) =>
140 _supportedExtensions.Contains(extension);
141
143 LotSizingProblemClassExtensionKind extension) =>
144 _knownUnsupportedExtensions.Contains(extension);
145
147 OptimizationObjectiveKind objectiveKind) =>
148 _supportedObjectiveKinds.Contains(objectiveKind);
149}
MathematicalFormulationScientificProfile(string formulationId, string formulationFamily, IEnumerable< CanonicalLotSizingProblemClassId > supportedProblemClasses, IEnumerable< LotSizingProblemClassExtensionKind >? supportedExtensions=null, IEnumerable< LotSizingProblemClassExtensionKind >? knownUnsupportedExtensions=null, IEnumerable< OptimizationObjectiveKind >? supportedObjectiveKinds=null, IEnumerable< string >? evidence=null)