LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
MathematicalModelSolveRequest.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Xml.Serialization;
7
9
10/// <summary>
11/// Describes a request to solve an already built,
12/// solver-independent mathematical model.
13/// </summary>
14/// <remarks>
15/// This request is used after formulation selection and model
16/// construction. Solver adapters receive the same mathematical
17/// model and are therefore responsible only for translating and
18/// solving it with their native optimization engine.
19/// </remarks>
20[Serializable]
21[XmlType(TypeName = "mathematicalModelSolveRequest")]
23{
24 private readonly List<ISolverProgressObserver> _progressObservers =
25 new();
26
27 /// <summary>
28 /// Initializes an empty mathematical-model solve request.
29 /// </summary>
31 {
32 RunName =
33 string.Empty;
34
36 string.Empty;
37
39 new SolverParameters();
40 }
41
42 /// <summary>
43 /// Gets or sets the mathematical model to solve.
44 /// </summary>
45 [XmlIgnore]
47 {
48 get;
49 set;
50 }
51
52 /// <summary>
53 /// Gets or sets an optional run name.
54 /// </summary>
55 [XmlAttribute("runName")]
56 public string RunName
57 {
58 get;
59 set;
60 }
61
62 /// <summary>
63 /// Gets or sets the identifier of the formulation that
64 /// generated the mathematical model.
65 /// </summary>
66 [XmlAttribute("formulationId")]
67 public string FormulationId
68 {
69 get;
70 set;
71 }
72
73 /// <summary>
74 /// Gets or sets the generic solver parameters.
75 /// </summary>
76 [XmlElement("parameters")]
78 {
79 get;
80 set;
81 }
82
83 /// <summary>
84 /// Gets the progress observers attached to the solve run.
85 /// </summary>
86 /// <remarks>
87 /// Runtime observer objects are intentionally excluded from
88 /// XML serialization.
89 /// </remarks>
90 [XmlIgnore]
91 public List<ISolverProgressObserver> ProgressObservers =>
92 _progressObservers;
93
94 /// <summary>
95 /// Validates the mathematical-model solve request.
96 /// </summary>
97 /// <exception cref="InvalidOperationException">
98 /// Thrown when the mathematical model or solver parameters
99 /// are missing or invalid.
100 /// </exception>
101 public void EnsureValid()
102 {
103 if (Model is null)
104 {
105 throw new InvalidOperationException(
106 "A mathematical model is required.");
107 }
108
109 Model.EnsureValid();
110
111 if (Parameters is null)
112 {
113 throw new InvalidOperationException(
114 "Solver parameters are required.");
115 }
116
117 Parameters.EnsureValid();
118
119 RunName =
120 RunName?.Trim() ??
121 string.Empty;
122
124 FormulationId?.Trim() ??
125 string.Empty;
126
127 foreach (
129 in _progressObservers)
130 {
131 if (observer is null)
132 {
133 throw new InvalidOperationException(
134 "The progress-observer collection cannot " +
135 "contain a null entry.");
136 }
137 }
138 }
139}
Defines solver-independent parameters for an optimization run.
string FormulationId
Gets or sets the identifier of the formulation that generated the mathematical model.
MathematicalModel? Model
Gets or sets the mathematical model to solve.
SolverParameters Parameters
Gets or sets the generic solver parameters.
MathematicalModelSolveRequest()
Initializes an empty mathematical-model solve request.
List< ISolverProgressObserver > ProgressObservers
Gets the progress observers attached to the solve run.
void EnsureValid()
Validates the mathematical-model solve request.
Represents a solver-independent mathematical optimization model.
Receives progress notifications produced during a solver execution.