Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased changes

- Remove unused pivot bindings and give the active row-update helper a descriptive name. ([#21](https://github.com/rasheedja/simplex-method/pull/21))
- Extract optimal variable values directly from dictionary constants without an intermediate tableau conversion. ([#22](https://github.com/rasheedja/simplex-method/pull/22))
- Remove QuickCheck from the library dependencies while retaining it for property tests. ([#24](https://github.com/rasheedja/simplex-method/pull/24))
- `twoPhaseSimplex` now takes a `VarDomainMap` as its first argument
Expand Down
21 changes: 3 additions & 18 deletions src/Linear/Simplex/Solver/TwoPhase.hs
Original file line number Diff line number Diff line change
Expand Up @@ -809,30 +809,15 @@ simplexPivot objective@(PivotObjective {variable = objectiveVar, function = obje
& #constant
%~ divideByNegatedEnteringVariableCoeff
where
newEnteringVarTerm = (leavingVariable, -1)
divideByNegatedEnteringVariableCoeff = (/ negate enteringVariableCoeff)

-- Substitute pivot equation into other rows
updatedRows :: Dict
updatedRows =
M.fromList $ map (uncurry f2) $ M.toList dict
M.fromList $ map (uncurry updateRow) $ M.toList dict
where
f entryVar entryVal =
if leavingVariable == entryVar
then pivotEnteringRow
else case M.lookup enteringVariable (entryVal.varMapSum) of
Just subsCoeff ->
entryVal
& #varMapSum
.~ combineVarLitMapSums
(pivotEnteringRow.varMapSum <&> (subsCoeff *))
(filterOutEnteringVarTerm (entryVal.varMapSum))
& #constant
.~ ((subsCoeff * (pivotEnteringRow.constant)) + entryVal.constant)
Nothing -> entryVal

f2 :: Var -> DictValue -> (Var, DictValue)
f2 entryVar entryVal =
updateRow :: Var -> DictValue -> (Var, DictValue)
updateRow entryVar entryVal =
if leavingVariable == entryVar
then (enteringVariable, pivotEnteringRow)
else case M.lookup enteringVariable (entryVal.varMapSum) of
Expand Down
Loading