LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
LagrangianRelaxationModelBuilder.cs
Go to the documentation of this file.
2
4
5/// <summary>
6/// Builds a source-preserving Lagrangian relaxation for a
7/// minimization model.
8/// </summary>
9/// <remarks>
10/// For every selected constraint the residual is
11/// <c>lhs - rhs</c>. The term
12/// <c>lambda * (lhs - rhs)</c> is added to the objective and the
13/// cloned constraint is disabled. Multiplier signs are validated
14/// by <see cref="LagrangianMultiplierDomain"/>.
15/// </remarks>
17{
19 MathematicalModel sourceModel,
21 {
22 ArgumentNullException.ThrowIfNull(
23 sourceModel);
24
25 ArgumentNullException.ThrowIfNull(
26 specification);
27
28 sourceModel.EnsureValid();
29
30 specification.EnsureValidAgainst(
31 sourceModel);
32
33 MathematicalModel relaxedModel =
34 sourceModel.Clone();
35
36 var relaxedIdentifiers =
37 new List<int>();
38
39 foreach (LagrangianMultiplier multiplier
40 in specification.Multipliers)
41 {
42 LinearConstraint sourceConstraint =
43 sourceModel.Constraints.Single(
44 constraint =>
45 constraint.Id ==
46 multiplier.ConstraintId);
47
48 LinearConstraint relaxedConstraint =
49 relaxedModel.Constraints.Single(
50 constraint =>
51 constraint.Id ==
52 multiplier.ConstraintId);
53
54 var residual =
55 sourceConstraint.LeftHandSide.Clone();
56
57 residual.AddConstant(
58 -sourceConstraint.RightHandSide);
59
60 residual.MultiplyBy(
61 multiplier.Value);
62
63 relaxedModel.Objective.Expression.Add(
64 residual);
65
66 relaxedConstraint.IsEnabled =
67 false;
68
69 relaxedIdentifiers.Add(
70 sourceConstraint.Id);
71 }
72
73 relaxedModel.Description =
74 string.IsNullOrWhiteSpace(
75 sourceModel.Description)
76 ? "Lagrangian-relaxed clone."
77 : sourceModel.Description.Trim() +
78 " Lagrangian-relaxed clone.";
79
80 relaxedModel.EnsureValid();
81
83 relaxedModel,
84 relaxedIdentifiers);
85 }
86}
Associates one relaxed mathematical constraint with its Lagrangian multiplier.
Builds a source-preserving Lagrangian relaxation for a minimization model.
LagrangianRelaxationBuildResult Build(MathematicalModel sourceModel, LagrangianRelaxationSpecification specification)
Explicit immutable set of constraints and multipliers used to construct one Lagrangian-relaxed mathem...
Represents one linear constraint in a mathematical optimization model.
double RightHandSide
Gets or sets the right-hand-side constant value.
LinearExpression LeftHandSide
Gets or sets the left-hand-side linear expression.
int Id
Gets or sets the unique constraint identifier within the mathematical model.
LinearExpression Clone()
Creates an independent copy of this expression.
void AddConstant(double value)
Adds a constant value to the expression.
Represents a solver-independent mathematical optimization model.
MathematicalModel Clone()
Creates an independent copy of the mathematical model.
void EnsureValid()
Validates the complete mathematical model.