2using System.Collections.Generic;
28 private readonly List<LinearTerm> _inflows =
31 private readonly List<LinearTerm> _outflows =
79 ArgumentNullException.ThrowIfNull(
83 backlog?.EnsureValid();
84 shortage?.EnsureValid();
119 backlog?.EnsureValid();
120 shortage?.EnsureValid();
148 double coefficient = 1.0)
154 nameof(coefficient));
173 double coefficient = 1.0)
179 nameof(coefficient));
202 _currentInventory!.Id,
205 if (_currentBacklog is not
null)
212 if (_currentShortage is not
null)
219 if (_previousInventory is not
null)
222 _previousInventory.Id,
226 if (_previousBacklog is not
null)
233 if (_previousShortage is not
null)
236 _previousShortage.Id,
258 expression.EnsureValid();
285 string domainKey =
"",
286 string description =
"")
288 ArgumentNullException.ThrowIfNull(
308 if (_currentInventory is
null)
310 throw new InvalidOperationException(
311 "A current-period inventory variable is " +
320 throw new InvalidOperationException(
321 "Inventory-balance demand must be finite.");
339 private static void AddFlowTerm(
340 ICollection<LinearTerm> target,
343 string coefficientName)
345 ArgumentNullException.ThrowIfNull(
356 throw new ArgumentOutOfRangeException(
359 "A flow coefficient must be finite and " +
360 "strictly positive.");
Builds a corrected inventory-balance constraint for one item, location, and period.
InventoryBalanceConstraintBuilder AddInflow(MathematicalVariable variable, double coefficient=1.0)
Adds an inflow variable to the balance.
InventoryBalanceConstraintBuilder AddOutflow(MathematicalVariable variable, double coefficient=1.0)
Adds an outflow variable to the balance.
void EnsureValid()
Validates the inventory-balance definition.
LinearExpression BuildExpression()
Builds the corrected inventory-balance expression.
InventoryBalanceConstraintBuilder SetCurrentState(MathematicalVariable inventory, MathematicalVariable? backlog=null, MathematicalVariable? shortage=null)
Assigns the current-period inventory state variables.
double Demand
Gets or sets the external demand for the period.
InventoryBalanceConstraintBuilder SetPreviousState(MathematicalVariable? inventory, MathematicalVariable? backlog=null, MathematicalVariable? shortage=null)
Assigns the previous-period inventory state variables.
LinearConstraint AddToModel(MathematicalModelBuilder modelBuilder, string name, string domainKey="", string description="")
Adds the corrected inventory-balance constraint to a mathematical model.
Builds a solver-independent mathematical model while assigning unique variable and constraint identif...
LinearConstraint AddConstraint(string name, LinearExpression leftHandSide, MathematicalConstraintSense sense, double rightHandSide, string domainKey="", string description="")
Creates and adds a linear constraint.
Represents one linear constraint in a mathematical optimization model.
Represents a linear expression composed of variable terms and a constant value.
Represents one coefficient-variable term in a linear expression.
int VariableId
Gets or sets the identifier of the referenced mathematical variable.
double Coefficient
Gets or sets the coefficient multiplying the referenced variable.
void EnsureValid()
Validates the linear term.
Represents one decision variable in a mathematical optimization model.
int Id
Gets or sets the unique variable identifier within the mathematical model.
void EnsureValid()
Validates the mathematical variable.
MathematicalConstraintSense
Identifies the relational sense of a mathematical constraint.