LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
SolverRequest.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Xml.Serialization;
4using LotSizingDataModel.Instance;
8
10
11/// <summary>
12/// Describes a request to solve a lot-sizing instance.
13/// </summary>
14[Serializable]
15[XmlType(TypeName = "solverRequest")]
16public sealed class SolverRequest
17{
18 private readonly List<ISolverProgressObserver>
19 _progressObservers =
20 new();
21
22 /// <summary>
23 /// Initializes an empty solver request.
24 /// </summary>
26 {
28 SolverKind.Automatic;
29
31 string.Empty;
32
33 RunName =
34 string.Empty;
35
37 new SolverParameters();
38 }
39
40 /// <summary>
41 /// Initializes a solver request for an instance.
42 /// </summary>
43 /// <param name="instance">
44 /// Lot-sizing instance to solve.
45 /// </param>
47 LotSizingInstance instance)
48 : this()
49 {
50 ArgumentNullException.ThrowIfNull(
51 instance);
52
53 Instance =
54 instance;
55 }
56
57 /// <summary>
58 /// Gets or sets the lot-sizing instance to solve.
59 /// </summary>
60 [XmlIgnore]
61 public LotSizingInstance? Instance
62 {
63 get;
64 set;
65 }
66
67 /// <summary>
68 /// Gets or sets the preferred solver.
69 /// </summary>
70 /// <remarks>
71 /// <see cref="SolverKind.Automatic"/> requests automatic
72 /// selection among the adapters available on the current
73 /// computer.
74 /// </remarks>
75 [XmlAttribute("preferredSolver")]
77 {
78 get;
79 set;
80 }
81
82 /// <summary>
83 /// Gets or sets the formulation name to use.
84 /// </summary>
85 /// <remarks>
86 /// An empty value requests the default formulation selected
87 /// by the formulation service.
88 /// </remarks>
89 [XmlElement("formulationName")]
90 public string FormulationName
91 {
92 get;
93 set;
94 }
95
96 /// <summary>
97 /// Gets or sets a user-defined name for the solver run.
98 /// </summary>
99 [XmlElement("runName")]
100 public string RunName
101 {
102 get;
103 set;
104 }
105
106 /// <summary>
107 /// Gets or sets the solver parameters.
108 /// </summary>
109 [XmlElement("parameters")]
111 {
112 get;
113 set;
114 }
115
116 /// <summary>
117 /// Gets the progress observers attached to this request.
118 /// </summary>
119 [XmlIgnore]
120 public IList<ISolverProgressObserver> ProgressObservers =>
121 _progressObservers;
122
123 /// <summary>
124 /// Validates the solver request.
125 /// </summary>
126 /// <exception cref="InvalidOperationException">
127 /// Thrown when the request is incomplete or invalid.
128 /// </exception>
129 public void EnsureValid()
130 {
131 if (Instance is null)
132 {
133 throw new InvalidOperationException(
134 "A lot-sizing instance is required.");
135 }
136
137 if (PreferredSolver ==
138 SolverKind.Unknown)
139 {
140 throw new InvalidOperationException(
141 "The preferred solver cannot be Unknown.");
142 }
143
144 ArgumentNullException.ThrowIfNull(
145 Parameters);
146
147 Parameters.EnsureValid();
148
149 foreach (
151 in _progressObservers)
152 {
153 if (observer is null)
154 {
155 throw new InvalidOperationException(
156 "The progress-observer collection cannot " +
157 "contain a null entry.");
158 }
159 }
160 }
161
162 /// <summary>
163 /// Adds a progress observer.
164 /// </summary>
165 /// <param name="observer">
166 /// Observer to attach.
167 /// </param>
168 /// <exception cref="ArgumentNullException">
169 /// Thrown when <paramref name="observer"/> is
170 /// <see langword="null"/>.
171 /// </exception>
174 {
175 ArgumentNullException.ThrowIfNull(
176 observer);
177
178 _progressObservers.Add(
179 observer);
180 }
181}
Defines solver-independent parameters for an optimization run.
string FormulationName
Gets or sets the formulation name to use.
void EnsureValid()
Validates the solver request.
IList< ISolverProgressObserver > ProgressObservers
Gets the progress observers attached to this request.
string RunName
Gets or sets a user-defined name for the solver run.
SolverKind PreferredSolver
Gets or sets the preferred solver.
void AddProgressObserver(ISolverProgressObserver observer)
Adds a progress observer.
LotSizingInstance? Instance
Gets or sets the lot-sizing instance to solve.
SolverRequest()
Initializes an empty solver request.
SolverRequest(LotSizingInstance instance)
Initializes a solver request for an instance.
SolverParameters Parameters
Gets or sets the solver parameters.
Receives progress notifications produced during a solver execution.
SolverKind
Identifies a supported mathematical optimization solver.
Definition SolverKind.cs:12