LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
LagrangianRelaxationSpecification.cs
Go to the documentation of this file.
2
4
5/// <summary>
6/// Explicit immutable set of constraints and multipliers used to
7/// construct one Lagrangian-relaxed mathematical model.
8/// </summary>
10{
11 private readonly LagrangianMultiplier[] _multipliers;
12
14 IEnumerable<LagrangianMultiplier> multipliers)
15 {
16 ArgumentNullException.ThrowIfNull(
17 multipliers);
18
19 _multipliers =
20 multipliers.ToArray();
21
22 if (_multipliers.Length == 0)
23 {
24 throw new InvalidOperationException(
25 "At least one constraint must be selected for Lagrangian relaxation.");
26 }
27
29 }
30
31 public IReadOnlyList<LagrangianMultiplier> Multipliers =>
32 _multipliers;
33
34 public void EnsureValid()
35 {
36 var identifiers =
37 new HashSet<int>();
38
39 foreach (LagrangianMultiplier multiplier
40 in _multipliers)
41 {
42 ArgumentNullException.ThrowIfNull(
43 multiplier);
44
45 multiplier.EnsureValid();
46
47 if (!identifiers.Add(
48 multiplier.ConstraintId))
49 {
50 throw new InvalidOperationException(
51 $"Constraint identifier '{multiplier.ConstraintId}' appears more than once in the Lagrangian specification.");
52 }
53 }
54 }
55
56 public void EnsureValidAgainst(
58 {
59 ArgumentNullException.ThrowIfNull(
60 model);
61
63
64 if (model.Objective.Sense !=
65 ObjectiveSense.Minimize)
66 {
67 throw new NotSupportedException(
68 "The alpha.36 Lagrangian foundation currently supports minimization models only.");
69 }
70
71 foreach (LagrangianMultiplier multiplier
72 in _multipliers)
73 {
74 LinearConstraint? constraint =
75 model.Constraints.FirstOrDefault(
76 candidate =>
77 candidate.Id ==
78 multiplier.ConstraintId);
79
80 if (constraint is null)
81 {
82 throw new InvalidOperationException(
83 $"Constraint identifier '{multiplier.ConstraintId}' does not exist in the source model.");
84 }
85
86 if (!constraint.IsEnabled)
87 {
88 throw new InvalidOperationException(
89 $"Constraint '{constraint.Name}' is already disabled and cannot be selected for relaxation.");
90 }
91
93 constraint.Sense,
94 multiplier.Value);
95 }
96 }
97}
Encodes the multiplier-domain convention that guarantees a valid lower bound for minimization models ...
static void EnsureValid(MathematicalConstraintSense sense, double multiplier)
Associates one relaxed mathematical constraint with its Lagrangian multiplier.
Represents one linear constraint in a mathematical optimization model.
MathematicalConstraintSense Sense
Gets or sets the relational sense of the constraint.
bool IsEnabled
Gets or sets a value indicating whether the constraint is enabled.
Represents a solver-independent mathematical optimization model.
MathematicalObjective Objective
Gets or sets the mathematical objective.
ObjectiveSense Sense
Gets or sets the optimization direction.
ObjectiveSense
Identifies the optimization direction of a mathematical objective.