diff --git a/ChangeLog.md b/ChangeLog.md index f8e36e5..6f08c37 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/src/Linear/Simplex/Solver/TwoPhase.hs b/src/Linear/Simplex/Solver/TwoPhase.hs index 679d1e8..87e04af 100644 --- a/src/Linear/Simplex/Solver/TwoPhase.hs +++ b/src/Linear/Simplex/Solver/TwoPhase.hs @@ -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