You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`findFeasibleSolution` takes a list of `PolyConstraint`s.
18
18
The `PolyConstraint` type, as well as other custom types required by this library, are defined in the `Linear.Simplex.Types` module.
19
19
`PolyConstraint` is defined as:
20
20
21
21
```haskell
22
-
dataPolyConstraint=
23
-
LEQVarsRational |
24
-
GEQVarsRational |
25
-
EQVarsRationalderiving (Show, Eq);
22
+
dataPolyConstraint
23
+
=LEQ{lhs::VarLitMapSum, rhs::SimplexNum}
24
+
| GEQ{lhs::VarLitMapSum, rhs::SimplexNum}
25
+
| EQ{lhs::VarLitMapSum, rhs::SimplexNum}
26
+
deriving (Show, Read, Eq, Generic)
26
27
```
27
28
28
-
And `Vars` is defined as:
29
+
`SimplexNum` is an alias for `Rational`, and `VarLitMapSum` is an alias for `VarLitMap`, which is an alias for `MapVarSimplexNum`.
30
+
`Var` is an alias of `Int`.
29
31
30
-
```haskell
31
-
typeVars= [(Integer, Rational)]
32
-
```
32
+
A `VarLitMapSum` is read as `Integer` variables mapped to their `Rational` coefficients, with an implicit `+` between each entry.
33
+
For example: `Map.fromList [(1, 2), (2, (-3)), (1, 3)]` is equivalent to `(2x1 + (-3x2) +3x1)`.
33
34
34
-
A `Vars` is treated as a list of `Integer` variables mapped to their `Rational` coefficients, with an implicit `+` between each element in the list.
35
-
For example: `[(1, 2), (2, (-3)), (1, 3)]` is equivalent to `(2x1 + (-3x2) +3x1)`.
35
+
And a `PolyConstraint` is an inequality/equality where the LHS is a `VarLitMapSum` and the RHS is a `Rational`.
36
+
For example: `LEQ (Map.fromList [(1, 2), (2, (-3)), (1, 3)]60)` is equivalent to `(2x1 + (-3x2) +3x1)<=60`.
36
37
37
-
And a `PolyConstraint` is an inequality/equality where the LHS is a `Vars` and the RHS is a `Rational`.
38
-
For example: `LEQ [(1, 2), (2, (-3)), (1, 3)] 60` is equivalent to `(2x1 + (-3x2) +3x1) <=60`.
38
+
Passing a `[PolyConstraint]` to `findFeasibleSolution` will return a `FeasibleSystem` if a feasible solution exists:
39
39
40
-
Passing a `[PolyConstraint]` to `findFeasibleSolution` will return a feasible solution if it exists as well as a list of slack variables, artificial variables, and a variable that can be safely used to represent the objective for phase two.
41
-
`Nothing` is returned if the given `[PolyConstraint]` is infeasible.
42
-
The feasible system is returned as the type `DictionaryForm`:
40
+
```haskell
41
+
dataFeasibleSystem=FeasibleSystem
42
+
{dict::Dict
43
+
, slackVars:: [Var]
44
+
, artificialVars:: [Var]
45
+
, objectiveVar::Var
46
+
}
47
+
deriving (Show, Read, Eq, Generic)
48
+
```
43
49
44
50
```haskell
45
-
typeDictionaryForm= [(Integer, Vars)]
51
+
typeDict=M.MapVarDictValue
52
+
53
+
dataDictValue=DictValue
54
+
{varMapSum::VarLitMapSum
55
+
, constant::SimplexNum
56
+
}
57
+
deriving (Show, Read, Eq, Generic)
46
58
```
47
59
48
-
`DictionaryForm` can be thought of as a list of equations, where the `Integer` represents a basic variable on the LHS that is equal to the RHS represented as a `Vars`.In this `Vars`, the `Integer` -1 is used internally to represent a `Rational` number.
60
+
`Dict` can be thought of as a set of equations, where the key represents a basic variable on the LHSof the equation
61
+
that is equal to the RHS represented as a `DictValue` value.
49
62
50
63
### Phase Two
51
64
52
65
`optimizeFeasibleSystem` performs phase two of the simplex method, and has the type:
Then we give a feasible system in `DictionaryForm`, a list of slack variables, a list of artificial variables, and a variable to represent the objective.
62
-
`optimizeFeasibleSystem`Maximizes/Minimizes the linear equation represented as a `Vars` in the given `ObjectiveFunction`.
63
-
The first item of the returned pair is the `Integer` variable representing the objective.
64
-
The second item is a list of `Integer` variables mapped to their optimized values.
65
-
If a variable is notin this list, the variable is equal to 0.
80
+
We give `optimizeFeasibleSystem` an `ObjectiveFunction` along with a `FeasibleSystem`.
66
81
67
82
### Two-Phase Simplex
68
83
69
84
`twoPhaseSimplex` performs both phases of the simplex method.
Thereturntype is the same as that of`optimizeFeasibleSystem`
77
-
78
91
### Extracting Results
79
92
80
-
The result of the objective function is present in the returntypeof both `twoPhaseSimplex`and`optimizeFeasibleSystem`, but this can be difficult to grok in systems with many variables, so the following function will extract the value of the objective function for you.
93
+
The result of the objective function is present in the returned `Result`typeof both `twoPhaseSimplex`and`optimizeFeasibleSystem`, but this can be difficult to grok in systems with many variables, so the following function will extract the value of the objective function for you.
There are similar functions for `DictionaryForm` as well as other custom types in the module `Linear.Simplex.Util`.
87
100
88
-
## Usage notes
89
-
90
-
You must only use positive `Integer` variables in a `Vars`.
91
-
This implementation assumes that the user only provides positive `Integer` variables; the `Integer` -1, for example, is sometimes used to represent a `Rational` number.
0 commit comments