14 IEnumerable<LinearVariable> variables,
15 IEnumerable<LinearConstraint> constraints,
18 if (
string.IsNullOrWhiteSpace(name))
20 throw new ArgumentException(
21 "A model name is required.",
25 ArgumentNullException.ThrowIfNull(variables);
26 ArgumentNullException.ThrowIfNull(constraints);
27 ArgumentNullException.ThrowIfNull(objective);
29 _variables = variables.ToArray();
30 _constraints = constraints.ToArray();
37 .Count() != _variables.Length)
39 throw new ArgumentException(
40 "Variable identifiers must be unique.",
49 StringComparer.Ordinal)
50 .Count() != _variables.Length)
52 throw new ArgumentException(
53 "Variable names must be unique.",
70 throw new ArgumentException(
71 $
"Constraint '{constraint.Name}' references unknown " +
72 $
"variable id {term.VariableId}.",
82 throw new ArgumentException(
83 $
"The objective references unknown variable id " +
84 $
"{term.VariableId}.",
94 public string Name {
get; }
97 public IReadOnlyList<LinearVariable>
Variables => _variables;
100 public IReadOnlyList<LinearConstraint>
Constraints => _constraints;
121 return _variables.First(
Describes one portable linear constraint.
IReadOnlyList< LinearTerm > Terms
Gets the nonzero terms.
IReadOnlyList< LinearVariable > Variables
Gets all variables.
LinearVariable GetVariable(int id)
Finds a variable by id.
int ConstraintCount
Gets the number of constraints.
LinearObjective Objective
Gets the minimization objective.
LinearModel(string name, IEnumerable< LinearVariable > variables, IEnumerable< LinearConstraint > constraints, LinearObjective objective)
Initializes a portable model.
IReadOnlyList< LinearConstraint > Constraints
Gets all constraints.
bool IsMixedInteger
Gets whether the model contains integer or binary variables.
string Name
Gets the model name.
int VariableCount
Gets the number of variables.
Describes the minimization objective of a portable linear model.
Describes one variable in a portable linear mathematical model.
LinearVariableType
Identifies the domain of a variable in a portable linear mathematical model.
Stores one coefficient of a portable linear expression.
int VariableId
Gets the referenced variable identifier.