LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
UlsAlgorithmsHeuristicCatalog.cs
Go to the documentation of this file.
1using ULSAlgorithms.Abstractions;
2using ULSAlgorithms.Catalog;
3
5
6/// <summary>
7/// Pinned public ULSAlgorithms v1.1.0 heuristic inventory.
8/// </summary>
10{
11 private static readonly string[] PinnedIds =
12 [
13 "chiu-modified-least-unit-cost",
14 "chiu-ting-modified-part-period-balancing",
15 "freeland-colley",
16 "groff",
17 "ho-chang-solis-improved-net-least-period-cost",
18 "ho-chang-solis-net-least-period-cost",
19 "karni-maximum-part-period-gain",
20 "least-unit-cost",
21 "lot-for-lot",
22 "mclaren-order-moment",
23 "part-period-balancing",
24 "part-period-simplified",
25 "patterson-laforge-incremental-part-period",
26 "periodic-order-quantity",
27 "segerstedt-reformulated-silver-meal",
28 "silver-meal",
29 "wemmerlov-modified-ppb",
30 "wemmerlov-modified-ppb-lalb",
31 "wemmerlov-ppb-lalb"
32 ];
33
34 public static IReadOnlyList<string> SolverIds =>
35 PinnedIds;
36
37 public static IReadOnlyList<UlsSolverDescriptor>
39 {
40 UlsSolverDescriptor[] actual =
41 UlsSolverCatalog.Heuristics
42 .OrderBy(
43 descriptor =>
44 descriptor.Id,
45 StringComparer.Ordinal)
46 .ToArray();
47
48 string[] actualIds =
49 actual
50 .Select(
51 descriptor =>
52 descriptor.Id)
53 .ToArray();
54
55 if (!actualIds.SequenceEqual(
56 PinnedIds,
57 StringComparer.Ordinal))
58 {
59 throw new InvalidOperationException(
60 "The ULSAlgorithms v1.1.0 heuristic catalog does not match the alpha.35 pinned inventory.");
61 }
62
63 foreach (UlsSolverDescriptor descriptor
64 in actual)
65 {
66 EnsureHeuristicDescriptor(
67 descriptor);
68 }
69
70 return actual;
71 }
72
73 public static UlsSolverDescriptor GetRequired(
74 string solverId)
75 {
76 if (string.IsNullOrWhiteSpace(
77 solverId))
78 {
79 throw new ArgumentException(
80 "A ULSAlgorithms heuristic solver ID is required.",
81 nameof(solverId));
82 }
83
84 string normalized =
85 solverId.Trim();
86
87 if (!PinnedIds.Contains(
88 normalized,
89 StringComparer.Ordinal))
90 {
91 throw new ArgumentOutOfRangeException(
92 nameof(solverId),
93 solverId,
94 "The requested method is not one of the alpha.35 pinned ULSAlgorithms heuristics.");
95 }
96
97 UlsSolverDescriptor descriptor =
98 UlsSolverCatalog.Get(
99 normalized);
100
101 EnsureHeuristicDescriptor(
102 descriptor);
103
104 return descriptor;
105 }
106
107 private static void EnsureHeuristicDescriptor(
108 UlsSolverDescriptor descriptor)
109 {
110 if (descriptor.Kind !=
111 UlsSolverKind.Heuristic ||
112 descriptor.Category !=
113 UlsSolverCategory.Heuristic)
114 {
115 throw new InvalidOperationException(
116 $"ULSAlgorithms solver '{descriptor.Id}' is not classified as a heuristic.");
117 }
118
119 if (descriptor.RequiresExternalSolver)
120 {
121 throw new InvalidOperationException(
122 $"Pinned heuristic '{descriptor.Id}' unexpectedly requires an external optimization solver.");
123 }
124 }
125}