Skip to content

Commit 497d8d6

Browse files
committed
wip
1 parent 9895193 commit 497d8d6

File tree

9 files changed

+1745
-528
lines changed

9 files changed

+1745
-528
lines changed

.github/workflows/haskell-nix.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Haskell CI with Nix
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
nix-ci:
13+
runs-on: ubuntu-latest
14+
env:
15+
NIX_CONFIG: accept-flake-config = true
16+
17+
steps:
18+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
19+
20+
- name: Check Nix flake inputs
21+
uses: DeterminateSystems/flake-checker-action@3164002371bc90729c68af0e24d5aacf20d7c9f6 # v12
22+
23+
- name: Install Nix
24+
uses: DeterminateSystems/nix-installer-action@c5a866b6ab867e88becbed4467b93592bce69f8a # v21
25+
26+
- name: Enable Nix cache
27+
uses: DeterminateSystems/magic-nix-cache-action@565684385bcd71bad329742eefe8d12f2e765b39 # v13
28+
29+
- name: Show toolchain versions from nix shell
30+
shell: bash
31+
run: |
32+
nix develop --command bash -lc 'ghc --numeric-version'
33+
nix develop --command bash -lc 'cabal --numeric-version'
34+
nix develop --command bash -lc 'stack --numeric-version || true'
35+
nix develop --command bash -lc 'fourmolu --version'
36+
37+
- name: Check formatting
38+
run: nix develop --command make format-check
39+
40+
- name: Check cabal file
41+
run: nix develop --command make cabal-check
42+
43+
- name: Update cabal package index
44+
run: nix develop --command make cabal-update
45+
46+
- name: Configure the build
47+
run: nix develop --command make configure
48+
49+
- name: Build dependencies
50+
run: nix develop --command make deps
51+
52+
- name: Build the package
53+
run: nix develop --command make build
54+
55+
- name: Run tests
56+
run: nix develop --command make test
57+
58+
- name: Build documentation
59+
run: nix develop --command make docs

.github/workflows/haskell.yml

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,83 @@ name: Haskell CI
22

33
on:
44
push:
5+
pull_request:
56
workflow_dispatch:
67

78
permissions:
89
contents: read
910

1011
jobs:
11-
nix-ci:
12+
fourmolu:
1213
runs-on: ubuntu-latest
13-
env:
14-
NIX_CONFIG: accept-flake-config = true
1514

1615
steps:
1716
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1817

19-
- name: Check Nix flake inputs
20-
uses: DeterminateSystems/flake-checker-action@3164002371bc90729c68af0e24d5aacf20d7c9f6 # v12
18+
- uses: haskell-actions/run-fourmolu@v11
19+
with:
20+
version: "0.17.0.0"
2121

22-
- name: Install Nix
23-
uses: DeterminateSystems/nix-installer-action@c5a866b6ab867e88becbed4467b93592bce69f8a # v21
22+
build:
23+
name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }}
24+
runs-on: ${{ matrix.os }}
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
os: [ubuntu-latest, macos-latest, windows-latest]
29+
ghc-version: ["9.6.7"]
2430

25-
- name: Enable Nix cache
26-
uses: DeterminateSystems/magic-nix-cache-action@565684385bcd71bad329742eefe8d12f2e765b39 # v13
31+
steps:
32+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
33+
34+
- name: Set up GHC ${{ matrix.ghc-version }}
35+
uses: haskell-actions/setup@v2
36+
id: setup
37+
with:
38+
ghc-version: ${{ matrix.ghc-version }}
39+
cabal-version: "3.16.0.0"
2740

28-
- name: Show toolchain versions from nix shell
41+
- name: Show toolchain versions
2942
shell: bash
3043
run: |
31-
nix develop --command bash -lc 'ghc --numeric-version'
32-
nix develop --command bash -lc 'cabal --numeric-version'
33-
nix develop --command bash -lc 'stack --numeric-version || true'
34-
nix develop --command bash -lc 'fourmolu --version'
35-
36-
- name: Check formatting
37-
run: nix develop --command make format-check
44+
ghc --numeric-version
45+
cabal --numeric-version
3846
3947
- name: Check cabal file
40-
run: nix develop --command make cabal-check
48+
run: cabal check
4149

4250
- name: Update cabal package index
43-
run: nix develop --command make cabal-update
51+
run: cabal update
4452

4553
- name: Configure the build
46-
run: nix develop --command make configure
54+
run: |
55+
cabal configure --enable-tests --enable-benchmarks --disable-documentation
56+
cabal build --dry-run
57+
58+
- name: Restore cabal store cache
59+
uses: actions/cache/restore@v4
60+
id: cache-restore
61+
with:
62+
path: ${{ steps.setup.outputs.cabal-store }}
63+
key: ${{ runner.os }}-ghc-${{ matrix.ghc-version }}-cabal-${{ hashFiles('**/plan.json') }}
64+
restore-keys: |
65+
${{ runner.os }}-ghc-${{ matrix.ghc-version }}-cabal-
4766
4867
- name: Build dependencies
49-
run: nix develop --command make deps
68+
run: cabal build --only-dependencies
69+
70+
- name: Save cabal store cache
71+
uses: actions/cache/save@v4
72+
if: steps.cache-restore.outputs.cache-hit != 'true'
73+
with:
74+
path: ${{ steps.setup.outputs.cabal-store }}
75+
key: ${{ steps.cache-restore.outputs.cache-primary-key }}
5076

5177
- name: Build the package
52-
run: nix develop --command make build
78+
run: cabal build all
5379

5480
- name: Run tests
55-
run: nix develop --command make test
81+
run: cabal test all
5682

5783
- name: Build documentation
58-
run: nix develop --command make docs
84+
run: cabal haddock all --disable-documentation

.github/workflows/update-flake.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Update Nix Flake
2+
3+
on:
4+
schedule:
5+
# Every 2 weeks on Monday at 06:00 UTC
6+
- cron: "0 6 1,15 * *"
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
update-flake:
15+
runs-on: ubuntu-latest
16+
env:
17+
NIX_CONFIG: accept-flake-config = true
18+
19+
steps:
20+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
21+
22+
- name: Install Nix
23+
uses: DeterminateSystems/nix-installer-action@c5a866b6ab867e88becbed4467b93592bce69f8a # v21
24+
25+
- name: Enable Nix cache
26+
uses: DeterminateSystems/magic-nix-cache-action@565684385bcd71bad329742eefe8d12f2e765b39 # v13
27+
28+
- name: Update flake lockfile
29+
run: nix flake update
30+
31+
- name: Create Pull Request
32+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
33+
with:
34+
commit-message: "chore(nix): update flake lockfile"
35+
title: "chore(nix): update flake lockfile"
36+
body: |
37+
Automated flake lockfile update via `nix flake update`.
38+
39+
This PR was created by the scheduled update-flake workflow.
40+
Please review CI results before merging.
41+
branch: automation/update-flake-lock
42+
delete-branch: true
43+
labels: dependencies, automated

simplex-method.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ test-suite simplex-haskell-test
6666
main-is: Spec.hs
6767
other-modules:
6868
Linear.Simplex.Solver.TwoPhaseSpec
69+
Linear.Simplex.UtilSpec
6970
Paths_simplex_method
7071
hs-source-dirs:
7172
test

src/Linear/Simplex/Prettify.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import Data.Ratio
1919
import Linear.Simplex.Types
2020

2121
-- | Convert a 'VarLitMapSum' into a human-readable 'String'
22-
prettyShowVarConstMap :: VarLitMapSum -> String
23-
prettyShowVarConstMap = aux . M.toList
22+
prettyShowVarLitMapSum :: VarLitMapSum -> String
23+
prettyShowVarLitMapSum = aux . M.toList
2424
where
2525
aux [] = ""
2626
aux ((vName, vCoeff) : vs) = prettyShowRational vCoeff ++ " * " ++ show vName ++ " + " ++ aux vs
@@ -34,11 +34,11 @@ prettyShowVarConstMap = aux . M.toList
3434

3535
-- | Convert a 'PolyConstraint' into a human-readable 'String'
3636
prettyShowPolyConstraint :: PolyConstraint -> String
37-
prettyShowPolyConstraint (LEQ vcm r) = prettyShowVarConstMap vcm ++ " <= " ++ show r
38-
prettyShowPolyConstraint (GEQ vcm r) = prettyShowVarConstMap vcm ++ " >= " ++ show r
39-
prettyShowPolyConstraint (Linear.Simplex.Types.EQ vcm r) = prettyShowVarConstMap vcm ++ " == " ++ show r
37+
prettyShowPolyConstraint (LEQ vcm r) = prettyShowVarLitMapSum vcm ++ " <= " ++ show r
38+
prettyShowPolyConstraint (GEQ vcm r) = prettyShowVarLitMapSum vcm ++ " >= " ++ show r
39+
prettyShowPolyConstraint (Linear.Simplex.Types.EQ vcm r) = prettyShowVarLitMapSum vcm ++ " == " ++ show r
4040

4141
-- | Convert an 'ObjectiveFunction' into a human-readable 'String'
4242
prettyShowObjectiveFunction :: ObjectiveFunction -> String
43-
prettyShowObjectiveFunction (Min vcm) = "min: " ++ prettyShowVarConstMap vcm
44-
prettyShowObjectiveFunction (Max vcm) = "max: " ++ prettyShowVarConstMap vcm
43+
prettyShowObjectiveFunction (Min vcm) = "min: " ++ prettyShowVarLitMapSum vcm
44+
prettyShowObjectiveFunction (Max vcm) = "max: " ++ prettyShowVarLitMapSum vcm

src/Linear/Simplex/Solver/TwoPhase.hs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,17 @@ findFeasibleSolution unsimplifiedSystem = do
147147
system = simplifySystem unsimplifiedSystem
148148

149149
maxVar =
150-
maximum $
151-
map
152-
( \case
153-
LEQ vcm _ -> maximum (map fst $ M.toList vcm)
154-
GEQ vcm _ -> maximum (map fst $ M.toList vcm)
155-
EQ vcm _ -> maximum (map fst $ M.toList vcm)
156-
)
157-
system
150+
if null system
151+
then 0
152+
else
153+
maximum $
154+
map
155+
( \case
156+
LEQ vcm _ -> maximum (map fst $ M.toList vcm)
157+
GEQ vcm _ -> maximum (map fst $ M.toList vcm)
158+
EQ vcm _ -> maximum (map fst $ M.toList vcm)
159+
)
160+
system
158161

159162
(systemWithSlackVars, slackVars) = systemInStandardForm system maxVar []
160163

src/Linear/Simplex/Util.hs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,6 @@ tableauInDictionaryForm =
106106
}
107107
)
108108

109-
-- | Extract the objective value from an ObjectiveResult.
110-
-- Returns Nothing if the result is Unbounded.
111-
-- Returns Just the objective value if Optimal.
112-
extractObjectiveValue :: ObjectiveFunction -> ObjectiveResult -> Maybe SimplexNum
113-
extractObjectiveValue objFunction (ObjectiveResult _ outcome) =
114-
case outcome of
115-
Unbounded -> Nothing
116-
Optimal varVals ->
117-
let coeffs = case objFunction of
118-
Max m -> m
119-
Min m -> m
120-
in Just $ sum $ map (\(var, coeff) -> coeff * Map.findWithDefault 0 var varVals) (Map.toList coeffs)
121-
122109
-- | Combines two 'VarLitMapSums together by summing values with matching keys
123110
combineVarLitMapSums :: VarLitMapSum -> VarLitMapSum -> VarLitMapSum
124111
combineVarLitMapSums =

0 commit comments

Comments
 (0)