Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression in how we handle solution copying #570

Merged
merged 2 commits into from
Jun 8, 2023
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
12 changes: 9 additions & 3 deletions src/Conjure/UI/MainHelper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,21 @@ mainWithArgs config@Solve{..} = do
case stripPostfix ext (snd (splitFileName file)) of
Nothing -> return ()
Just base -> do
let parts = splitOn "-" base
let parts' = splitOn "-" base
let parts = case (head parts', parts', last parts') of
(model, _:paramparts, stripPrefix "solution" -> msolnum) ->
case msolnum of
Nothing -> [model, intercalate "-" paramparts]
Just{} -> [model, intercalate "-" (init paramparts), last paramparts]
_ -> parts'
case (solutionsInOneFile, null essenceParams, nbSolutions == "1", parts) of
-- not parameterised, but no solution numbers. must be using solutionsInOneFile.
(True, True, _singleSolution, [_model]) ->
(True, True, _singleSolution, [_model, ""]) ->
copySolution file $ essenceDir
</> essenceBasename
<.> ext
-- not parameterised, with solution numbers
(False, True, singleSolution, [_model, (stripPrefix "solution" -> Just solnum)]) ->
(False, True, singleSolution, [_model, "", (stripPrefix "solution" -> Just solnum)]) ->
if singleSolution
then when (solnum == "000001") $ -- only copy the first solution
copySolution file $ essenceDir
Expand Down
5 changes: 5 additions & 0 deletions tests/custom/solution-copy-dashed/p.param
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$ sumplete 1 x 1 instance generated by ./sumplete-gen.pl -s 42
letting n be 1
letting c be [[4]]
letting rt be [0]
letting ct be [0]
6 changes: 6 additions & 0 deletions tests/custom/solution-copy-dashed/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rm -rf conjure-output *.solution
conjure solve sumplete-2023053102.essence p.param
ls -1 *.solution
conjure solve sumplete-2023053102.essence sumplete-1x1-42.param
ls -1 *.solution
rm -rf conjure-output *.solution
15 changes: 15 additions & 0 deletions tests/custom/solution-copy-dashed/stdout.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Generating models for sumplete-2023053102.essence
Generated models: model000001.eprime
Saved under: conjure-output
Savile Row: model000001.eprime p.param
Running minion for domain filtering.
Running solver: minion
Copying solution to: sumplete-2023053102-p.solution
sumplete-2023053102-p.solution
Using cached models.
Savile Row: model000001.eprime sumplete-1x1-42.param
Running minion for domain filtering.
Running solver: minion
Copying solution to: sumplete-2023053102-sumplete-1x1-42.solution
sumplete-2023053102-p.solution
sumplete-2023053102-sumplete-1x1-42.solution
5 changes: 5 additions & 0 deletions tests/custom/solution-copy-dashed/sumplete-1x1-42.param
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$ sumplete 1 x 1 instance generated by ./sumplete-gen.pl -s 42
letting n be 1
letting c be [[4]]
letting rt be [0]
letting ct be [0]
18 changes: 18 additions & 0 deletions tests/custom/solution-copy-dashed/sumplete-2023053102.essence
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$ https://sumplete.com/
$ delete numbers so each row and column adds up to the target number

given n : int(1..)
letting M be n*9 $ largest possible target number
letting rows be domain int(1..n)
letting cols be domain int(1..n)
letting digits be domain int(1..9)
letting targets be domain int(0..M)

given c : matrix indexed by [rows,cols] of digits
given rt : matrix indexed by [rows] of targets
given ct : matrix indexed by [cols] of targets

find d : function (total) (rows,cols) --> int(0..1)
such that
forAll i : rows . (sum j : cols . d((i,j))*c[i,j]) = rt[i]
, forAll j : cols . (sum i : rows . d((i,j))*c[i,j]) = ct[j]