LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
LagrangianMultiplierDomain.cs
Go to the documentation of this file.
2
4
5/// <summary>
6/// Encodes the multiplier-domain convention that guarantees a
7/// valid lower bound for minimization models when the residual is
8/// defined as left-hand side minus right-hand side.
9/// </summary>
10public static class LagrangianMultiplierDomain
11{
12 public static void EnsureValid(
14 double multiplier)
15 {
16 if (double.IsNaN(multiplier) ||
17 double.IsInfinity(multiplier))
18 {
19 throw new InvalidOperationException(
20 "A Lagrangian multiplier must be finite.");
21 }
22
23 switch (sense)
24 {
25 case MathematicalConstraintSense.LessThanOrEqual:
26 if (multiplier < 0.0)
27 {
28 throw new InvalidOperationException(
29 "A relaxed <= constraint requires a non-negative multiplier in a minimization model.");
30 }
31
32 break;
33
34 case MathematicalConstraintSense.GreaterThanOrEqual:
35 if (multiplier > 0.0)
36 {
37 throw new InvalidOperationException(
38 "A relaxed >= constraint requires a non-positive multiplier in a minimization model.");
39 }
40
41 break;
42
44 break;
45
46 default:
47 throw new NotSupportedException(
48 $"Constraint sense '{sense}' cannot be Lagrangian-relaxed.");
49 }
50 }
51
52 public static double Project(
54 double value)
55 {
56 if (double.IsNaN(value) ||
57 double.IsInfinity(value))
58 {
59 throw new InvalidOperationException(
60 "A projected multiplier value must be finite.");
61 }
62
63 return sense switch
64 {
66 Math.Max(
67 0.0,
68 value),
69
71 Math.Min(
72 0.0,
73 value),
74
76 value,
77
78 _ =>
79 throw new NotSupportedException(
80 $"Constraint sense '{sense}' cannot be Lagrangian-relaxed.")
81 };
82 }
83}
Encodes the multiplier-domain convention that guarantees a valid lower bound for minimization models ...
static void EnsureValid(MathematicalConstraintSense sense, double multiplier)
static double Project(MathematicalConstraintSense sense, double value)
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.