LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
LagrangianConstraintResidualEvaluator.cs
Go to the documentation of this file.
2
4
5/// <summary>
6/// Evaluates the canonical Lagrangian residual
7/// left-hand side minus right-hand side.
8/// </summary>
10{
11 public static double Evaluate(
12 LinearConstraint constraint,
13 IReadOnlyDictionary<int, double> variableValues)
14 {
15 ArgumentNullException.ThrowIfNull(
16 constraint);
17
18 ArgumentNullException.ThrowIfNull(
19 variableValues);
20
21 double value =
22 constraint.LeftHandSide.Constant -
23 constraint.RightHandSide;
24
25 foreach (LinearTerm term
26 in constraint.LeftHandSide.Terms)
27 {
28 if (!variableValues.TryGetValue(
29 term.VariableId,
30 out double variableValue))
31 {
32 throw new KeyNotFoundException(
33 $"No value is available for variable identifier '{term.VariableId}'.");
34 }
35
36 if (double.IsNaN(variableValue) ||
37 double.IsInfinity(variableValue))
38 {
39 throw new InvalidOperationException(
40 $"Variable identifier '{term.VariableId}' has a non-finite value.");
41 }
42
43 value +=
44 term.Coefficient *
45 variableValue;
46 }
47
48 if (double.IsNaN(value) ||
49 double.IsInfinity(value))
50 {
51 throw new InvalidOperationException(
52 "The evaluated Lagrangian residual is not finite.");
53 }
54
55 return value;
56 }
57}
Evaluates the canonical Lagrangian residual left-hand side minus right-hand side.
static double Evaluate(LinearConstraint constraint, IReadOnlyDictionary< int, double > variableValues)
Represents one linear constraint in a mathematical optimization model.
double RightHandSide
Gets or sets the right-hand-side constant value.
Represents one coefficient-variable term in a linear expression.
Definition LinearTerm.cs:13
int VariableId
Gets or sets the identifier of the referenced mathematical variable.
Definition LinearTerm.cs:49