Skip to content

Commit 6802e3a

Browse files
authored
Simplified generator system (#657)
## Changes * This is a complete rewrite of the generator system. * Old `GenerateMultihistory` syntax is removed. * Instead, all generators have the format ```wl Generator[System[rules], param1 -> value1, ...] @ init ``` Note that `param1`, etc. are symbols rather than strings. They have usage messages, etc. Also, one can use lists or associations instead, e.g., ```wl Generator[System[rules], {param1 -> value1}, <|param2 -> value2|>, param3 -> value3] @ init ``` * Parameters are now declared separately from systems and generators. * Systems need to declare a logical expression specifying which parameters can be specified. For example, ```wl Implies[MaxEvents || MaxDestroyerEvents, EventOrder] ``` means that `EventOrder` needs to be specified if either `MaxEvents` or `MaxDestroyerEvents` are specified. * Generators have predefined values for some parameters. E.g., `GenerateSingleHistory` sets `MaxDestroyerEvents -> 1`, which can no longer be changed. ## Comments * Apologies for a huge PR. There is a lot of refactoring here as all instances of `GenerateMultihistory` had to be changed. * Ordering functions page is deleted for now but should return as a page for the `EventOrder` parameter once it is used somewhere. * @daneelsan, unfortunately, it will break #643, but on the flip side, it should make it a lot easier to define parameters (as one does not need to think where to put them anymore). ## Examples * `GenerateSingleHistory`: ```wl In[] := #["StatesList"] & @ SetReplaceTypeConvert[{WolframModelEvolutionObject, 2}] @ GenerateSingleHistory[MultisetSubstitutionSystem[{a_, b_} :> {a + b}], MaxEvents -> 4] @ {1, 2, 3} Out[] = {{1, 2, 3}, {3, 3}, {6}} ``` * `GenerateAllHistories`: ```wl In[] := #["ExpressionsEventsGraph", VertexLabels -> Placed[Automatic, After]] & @ SetReplaceTypeConvert[{WolframModelEvolutionObject, 2}] @ GenerateMultihistory[ MultisetSubstitutionSystem[{a_, b_} /; a < b :> {a + b}], MaxGeneration -> 2] @ Range[3] ``` <img width="399" alt="image" src="https://user-images.githubusercontent.com/1479325/122285946-f08ade80-ceb4-11eb-882d-7da3fdeb75fb.png">
1 parent 5483c0e commit 6802e3a

34 files changed

+1061
-1322
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# $SetReplaceGenerators
2+
3+
**`$SetReplaceGenerators`** gives the list of all generators that can be used to evaluate
4+
[computational systems](/Documentation/Systems/README.md):
5+
6+
```wl
7+
In[] := $SetReplaceGenerators
8+
Out[] = {GenerateMultihistory, GenerateSingleHistory}
9+
```

Documentation/Generators/$SetReplaceSystems.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# $SetReplaceSystems
22

33
**`$SetReplaceSystems`** gives the list of all [computational systems](/Documentation/Systems/README.md) that can be
4-
used with [GenerateMultihistory](/Documentation/Generators/GenerateMultihistory.md) and related functions:
4+
used with [GenerateMultihistory](/Documentation/Generators/GenerateMultihistory.md) and other [generators](README.md):
55

66
```wl
77
In[] := $SetReplaceSystems

Documentation/Generators/EventOrderingFunctions.md

-142
This file was deleted.

Documentation/Generators/EventSelectionParameters.md

-168
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
# GenerateMultihistory
22

3-
**`GenerateMultihistory`** is the most verbose and configurable generator. It can create both single histories, full
4-
multihistories, as well as partial ones. It, however, requires one to specify all groups of parameters
5-
([system](/Documentation/Systems/README.md), [event selection](EventSelectionParameters.md), deduplication,
6-
[event ordering](EventOrderingFunctions.md) and [stopping conditions](StoppingConditionParameters.md)), nothing is
7-
implied automatically:
8-
9-
```wl
10-
GenerateMultihistory[
11-
system, eventSelectionSpec, tokenDeduplicationSpec, eventOrderingSpec, stoppingConditionSpec] @ init
12-
```
3+
**`GenerateMultihistory`** is the most configurable multihistory generator. With no parameters specified, it attempts to
4+
generate all possible histories starting from the initial state. However, it can be configured to generate partial
5+
multihistories and even single histories, although [`GenerateSingleHistory`](GenerateSingleHistory.md) is more
6+
convenient for that.
137

148
For example, for a [`MultisetSubstitutionSystem`](/Documentation/Systems/MultisetSubstitutionSystem.md):
159

1610
```wl
17-
In[] := multihistory = GenerateMultihistory[MultisetSubstitutionSystem[{a_, b_} :> {a + b}],
18-
{"MaxDestroyerEvents" -> 3},
19-
None,
20-
EventOrderingFunctions[MultisetSubstitutionSystem],
21-
{"MaxEvents" -> 10}] @ {1, 2, 3, 4}
11+
In[] := multihistory = GenerateMultihistory[
12+
MultisetSubstitutionSystem[{a_, b_} :> {a + b}], MaxDestroyerEvents -> 3, MaxEvents -> 10] @ {1, 2, 3, 4}
2213
```
2314

2415
<img src="/Documentation/Images/MultisetMultihistory.png" width="472.2">
@@ -29,11 +20,3 @@ In[] := #["ExpressionsEventsGraph", VertexLabels -> Placed[Automatic, After]] &
2920
```
3021

3122
<img src="/Documentation/Images/GenerateMultihistoryExample.png" width="478.2">
32-
33-
Everything that can be generated with more specialized `GenerateSingleHistory` and `GenerateFullMultihistory` can be
34-
reproduced with `GenerateMultihistory` as well. This can be done by setting `"MaxDestroyerEvents" -> 1` to emulate
35-
`GenerateSingleHistory` and setting `"MaxDestroyerEvents" -> Infinity` and leaving the
36-
[stopping condition](StoppingConditionParameters.md) empty to emulate `GenerateFullMultihistory`.
37-
38-
However, by setting `"MaxDestroyerEvents"` to finite values larger than 1, one can generate multihistories not possible
39-
with other generators.

0 commit comments

Comments
 (0)