ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
LinearModelBuilder.cs
Go to the documentation of this file.
2
4
5internal sealed class LinearModelBuilder
6{
7 private readonly List<LinearVariable> _variables = [];
8 private readonly List<LinearConstraint> _constraints = [];
9 private readonly List<LinearTerm> _objectiveTerms = [];
10
11 internal int AddVariable(
12 string name,
14 double lowerBound,
15 double upperBound)
16 {
17 int id =
18 _variables.Count;
19
20 _variables.Add(
22 id,
23 name,
24 type,
25 lowerBound,
26 upperBound));
27
28 return id;
29 }
30
31 internal void AddConstraint(
32 string name,
33 IEnumerable<LinearTerm> terms,
35 double rightHandSide)
36 {
37 _constraints.Add(
39 name,
40 terms,
41 sense,
42 rightHandSide));
43 }
44
45 internal void AddObjectiveTerm(
46 int variableId,
47 double coefficient)
48 {
49 if (coefficient == 0.0)
50 {
51 return;
52 }
53
54 _objectiveTerms.Add(
55 new LinearTerm(
56 variableId,
57 coefficient));
58 }
59
61 string name,
62 double objectiveConstant = 0.0)
63 {
64 LinearTerm[] combinedObjective =
65 _objectiveTerms
66 .GroupBy(
67 static term =>
68 term.VariableId)
69 .Select(
70 group =>
71 new LinearTerm(
72 group.Key,
73 group.Sum(
74 static term =>
75 term.Coefficient)))
76 .Where(
77 static term =>
78 term.Coefficient != 0.0)
79 .OrderBy(
80 static term =>
81 term.VariableId)
82 .ToArray();
83
84 return new LinearModel(
85 name,
86 _variables,
87 _constraints,
89 combinedObjective,
90 objectiveConstant));
91 }
92}
void AddConstraint(string name, IEnumerable< LinearTerm > terms, LinearConstraintSense sense, double rightHandSide)
int AddVariable(string name, LinearVariableType type, double lowerBound, double upperBound)
void AddObjectiveTerm(int variableId, double coefficient)
LinearModel Build(string name, double objectiveConstant=0.0)
Describes one portable linear constraint.
Immutable solver-independent linear or mixed-integer linear model.
Definition LinearModel.cs:7
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.
LinearConstraintSense
Identifies the sense of a portable linear constraint.
Stores one coefficient of a portable linear expression.
Definition LinearTerm.cs:7