Skip to content

Commit

Permalink
Simplified generator system (#657)
Browse files Browse the repository at this point in the history
## 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">
  • Loading branch information
maxitg authored Jul 19, 2021
1 parent 5483c0e commit 6802e3a
Show file tree
Hide file tree
Showing 34 changed files with 1,061 additions and 1,322 deletions.
9 changes: 9 additions & 0 deletions Documentation/Generators/$SetReplaceGenerators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# $SetReplaceGenerators

**`$SetReplaceGenerators`** gives the list of all generators that can be used to evaluate
[computational systems](/Documentation/Systems/README.md):

```wl
In[] := $SetReplaceGenerators
Out[] = {GenerateMultihistory, GenerateSingleHistory}
```
2 changes: 1 addition & 1 deletion Documentation/Generators/$SetReplaceSystems.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# $SetReplaceSystems

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

```wl
In[] := $SetReplaceSystems
Expand Down
142 changes: 0 additions & 142 deletions Documentation/Generators/EventOrderingFunctions.md

This file was deleted.

168 changes: 0 additions & 168 deletions Documentation/Generators/EventSelectionParameters.md

This file was deleted.

29 changes: 6 additions & 23 deletions Documentation/Generators/GenerateMultihistory.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
# GenerateMultihistory

**`GenerateMultihistory`** is the most verbose and configurable generator. It can create both single histories, full
multihistories, as well as partial ones. It, however, requires one to specify all groups of parameters
([system](/Documentation/Systems/README.md), [event selection](EventSelectionParameters.md), deduplication,
[event ordering](EventOrderingFunctions.md) and [stopping conditions](StoppingConditionParameters.md)), nothing is
implied automatically:

```wl
GenerateMultihistory[
system, eventSelectionSpec, tokenDeduplicationSpec, eventOrderingSpec, stoppingConditionSpec] @ init
```
**`GenerateMultihistory`** is the most configurable multihistory generator. With no parameters specified, it attempts to
generate all possible histories starting from the initial state. However, it can be configured to generate partial
multihistories and even single histories, although [`GenerateSingleHistory`](GenerateSingleHistory.md) is more
convenient for that.

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

```wl
In[] := multihistory = GenerateMultihistory[MultisetSubstitutionSystem[{a_, b_} :> {a + b}],
{"MaxDestroyerEvents" -> 3},
None,
EventOrderingFunctions[MultisetSubstitutionSystem],
{"MaxEvents" -> 10}] @ {1, 2, 3, 4}
In[] := multihistory = GenerateMultihistory[
MultisetSubstitutionSystem[{a_, b_} :> {a + b}], MaxDestroyerEvents -> 3, MaxEvents -> 10] @ {1, 2, 3, 4}
```

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

<img src="/Documentation/Images/GenerateMultihistoryExample.png" width="478.2">

Everything that can be generated with more specialized `GenerateSingleHistory` and `GenerateFullMultihistory` can be
reproduced with `GenerateMultihistory` as well. This can be done by setting `"MaxDestroyerEvents" -> 1` to emulate
`GenerateSingleHistory` and setting `"MaxDestroyerEvents" -> Infinity` and leaving the
[stopping condition](StoppingConditionParameters.md) empty to emulate `GenerateFullMultihistory`.

However, by setting `"MaxDestroyerEvents"` to finite values larger than 1, one can generate multihistories not possible
with other generators.
Loading

0 comments on commit 6802e3a

Please sign in to comment.