LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
SolverAdapterDescriptor.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Xml.Serialization;
4
6
7/// <summary>
8/// Describes a solver adapter without loading or executing its
9/// native optimization engine.
10/// </summary>
11[Serializable]
12[XmlType(TypeName = "solverAdapterDescriptor")]
13public sealed class SolverAdapterDescriptor
14{
15 private readonly List<SolverCapability> _capabilities =
16 new();
17
18 /// <summary>
19 /// Initializes an empty solver-adapter descriptor.
20 /// </summary>
22 {
23 AdapterId =
24 string.Empty;
25
27 string.Empty;
28
30 string.Empty;
31
33 string.Empty;
34
36 string.Empty;
37
38 TypeName =
39 string.Empty;
40 }
41
42 /// <summary>
43 /// Gets or sets the unique adapter identifier.
44 /// </summary>
45 [XmlAttribute("adapterId")]
46 public string AdapterId
47 {
48 get;
49 set;
50 }
51
52 /// <summary>
53 /// Gets or sets the adapter display name.
54 /// </summary>
55 [XmlElement("adapterName")]
56 public string AdapterName
57 {
58 get;
59 set;
60 }
61
62 /// <summary>
63 /// Gets or sets the adapter implementation version.
64 /// </summary>
65 [XmlElement("adapterVersion")]
66 public string AdapterVersion
67 {
68 get;
69 set;
70 }
71
72 /// <summary>
73 /// Gets or sets the solver kind implemented by the adapter.
74 /// </summary>
75 [XmlAttribute("solverKind")]
77 {
78 get;
79 set;
80 }
81
82 /// <summary>
83 /// Gets or sets the minimum supported native solver
84 /// version.
85 /// </summary>
86 [XmlElement("minimumSupportedSolverVersion")]
88 {
89 get;
90 set;
91 }
92
93 /// <summary>
94 /// Gets or sets the full path of the adapter assembly.
95 /// </summary>
96 [XmlElement("assemblyPath")]
97 public string AssemblyPath
98 {
99 get;
100 set;
101 }
102
103 /// <summary>
104 /// Gets or sets the assembly-qualified adapter type name.
105 /// </summary>
106 [XmlElement("typeName")]
107 public string TypeName
108 {
109 get;
110 set;
111 }
112
113 /// <summary>
114 /// Gets the capabilities declared by the adapter.
115 /// </summary>
116 [XmlArray("capabilities")]
117 [XmlArrayItem("capability")]
118 public List<SolverCapability> Capabilities =>
119 _capabilities;
120
121 /// <summary>
122 /// Validates the adapter descriptor.
123 /// </summary>
124 /// <exception cref="InvalidOperationException">
125 /// Thrown when required metadata is missing or invalid.
126 /// </exception>
127 public void EnsureValid()
128 {
129 if (string.IsNullOrWhiteSpace(
130 AdapterId))
131 {
132 throw new InvalidOperationException(
133 "A solver adapter identifier is required.");
134 }
135
136 if (string.IsNullOrWhiteSpace(
138 {
139 throw new InvalidOperationException(
140 "A solver adapter name is required.");
141 }
142
143 if (string.IsNullOrWhiteSpace(
145 {
146 throw new InvalidOperationException(
147 "A solver adapter version is required.");
148 }
149
150 if (SolverKind is
151 SolverKind.Unknown or
152 SolverKind.Automatic)
153 {
154 throw new InvalidOperationException(
155 "A solver adapter must target a concrete " +
156 "solver kind.");
157 }
158
159 foreach (
160 SolverCapability capability
161 in _capabilities)
162 {
163 if (capability ==
164 SolverCapability.Unknown)
165 {
166 throw new InvalidOperationException(
167 "The capability collection cannot contain " +
168 "Unknown.");
169 }
170 }
171 }
172
173 /// <summary>
174 /// Gets a value indicating whether the adapter declares the
175 /// specified capability.
176 /// </summary>
177 /// <param name="capability">
178 /// Capability to test.
179 /// </param>
180 /// <returns>
181 /// <see langword="true"/> when the capability is declared;
182 /// otherwise, <see langword="false"/>.
183 /// </returns>
185 SolverCapability capability)
186 {
187 return _capabilities.Contains(
188 capability);
189 }
190}
string AdapterVersion
Gets or sets the adapter implementation version.
bool SupportsCapability(SolverCapability capability)
Gets a value indicating whether the adapter declares the specified capability.
string AdapterName
Gets or sets the adapter display name.
string MinimumSupportedSolverVersion
Gets or sets the minimum supported native solver version.
SolverKind SolverKind
Gets or sets the solver kind implemented by the adapter.
List< SolverCapability > Capabilities
Gets the capabilities declared by the adapter.
string AdapterId
Gets or sets the unique adapter identifier.
string TypeName
Gets or sets the assembly-qualified adapter type name.
string AssemblyPath
Gets or sets the full path of the adapter assembly.
SolverAdapterDescriptor()
Initializes an empty solver-adapter descriptor.
SolverCapability
Identifies an optional capability implemented by a solver adapter.