Skip to content

Commit

Permalink
fix for regression #456
Browse files Browse the repository at this point in the history
  • Loading branch information
fraser-dunlop committed Feb 26, 2020
1 parent 4851e39 commit 655e753
Show file tree
Hide file tree
Showing 66 changed files with 1,102 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/Conjure/UI/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1938,14 +1938,7 @@ rule_DotLtLeq = "generic-DotLtLeq" `namedRule` theRule where
rule_Flatten_Lex :: Rule
rule_Flatten_Lex = "flatten-lex" `namedRule` theRule where
theRule [essence| &a <lex &b |] = do
ta <- typeOf a
tb <- typeOf b
case (ta, tb) of
(TypeList TypeInt{}, TypeList TypeInt{}) ->
na "rule_Flatten_Lex"
(TypeMatrix TypeInt{} TypeInt{}, TypeMatrix TypeInt{} TypeInt{}) ->
na "rule_Flatten_Lex"
_ -> return ()
reject_flat a b
fa <- flatten a
fb <- flatten b
tfa <- typeOf fa
Expand All @@ -1958,14 +1951,7 @@ rule_Flatten_Lex = "flatten-lex" `namedRule` theRule where
, return [essence| &fa <lex &fb |]
)
theRule [essence| &a <=lex &b |] = do
ta <- typeOf a
tb <- typeOf b
case (ta, tb) of
(TypeList TypeInt{}, TypeList TypeInt{}) ->
na "rule_Flatten_Lex"
(TypeMatrix TypeInt{} TypeInt{}, TypeMatrix TypeInt{} TypeInt{}) ->
na "rule_Flatten_Lex"
_ -> return ()
reject_flat a b
fa <- flatten a
fb <- flatten b
tfa <- typeOf fa
Expand All @@ -1978,6 +1964,24 @@ rule_Flatten_Lex = "flatten-lex" `namedRule` theRule where
, return [essence| &fa <=lex &fb |]
)
theRule _ = na "rule_Flatten_Lex"
reject_flat a b = do
ta <- typeOf a
tb <- typeOf b
case (ta, tb) of
(TypeMatrix TypeBool TypeInt{}, _) ->
na "rule_Flatten_Lex"
(TypeMatrix TypeBool TypeBool, _) ->
na "rule_Flatten_Lex"
(TypeList TypeInt{}, _) ->
na "rule_Flatten_Lex"
(TypeMatrix TypeInt{} TypeInt{}, _) ->
na "rule_Flatten_Lex"
(TypeList TypeBool, _) ->
na "rule_Flatten_Lex"
(TypeMatrix TypeInt{} TypeBool, _) ->
na "rule_Flatten_Lex"
_ -> return ()

flatten a = do
ta <- typeOf a
case ta of
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
given A : matrix indexed by [int(0..1)] of (bool,bool)
find B : matrix indexed by [int(0..1)] of (bool,bool)
such that A .< B
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
letting A be [(true,false),(false,true);int(0..1)]
5 changes: 5 additions & 0 deletions tests/custom/flatten_lex/find_v_given/matrix_2_bools/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
conjure solve *.essence *.param
cat conjure-output/*.eprime
cat *.solution
rm *.solution
rm -r conjure-output
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
Generating models for matrix.essence
Generated models: model000001.eprime
Saved under: conjure-output
Savile Row: model000001.eprime matrix.param
Running minion for domain filtering.
Running solver: minion
Copying solution to: matrix-matrix.solution
language ESSENCE' 1.0

given A_1: matrix indexed by [int(0..1)] of bool
given A_2: matrix indexed by [int(0..1)] of bool
find B_1: matrix indexed by [int(0..1)] of bool
find B_2: matrix indexed by [int(0..1)] of bool
branching on [B_1, B_2]
such that
flatten([flatten([[-toInt(A_1[q2]); int(1)], [-toInt(A_2[q2]); int(1)]; int(1..2)]) | q2 : int(0..1)]) <lex
flatten([flatten([[-toInt(B_1[q3]); int(1)], [-toInt(B_2[q3]); int(1)]; int(1..2)]) | q3 : int(0..1)])

$ Conjure's
$ {"finds": [{"Name": "B"}],
$ "givens": [{"Name": "A"}],
$ "enumGivens": [],
$ "enumLettings": [],
$ "lettings": [],
$ "unnameds": [],
$ "strategyQ": {"PickFirst": []},
$ "strategyA": {"Compact": []},
$ "trailCompact": [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]],
$ "trailVerbose": [],
$ "trailRewrites": [],
$ "nameGenState": [["q", 4]],
$ "nbExtraGivens": 0,
$ "representations":
$ [[{"Name": "A"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple": [{"DomainBool": []}, {"DomainBool": []}]}]}],
$ [{"Name": "B"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple": [{"DomainBool": []}, {"DomainBool": []}]}]}]],
$ "representationsTree":
$ [[{"Name": "A"},
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest": []},
$ {"rootLabel": null,
$ "subForest": []}]}]}]],
$ [{"Name": "B"},
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest": []},
$ {"rootLabel": null,
$ "subForest": []}]}]}]]],
$ "originalDomains":
$ [[{"Name": "A"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple": [{"DomainBool": []}, {"DomainBool": []}]}]}],
$ [{"Name": "B"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple": [{"DomainBool": []}, {"DomainBool": []}]}]}]]}
language Essence 1.3

letting B be [(false, false), (false, false); int(0..1)]
$ Visualisation for B
$ _ _
$ _ _

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
given A : matrix indexed by [int(0..1)] of (bool,int(5..7))
find B : matrix indexed by [int(0..1)] of (bool,int(2..7))
such that A .< B
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
letting A be [(false, 5), (false, 5); int(0..1)]
5 changes: 5 additions & 0 deletions tests/custom/flatten_lex/find_v_given/matrix_2_mixed/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
conjure solve *.essence *.param
cat conjure-output/*.eprime
cat *.solution
rm *.solution
rm -r conjure-output
116 changes: 116 additions & 0 deletions tests/custom/flatten_lex/find_v_given/matrix_2_mixed/stdout.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
Generating models for matrix.essence
Generated models: model000001.eprime
Saved under: conjure-output
Savile Row: model000001.eprime matrix.param
Running minion for domain filtering.
Running solver: minion
Copying solution to: matrix-matrix.solution
language ESSENCE' 1.0

given A_1: matrix indexed by [int(0..1)] of bool
given A_2: matrix indexed by [int(0..1)] of int(5..7)
find B_1: matrix indexed by [int(0..1)] of bool
find B_2: matrix indexed by [int(0..1)] of int(2..7)
branching on [B_1, B_2]
such that
flatten([flatten([[-toInt(A_1[q2]); int(1)], [A_2[q2]; int(1)]; int(1..2)]) | q2 : int(0..1)]) <lex
flatten([flatten([[-toInt(B_1[q3]); int(1)], [B_2[q3]; int(1)]; int(1..2)]) | q3 : int(0..1)])

$ Conjure's
$ {"finds": [{"Name": "B"}],
$ "givens": [{"Name": "A"}],
$ "enumGivens": [],
$ "enumLettings": [],
$ "lettings": [],
$ "unnameds": [],
$ "strategyQ": {"PickFirst": []},
$ "strategyA": {"Compact": []},
$ "trailCompact": [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]],
$ "trailVerbose": [],
$ "trailRewrites": [],
$ "nameGenState": [["q", 4]],
$ "nbExtraGivens": 0,
$ "representations":
$ [[{"Name": "A"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple":
$ [{"DomainBool": []},
$ {"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 5]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 7]}}]}]]}]}]}],
$ [{"Name": "B"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple":
$ [{"DomainBool": []},
$ {"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 2]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 7]}}]}]]}]}]}]],
$ "representationsTree":
$ [[{"Name": "A"},
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest": []},
$ {"rootLabel": null,
$ "subForest": []}]}]}]],
$ [{"Name": "B"},
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest":
$ [{"rootLabel": null,
$ "subForest": []},
$ {"rootLabel": null,
$ "subForest": []}]}]}]]],
$ "originalDomains":
$ [[{"Name": "A"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple":
$ [{"DomainBool": []},
$ {"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 5]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 7]}}]}]]}]}]}],
$ [{"Name": "B"},
$ {"DomainMatrix":
$ [{"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 0]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 1]}}]}]]},
$ {"DomainTuple":
$ [{"DomainBool": []},
$ {"DomainInt":
$ [{"TagInt": []},
$ [{"RangeBounded":
$ [{"Constant": {"ConstantInt": [{"TagInt": []}, 2]}},
$ {"Constant": {"ConstantInt": [{"TagInt": []}, 7]}}]}]]}]}]}]]}
language Essence 1.3

letting B be [(false, 5), (false, 6); int(0..1)]
$ Visualisation for B
$ _ 5
$ _ 6

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
given A : matrix indexed by [int(0..1)] of matrix indexed by [int(0..2)] of (bool,int(5..7))
find B : matrix indexed by [int(0..1)] of matrix indexed by [int(0..2)] of (bool,int(5..7))
such that A .< B
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
letting A be
[[(false, 5), (false, 5), (false, 5); int(0..2)], [(false, 5), (false, 5), (false, 5); int(0..2)]; int(0..1)]
5 changes: 5 additions & 0 deletions tests/custom/flatten_lex/find_v_given/matrix_of_matrix/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
conjure solve *.essence *.param
cat conjure-output/*.eprime
cat *.solution
rm *.solution
rm -r conjure-output
Loading

0 comments on commit 655e753

Please sign in to comment.