-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EventDeduplication -> SameInputSetIsomorphicOutputs (#404)
## Changes * Closes #341. * Adds `"EventDeduplication"` option, which, if set to `"SameInputSetIsomorphicOutputs"`, allows one to treat multiple matches to the same set of inputs producing isomorphic outputs as one. ## Review questions * Can you think of a better name than `"SameInputSetIsomorphicOutputs"`? Keep in mind that another possibility for event identification would be, for example, a rule `{{0}, {0}} -> {}` starting with an input `{{0}, {0}, {0}}`. In this case, there are three events possible, but they are still the same in the sense that the states after instantiating any of these events would be identical. So, we might want to add an option for this case as well. Maybe, as an element in a list `"EventDeduplication" -> {"SameInputSetIsomorphicOutputs", ...}`. And if all possible identification are needed, `"EventDeduplication" -> All`. ## Examples * By default, matches to every possible order of the input subsets will be turned into separate events: ```wl In[] := WolframModel[{{a, b}, {a, c}} -> {{b, d}, {c, d}}, {{1, 2}, {1, 3}}, "EventSelectionFunction" -> "MultiwaySpacelike"]["ExpressionsEventsGraph", VertexLabels -> Automatic] ``` <img width="399" alt="image" src="https://user-images.githubusercontent.com/1479325/93140017-bdaa8480-f6af-11ea-9339-96599bcf36b7.png"> * However, with `"EventDeduplication" -> "SameInputSetIsomorphicOutputs"` they will be identified if the outputs are the same up to the renaming of new atoms: ```wl In[] := WolframModel[{{a, b}, {a, c}} -> {{b, d}, {c, d}}, {{1, 2}, {1, 3}}, "EventSelectionFunction" -> "MultiwaySpacelike", "EventDeduplication" -> "SameInputSetIsomorphicOutputs"]["ExpressionsEventsGraph", VertexLabels -> Automatic] ``` <img width="259" alt="image" src="https://user-images.githubusercontent.com/1479325/93140076-d5820880-f6af-11ea-8336-e47edb8a176a.png"> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/maxitg/setreplace/404) <!-- Reviewable:end -->
- Loading branch information
Showing
16 changed files
with
506 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<| | ||
"eventDeduplication" -> <| | ||
"init" -> ( | ||
Attributes[Global`testUnevaluated] = {HoldAll}; | ||
Global`testUnevaluated[args___] := SetReplace`PackageScope`testUnevaluated[VerificationTest, args]; | ||
), | ||
"tests" -> { | ||
(* No deduplication is the default *) | ||
VerificationTest[ | ||
Options[WolframModel, "EventDeduplication"], | ||
{"EventDeduplication" -> None} | ||
], | ||
|
||
(* Deduplication requires Method -> "LowLevel" *) | ||
testUnevaluated[ | ||
WolframModel[{1 -> 2, 1 -> 3}, {1}, "EventDeduplication" -> "SameInputSetIsomorphicOutputs", Method -> #1], | ||
#2 | ||
] & @@@ {{Automatic, WolframModel::symbNotImplemented}, {"Symbolic", WolframModel::symbOrdering}}, | ||
|
||
(* Non-symmetric case *) | ||
VerificationTest[ | ||
WolframModel[{{1, 2}, {1, 3}} -> {{2, 3}}, | ||
{{1, 2}, {1, 3}}, | ||
1, | ||
"EventSelectionFunction" -> "MultiwaySpacelike", | ||
"EventDeduplication" -> "SameInputSetIsomorphicOutputs"], | ||
WolframModel[{{1, 2}, {1, 3}} -> {{2, 3}}, {{1, 2}, {1, 3}}, 1, "EventSelectionFunction" -> "MultiwaySpacelike"] | ||
], | ||
|
||
(* Symmetric case *) | ||
VerificationTest[ | ||
WolframModel[{{1, 2}, {1, 3}} -> {{2, 3}, {3, 2}}, | ||
{{1, 2}, {1, 3}}, | ||
1, | ||
"EventSelectionFunction" -> "MultiwaySpacelike", | ||
"EventDeduplication" -> "SameInputSetIsomorphicOutputs"]["EventsList"], | ||
{{1, {1, 2} -> {3, 4}}} | ||
], | ||
|
||
(* System that becomes non-overlapping *) | ||
VerificationTest[ | ||
WolframModel[{{1, 2}, {2, 1}} -> {{1, 3}, {3, 1}, {3, 2}, {2, 3}}, | ||
{{1, 2}, {2, 1}}, | ||
3, | ||
"EventSelectionFunction" -> "MultiwaySpacelike", | ||
"EventDeduplication" -> #1]["EventsCount"], | ||
#2 | ||
] & @@@ {{None, 42}, {"SameInputSetIsomorphicOutputs", 7}}, | ||
|
||
VerificationTest[ | ||
WolframModel[{{1, 2}, {2, 1}} -> {{1, 3}, {3, 1}, {3, 2}, {2, 3}}, | ||
{{1, 2}, {2, 1}}, | ||
3, | ||
"EventSelectionFunction" -> "MultiwaySpacelike", | ||
"EventDeduplication" -> "SameInputSetIsomorphicOutputs"]["FinalState"], | ||
{{1, 6}, {6, 1}, {6, 4}, {4, 6}, {4, 7}, {7, 4}, {7, 3}, {3, 7}, {3, 8}, {8, 3}, {8, 5}, {5, 8}, {5, 9}, {9, 5}, | ||
{9, 2}, {2, 9}} | ||
], | ||
|
||
(* Neat examples *) | ||
VerificationTest[ | ||
WolframModel[{{x, y}, {x, z}} -> {{x, y}, {x, w}, {y, w}, {z, w}}, | ||
{{0, 0}, {0, 0}}, | ||
3, | ||
"EventSelectionFunction" -> "MultiwaySpacelike", | ||
"EventDeduplication" -> None]["EventsCount"] > | ||
WolframModel[{{x, y}, {x, z}} -> {{x, y}, {x, w}, {y, w}, {z, w}}, | ||
{{0, 0}, {0, 0}}, | ||
3, | ||
"EventSelectionFunction" -> "MultiwaySpacelike", | ||
"EventDeduplication" -> "SameInputSetIsomorphicOutputs"]["EventsCount"] | ||
], | ||
|
||
(* Tests for correct isomorphism *) | ||
VerificationTest[ | ||
WolframModel[#1, | ||
#2, | ||
#3, | ||
"EventSelectionFunction" -> "MultiwaySpacelike", | ||
"EventDeduplication" -> "SameInputSetIsomorphicOutputs"]["EventsCount"], | ||
#4 | ||
] & @@@ { | ||
(* Symmetric case *) | ||
{{{1, 2}, {1, 3}} -> {{2, 3}, {3, 2}}, {{1, 2}, {1, 3}}, 1, 1}, | ||
(* Nontrivial isomorphism *) | ||
{{{1, 2}, {1, 3}} -> {{2, 4}, {4, 5}, {5, 3}, {3, 6}, {6, 2}}, {{1, 2}, {1, 3}}, 1, 2}, | ||
{{{1, 2}, {1, 3}} -> {{2, 4}, {4, 3}, {3, 5}, {5, 2}}, {{1, 2}, {1, 3}}, 1, 1}, | ||
(* Different size subgraph-isomorphic outputs *) | ||
{{{{1}} -> {{1, 2}}, {{1}} -> {{1, 2}, {1, 2}}}, {{1}}, 1, 2}, | ||
{{{{1}} -> {{1, 2}, {1, 2}}, {{1}} -> {{1, 2}}}, {{1}}, 1, 2}, | ||
(* Empty output *) | ||
{{{1}, {1}} -> {}, {{1}, {1}}, 1, 1}, | ||
{{{1}, {1}} -> {}, {{1}, {1}, {1}}, 1, 3}, | ||
{{{{1}, {1}} -> {}, {{1}, {1}} -> {}}, {{1}, {1}, {1}}, 1, 3}, | ||
{{{{1}, {1}} -> {}, {{1}, {1}, {1}} -> {}}, {{1}, {1}, {1}}, 1, 4}, | ||
(* Neat examples *) | ||
{{{1}, {1}} -> {{1}, {1}}, {{1}, {1}, {1}}, 2, 12}, | ||
{{{0, 1}, {0, 6}} -> {{1, 4}, {2, 3}, {2, 4}, {3, 4}, {3, 5}, {4, 5}, {6, 4}}, {{0, 1}, {0, 6}}, 1, 1}, | ||
{{{0, 1}, {0, 6}} -> {{1, 4}, {2, 3}, {2, 4}, {3, 4}, {3, 5}, {4, 5}, {4, 6}}, {{0, 1}, {0, 6}}, 1, 2}, | ||
(* Pattern rules *) | ||
{<|"PatternRules" -> {{0, a_}, {0, b_}} :> Module[{c, d}, {{a, c}, {b, d}}]|>, {{0, 1}, {0, 2}}, 1, 1}, | ||
{<|"PatternRules" -> {{0, a_}, {0, b_}} :> {{a, 1}, {b, 2}}|>, {{0, 1}, {0, 2}}, 1, 2}, | ||
{<|"PatternRules" -> {{0, a_}, {0, b_}} :> {{a, 3}, {b, 4}}|>, {{0, 1}, {0, 2}}, 1, 2}, | ||
{<|"PatternRules" -> {{0, a_}, {0, b_}} :> Module[{c, d}, {{a, 1}, {b, 2}}]|>, {{0, 1}, {0, 2}}, 1, 2} | ||
}, | ||
|
||
(* Correct weights in random evolution *) | ||
VerificationTest[ | ||
Count[Table[First[WolframModel[{{{1}, {1}, {1}, {1}} -> {}, {{1}} -> {}}, | ||
{{1}, {1}, {1}, {1}}, | ||
<|"MaxEvents" -> 1|>, | ||
"EventOrderingFunction" -> {}]["AllEventsRuleIndices"]], 1000], 2] < 200 | ||
], | ||
|
||
VerificationTest[ | ||
Count[Table[First[WolframModel[{{{1}, {1}, {1}, {1}} -> {}, {{1}} -> {}}, | ||
{{1}, {1}, {1}, {1}}, | ||
<|"MaxEvents" -> 1|>, | ||
"EventOrderingFunction" -> {}, | ||
"EventDeduplication" -> "SameInputSetIsomorphicOutputs"][ | ||
"AllEventsRuleIndices"]], 1000], 1] < 300 | ||
] | ||
} | ||
|> | ||
|> |
Oops, something went wrong.