Skip to content

Commit 2125abe

Browse files
committed
chore: fix ci, haddocks, remove unused functions
1 parent 93dd0a0 commit 2125abe

7 files changed

Lines changed: 26 additions & 48 deletions

File tree

.github/workflows/haskell.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
- name: Check cabal file
4040
run: nix develop --command make cabal-check
4141

42+
- name: Update cabal package index
43+
run: nix develop --command make cabal-update
44+
4245
- name: Configure the build
4346
run: nix develop --command make configure
4447

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ dist-*/
44
.vscode/*
55
.direnv/*
66
.envrc
7+
cabal.project.local

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ format-check:
1414
cabal-check:
1515
cabal check
1616

17+
.PHONY: cabal-update
18+
cabal-update:
19+
cabal update
20+
1721
.PHONY: configure
1822
configure:
1923
cabal configure --enable-tests --enable-benchmarks --disable-documentation
@@ -36,4 +40,4 @@ docs:
3640
cabal haddock all --disable-documentation
3741

3842
.PHONY: ci
39-
ci: format-check cabal-check configure deps build test docs
43+
ci: format-check cabal-check cabal-update configure deps build test docs

src/Linear/Simplex/Prettify.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Data.Map qualified as M
1818
import Data.Ratio
1919
import Linear.Simplex.Types
2020

21-
-- | Convert a 'VarConstMap' into a human-readable 'String'
21+
-- | Convert a 'VarLitMapSum' into a human-readable 'String'
2222
prettyShowVarConstMap :: VarLitMapSum -> String
2323
prettyShowVarConstMap = aux . M.toList
2424
where

src/Linear/Simplex/Solver/TwoPhase.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
-- 'findFeasibleSolution' performs phase one of the two-phase simplex method.
1111
-- 'optimizeFeasibleSystem' performs phase two of the two-phase simplex method.
1212
-- 'twoPhaseSimplex' performs both phases of the two-phase simplex method.
13-
-- 'twoPhaseSimplex'' performs both phases with variable domain support.
13+
-- 'twoPhaseSimplex' supports variable domains via its 'VarDomainMap' argument.
1414
module Linear.Simplex.Solver.TwoPhase
1515
( findFeasibleSolution
1616
, optimizeFeasibleSystem
@@ -272,7 +272,7 @@ findFeasibleSolution unsimplifiedSystem = do
272272

273273
-- | Optimize a feasible system by performing the second phase of the two-phase simplex method.
274274
-- We first pass an 'ObjectiveFunction'.
275-
-- Then, the feasible system in 'DictionaryForm' as well as a list of slack variables, a list artificial variables, and the objective variable.
275+
-- Then, the feasible system in 'Dict' form as well as a list of slack variables, a list artificial variables, and the objective variable.
276276
-- Returns 'Optimal' with variable values if an optimal solution is found, or 'Unbounded' if the objective is unbounded.
277277
optimizeFeasibleSystem :: (MonadIO m, MonadLogger m) => ObjectiveFunction -> FeasibleSystem -> m OptimisationOutcome
278278
optimizeFeasibleSystem objFunction fsys@(FeasibleSystem {dict = phase1Dict, ..}) = do

src/Linear/Simplex/Types.hs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,14 @@ import Data.List (sort)
1313
import qualified Data.Map as M
1414
import GHC.Generics (Generic)
1515

16+
-- | Variable identifier used in maps and constraints.
17+
-- Conventionally this maps to x1, x2, ... in examples.
1618
type Var = Int
1719

20+
-- | Numeric type used throughout simplex computations.
1821
type SimplexNum = Rational
1922

20-
type SystemRow = PolyConstraint
21-
22-
type System = [SystemRow]
23-
24-
-- A 'Tableau' where the basic variable may be empty.
25-
-- All non-empty basic vars are slack vars
26-
data SystemWithSlackVarRow = SystemInStandardFormRow
27-
{ mSlackVar :: Maybe Var
28-
-- ^ This is Nothing iff the row does not have a slack variable
29-
, row :: TableauRow
30-
}
31-
32-
type SystemWithSlackVars = [SystemWithSlackVarRow]
33-
23+
-- | A feasible system produced by phase one, ready for phase two optimization.
3424
data FeasibleSystem = FeasibleSystem
3525
{ dict :: Dict
3626
, slackVars :: [Var]
@@ -66,6 +56,7 @@ data SimplexResult = SimplexResult
6656
}
6757
deriving (Show, Read, Eq, Generic)
6858

59+
-- | Mapping from variable id to its numeric value/coefficient.
6960
type VarLitMap = M.Map Var SimplexNum
7061

7162
-- | List of variables with their 'SimplexNum' coefficients.
@@ -75,7 +66,7 @@ type VarLitMap = M.Map Var SimplexNum
7566
type VarLitMapSum = VarLitMap
7667

7768
-- | For specifying constraints in a system.
78-
-- The LHS is a 'Vars', and the RHS, is a 'SimplexNum' number.
69+
-- The LHS is a 'VarLitMapSum', and the RHS, is a 'SimplexNum' number.
7970
-- LEQ [(1, 2), (2, 1)] 3.5 is equivalent to 2x1 + x2 <= 3.5.
8071
-- Users must only provide positive integer variables.
8172
--
@@ -87,25 +78,18 @@ data PolyConstraint
8778
deriving (Show, Read, Eq, Generic)
8879

8980
-- | Create an objective function.
90-
-- We can either 'Max'imize or 'Min'imize a 'VarTermSum'.
81+
-- We can either 'Max'imize or 'Min'imize a 'VarLitMapSum'.
9182
data ObjectiveFunction = Max {objective :: VarLitMapSum} | Min {objective :: VarLitMapSum}
9283
deriving (Show, Read, Eq, Generic)
9384

94-
-- | TODO: Maybe we want this type
95-
-- TODO: A better/alternative name
96-
data Equation = Equation
97-
{ lhs :: VarLitMapSum
98-
, rhs :: SimplexNum
99-
}
100-
10185
-- | Value for 'Tableau'. lhs = rhs.
10286
data TableauRow = TableauRow
10387
{ lhs :: VarLitMapSum
10488
, rhs :: SimplexNum
10589
}
10690
deriving (Show, Read, Eq, Generic)
10791

108-
-- | A simplex 'Tableu' of equations.
92+
-- | A simplex 'Tableau' of equations.
10993
-- Each entry in the map is a row.
11094
type Tableau = M.Map Var TableauRow
11195

@@ -126,6 +110,9 @@ data DictValue = DictValue
126110
-- deriving (Show, Read, Eq, Generic)
127111
type Dict = M.Map Var DictValue
128112

113+
-- | Objective row representation used during pivoting.
114+
-- 'variable' is the objective basic variable and 'function'/'constant' encode
115+
-- the objective in dictionary form.
129116
data PivotObjective = PivotObjective
130117
{ variable :: Var
131118
, function :: VarLitMapSum

src/Linear/Simplex/Util.hs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ isMax :: ObjectiveFunction -> Bool
3030
isMax (Max _) = True
3131
isMax (Min _) = False
3232

33-
-- | Simplifies a system of 'PolyConstraint's by first calling 'simplifyPolyConstraint',
33+
-- | Simplifies a system of 'PolyConstraint's,
3434
-- then reducing 'LEQ' and 'GEQ' with same LHS and RHS (and other similar situations) into 'EQ',
3535
-- and finally removing duplicate elements using 'nub'.
3636
simplifySystem :: [PolyConstraint] -> [PolyConstraint]
@@ -78,7 +78,7 @@ simplifySystem = nub . reduceSystem
7878
then EQ lhs rhs : reduceSystem pcs
7979
else EQ lhs rhs : reduceSystem (pcs \\ matchingConstraints)
8080

81-
-- | Converts a 'Dict' to a 'Tableau' using 'dictEntryToTableauEntry'.
81+
-- | Converts a 'Dict' to a 'Tableau'.
8282
-- FIXME: maybe remove this line. The basic variables will have a coefficient of 1 in the 'Tableau'.
8383
dictionaryFormToTableau :: Dict -> Tableau
8484
dictionaryFormToTableau =
@@ -130,17 +130,6 @@ combineVarLitMapSums =
130130
keepVal = const pure
131131
sumVals k v1 v2 = Just $ v1 + v2
132132

133-
foldDictValue :: [DictValue] -> DictValue
134-
foldDictValue [] = error "Empty list of DictValues given to foldDictValue"
135-
foldDictValue [x] = x
136-
foldDictValue (DictValue {varMapSum = vm1, constant = c1} : DictValue {varMapSum = vm2, constant = c2} : dvs) =
137-
let combinedDictValue =
138-
DictValue
139-
{ varMapSum = foldVarLitMap [vm1, vm2]
140-
, constant = c1 + c2
141-
}
142-
in foldDictValue $ combinedDictValue : dvs
143-
144133
foldVarLitMap :: [VarLitMap] -> VarLitMap
145134
foldVarLitMap [] = error "Empty list of VarLitMaps given to foldVarLitMap"
146135
foldVarLitMap [x] = x
@@ -158,7 +147,7 @@ foldVarLitMap (vm1 : vm2 : vms) =
158147
(Just vm1VarVal, Just vm2VarVal) -> vm1VarVal + vm2VarVal
159148
(Just vm1VarVal, Nothing) -> vm1VarVal
160149
(Nothing, Just vm2VarVal) -> vm2VarVal
161-
(Nothing, Nothing) -> error "Reached unreachable branch in foldDictValue"
150+
(Nothing, Nothing) -> error "Reached unreachable branch in foldVarLitMap"
162151
)
163152
)
164153
combinedVars
@@ -180,9 +169,3 @@ logMsg lvl msg = do
180169
LevelWarn -> $logWarn msgToLog
181170
LevelError -> $logError msgToLog
182171
LevelOther otherLvl -> error "logMsg: LevelOther is not implemented"
183-
184-
extractTableauValues :: Tableau -> Map.Map Var SimplexNum
185-
extractTableauValues = Map.map (.rhs)
186-
187-
extractDictValues :: Dict -> Map.Map Var SimplexNum
188-
extractDictValues = Map.map (.constant)

0 commit comments

Comments
 (0)