10 private readonly Dictionary<int, int> _indexByVariableId;
15 ArgumentNullException.ThrowIfNull(
30 if (_variables.Length == 0)
32 throw new InvalidOperationException(
33 "A metaheuristic mathematical model requires at least one variable.");
52 public IReadOnlyList<MathematicalVariable>
Variables =>
59 IReadOnlyList<double> values)
62 _model.Objective.Expression,
68 IReadOnlyList<double> values)
70 ArgumentNullException.ThrowIfNull(
82 if (!_indexByVariableId.TryGetValue(
86 throw new InvalidOperationException(
87 $
"Expression references unknown variable identifier '{term.VariableId}'.");
98 throw new InvalidOperationException(
99 "Candidate expression evaluation must be finite.");
107 IReadOnlyList<double> values)
109 ArgumentNullException.ThrowIfNull(
112 double leftHandSide =
117 return constraint.Sense
switch
124 constraint.RightHandSide -
132 throw new NotSupportedException(
133 $
"Constraint sense '{constraint.Sense}' is not supported by the metaheuristic bridge.")
138 IReadOnlyList<double> values,
139 double tolerance = 1.0e-7)
148 index < _variables.Length;
157 if (!
double.IsFinite(
183 MidpointRounding.AwayFromZero)) >
192 if (Math.Abs(value) >
194 Math.Abs(value - 1.0) >
204 throw new NotSupportedException(
205 "Semi-continuous and semi-integer domains are not enabled in alpha.37.");
208 throw new NotSupportedException(
209 $
"Variable type '{variable.VariableType}' is not supported by alpha.37.");
217 IReadOnlyList<double> values,
218 double equalityTolerance = 1.0e-6)
227 in _model.Constraints)
239 if (constraint.
Sense ==
260 IReadOnlyList<double> values,
261 double equalityTolerance = 1.0e-6)
265 equalityTolerance) &&
274 ArgumentNullException.ThrowIfNull(
278 new double[_variables.Length];
281 index < _variables.Length;
293 throw new InvalidOperationException(
294 $
"Solver result does not contain variable identifier '{variable.Id}'.");
304 private void EnsureDimension(
305 IReadOnlyList<double> values)
307 ArgumentNullException.ThrowIfNull(
313 throw new ArgumentException(
314 $
"Expected candidate dimension {Dimension}, received {values.Count}.",
319 private static void EnsureTolerance(
322 if (!
double.IsFinite(
326 throw new ArgumentOutOfRangeException(
Stores the solver result for a solver-independent mathematical model.
MathematicalVariableValue? FindVariableValue(int variableId)
Finds a variable value by mathematical-variable identifier.
Stores the value returned by a solver for one mathematical decision variable.
double Value
Gets or sets the value returned by the solver.
Represents one linear constraint in a mathematical optimization model.
double RightHandSide
Gets or sets the right-hand-side constant value.
MathematicalConstraintSense Sense
Gets or sets the relational sense of the constraint.
bool IsEnabled
Gets or sets a value indicating whether the constraint is enabled.
LinearExpression LeftHandSide
Gets or sets the left-hand-side linear expression.
Represents a linear expression composed of variable terms and a constant value.
double Constant
Gets or sets the constant value of the expression.
Represents one coefficient-variable term in a linear expression.
int VariableId
Gets or sets the identifier of the referenced mathematical variable.
Represents a solver-independent mathematical optimization model.
void EnsureValid()
Validates the complete mathematical model.
Represents one decision variable in a mathematical optimization model.
MathematicalVariableType VariableType
Gets or sets the variable domain.
int Id
Gets or sets the unique variable identifier within the mathematical model.
double LowerBound
Gets or sets the variable lower bound.
double UpperBound
Gets or sets the variable upper bound.
MathematicalConstraintSense
Identifies the relational sense of a mathematical constraint.
@ GreaterThanOrEqual
The left-hand side must be greater than or equal to the right-hand side.
@ LessThanOrEqual
The left-hand side must be less than or equal to the right-hand side.
@ Equal
The left-hand side must be equal to the right-hand side.
MathematicalVariableType
Identifies the domain of a mathematical decision variable.