-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathMultisetToWolframModelEvolutionObject.m
30 lines (25 loc) · 1.35 KB
/
MultisetToWolframModelEvolutionObject.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Package["SetReplace`"]
PackageImport["GeneralUtilities`"]
declareTypeTranslation[toWolframModelEvolutionObject,
SetReplaceType[MultisetSubstitutionSystem, 0],
SetReplaceType[WolframModelEvolutionObject, 2]];
toWolframModelEvolutionObject[Multihistory[_, data_]] := WolframModelEvolutionObject[<|
"Version" -> 2,
"Rules" -> Normal @ checkNotMissing[data["Rules"]],
"MaxCompleteGeneration" -> Missing[],
"TerminationReason" -> Switch[data["TerminationReason"],
"Complete", "FixedPoint",
"MaxEvents", "MaxEvents",
_, throw[Failure["corruptMultisetMultihistory", <||>]]],
"AtomLists" -> Normal @ checkNotMissing[data["Expressions"]],
"EventRuleIDs" -> Normal @ checkNotMissing[data["EventRuleIndices"]],
"EventInputs" -> Normal @ checkNotMissing[data["EventInputs"]],
"EventOutputs" -> Normal @ checkNotMissing[data["EventOutputs"]],
"EventGenerations" -> Normal @ checkNotMissing[data["EventGenerations"]]
|>];
declareMessage[
General::corruptMultisetMultihistory,
"MultisetSubstitutionSystem Multihistory is corrupt in `expr`. Use MultisetSubstitutionSystem and a generator " <>
"function such as GenerateMultihistory to generate MultisetSubstitutionSystem Multihistory objects."];
checkNotMissing[_ ? MissingQ] := throw[Failure["corruptMultisetMultihistory", <||>]];
checkNotMissing[arg_] := arg;