diff --git a/Documentation/Images/Hypergraph.png b/Documentation/Images/Hypergraph.png new file mode 100644 index 00000000..879e12cf Binary files /dev/null and b/Documentation/Images/Hypergraph.png differ diff --git a/Documentation/Images/HypergraphCyclic.png b/Documentation/Images/HypergraphCyclic.png new file mode 100644 index 00000000..d5ca4465 Binary files /dev/null and b/Documentation/Images/HypergraphCyclic.png differ diff --git a/Documentation/Images/HypergraphPartError.png b/Documentation/Images/HypergraphPartError.png new file mode 100644 index 00000000..820edc8f Binary files /dev/null and b/Documentation/Images/HypergraphPartError.png differ diff --git a/Documentation/SymbolsAndFunctions/Hypergraph.md b/Documentation/SymbolsAndFunctions/Hypergraph.md new file mode 100644 index 00000000..ceeb8972 --- /dev/null +++ b/Documentation/SymbolsAndFunctions/Hypergraph.md @@ -0,0 +1,98 @@ +###### [Symbols and Functions](/README.md#symbols-and-functions) > + +# Hypergraph + +[HypergraphQ](#hypergraphq) | [HypergraphSymmetry](#hypergraphsymmetry) + +**`Hypergraph[...]`** represents a hypergraph object: + +```wl +In[] := Hypergraph[{{1, 1, 2}}] +``` + + + +`Hypergraph` follows the footsteps of [Graph](http://reference.wolfram.com/language/ref/Graph.html), in that the +`Hypergraph` symbol acts both as a constructor and as an object. + +The second argument of `Hypergraph` specifies the global [symmetry](#hypergraphsymmetry) of its hyperedges. + +```wl +In[] := Hypergraph[{{1, 1, 2}}, "Cyclic"] +``` + + + +If left unspecified, the default symmetry is `"Ordered"`: + +```wl +In[] := Hypergraph[{{1, 1, 2}}] === Hypergraph[{{1, 1, 2}}, "Ordered"] +Out[] = True +``` + +`Hypergraph` objects are atomic raw objects: + +```wl +In[] := AtomQ[Hypergraph[{{1, 1, 1}}]] +Out[] = True +``` + +Given their atomic nature, [parts](http://reference.wolfram.com/language/ref/Part.html) of a `Hypergraph` object +cannot be extracted: + +```wl +In[] := Hypergraph[{{1, 1, 1}}][[1]] +``` + + + +For this reason, the following accesor functions are supported: + +```wl +In[] := hg = Hypergraph[{{1, 1, 2}, {2, 5, 4, 3}, {3, 6}}, "Unordered"]; +``` + +- [`EdgeList`](http://reference.wolfram.com/language/ref/EdgeList.html) - the list of (hyper)edges in the hypergraph: + + ```wl + In[] := EdgeList[hg] + Out[] = {{1, 1, 2}, {2, 5, 4, 3}, {3, 6}} + ``` + +- [`VertexList`](http://reference.wolfram.com/language/ref/VertexList.html)- the list of vertices and in the + hypergraph: + + ```wl + In[] := VertexList[hg] + Out[] = {1, 2, 5, 4, 3, 6} + ``` + +- [`HypergraphSymmetry`](#hypergraphsymmetry) - the hypergraph symmetry: + + ```wl + In[]:= HypergraphSymmetry[hg] + Out[]= "Unordered" + ``` + +## HypergraphQ + +**`HypergraphQ[hg]`** returns True if `hg` is a valid [`Hypergraph`](#hypergraph) object and False otherwise: + +```wl +In[] := HypergraphQ[Hypergraph[{{1, 1, 2}}]] +Out[] = True +``` + +```wl +In[] := Quiet @ HypergraphQ[Hypergraph[1]] +Out[] = False +``` + +## HypergraphSymmetry + +A (global) hypergraph symmetry specifies the type of permutation under which each hyperedge of the hypergraph is +considered invariant. + +- Ordered: +- Unordered: +- Cyclic: diff --git a/Kernel/Hypergraph.m b/Kernel/Hypergraph.m new file mode 100644 index 00000000..25ae874f --- /dev/null +++ b/Kernel/Hypergraph.m @@ -0,0 +1,135 @@ +Package["SetReplace`"] + +PackageImport["GeneralUtilities`"] + +PackageExport["Hypergraph"] +PackageExport["HypergraphQ"] +PackageExport["HypergraphSymmetry"] + +SetRelatedSymbolGroup[Hypergraph, HypergraphQ, HypergraphSymmetry, EdgeList, VertexList]; + +(* HypergraphQ *) + +SetUsage @ "HypergraphQ[hg$] yields True if hg$ is a valid Hypergraph object and False otherwise."; + +SyntaxInformation[HypergraphQ] = {"ArgumentsPattern" -> {expr_}}; + +HypergraphQ[expr_Hypergraph] := System`Private`HoldNoEntryQ[expr]; +HypergraphQ[_] = False; + +(* HypergraphSymmetry *) + +$hypergraphSymmetries = {"Ordered", "Unordered", "Cyclic"(*, "Directed"*)}; + +SetUsage @ "HypergraphSymmetry[hg$] returns the symmetry of the hypergraph hg$."; + +SyntaxInformation[HypergraphSymmetry] = {"ArgumentsPattern" -> {hypergraph_}}; + +HypergraphSymmetry[HoldPattern[Hypergraph[hyperedges_, symmetry_] ? HypergraphQ]] := symmetry; + +(* Hypergraph *) + +SetUsage[Hypergraph, " +Hypergraph[{he$1, he$2, $$}] yields an ordered hypergraph with hyperedges he$j. +Hypergraph[$$, sym$] returns a hypergraph with symmetry sym$. +* Valid hypergraph symmetries include: " <> listToSentence[$hypergraphSymmetries] <> ". +"]; + +SyntaxInformation[Hypergraph] = {"ArgumentsPattern" -> {hyperedges_, symmetry_.}}; + +With[{symmetries = $hypergraphSymmetries}, + FE`Evaluate[FEPrivate`AddSpecialArgCompletion["Hypergraph" -> {0, symmetries}]] +]; + +Hypergraph /: Information`GetInformation[obj_Hypergraph ? HypergraphQ] := + <| + "ObjectType" -> Hypergraph, + "Symmetry" -> HypergraphSymmetry[obj], + "VertexCount" -> VertexCount[obj], + "EdgeCount" -> EdgeCount[obj], + "Functions" -> Sort @ { + EdgeCount, + EdgeList, + HypergraphSymmetry, + Information, + Normal, + SameQ, + VertexCount, + VertexList + } + |>; + +((expr : Hypergraph[args___]) ? System`Private`HoldEntryQ) /; CheckArguments[expr, {1, 2}] := + With[{ + result = Catch[hypergraph[args], + _ ? FailureQ, + message[Hypergraph, #, <|"expr" -> HoldForm[expr]|>] &] + }, + result /; !FailureQ[result] + ]; + +hypergraph[hyperedges_] := hypergraph[hyperedges, "Ordered"]; + +hypergraph[hyperedges : {___List}, symmetry : Alternatives @@ $hypergraphSymmetries] := + System`Private`ConstructNoEntry[Hypergraph, hyperedges, symmetry]; + +declareMessage[Hypergraph::invalidHyperedges, + "The argument at position 1 in `expr` should be a list of of lists."]; + +hypergraph[hyperedges_, symmetry : Alternatives @@ $hypergraphSymmetries] := + throw[Failure["invalidHyperedges", <||>]]; + +declareMessage[Hypergraph::invalidSymmetry, + "The argument at position 2 in `expr` should be a supported symmetry: `symmetries`."]; + +hypergraph[hyperedges_, symmetry_] := + throw[Failure["invalidSymmetry", <|"symmetries" -> $hypergraphSymmetries|>]]; + +(* Accessors *) + +Hypergraph /: EdgeList[HoldPattern[Hypergraph[hyperedges_, _] ? HypergraphQ]] := hyperedges; + +Hypergraph /: EdgeCount[hg_Hypergraph ? HypergraphQ] := Length[EdgeList[hg]]; + +Hypergraph /: VertexList[hg_Hypergraph ? HypergraphQ] := DeleteDuplicates[Catenate[EdgeList[hg]]]; + +Hypergraph /: VertexCount[hg_Hypergraph ? HypergraphQ] := Length[VertexList[hg]]; + +(* Normal *) + +Hypergraph /: Normal[hg_Hypergraph ? HypergraphQ] := EdgeList[hg]; + +(* SameQ *) + +Hypergraph /: SameQ[hg1_Hypergraph, hg2_Hypergraph] := Normal[hg1] === Normal[hg2]; + +(* Boxes *) + +disablePlotQ = TrueQ[EdgeCount[#] > 100] &; + +$iconSize = Dynamic[{Automatic, 3.5` CurrentValue["FontCapHeight"]/ AbsoluteCurrentValue[Magnification]}]; + +getIcon[hg_] /; (!disablePlotQ[hg] && MemberQ[$edgeTypes, HypergraphSymmetry[hg]]) := + HypergraphPlot[EdgeList[hg], HypergraphSymmetry[hg], ImageSize -> $iconSize]; + +getIcon[_] = style[$lightTheme][$evolutionObjectIcon]; + +Hypergraph /: MakeBoxes[hg_Hypergraph ? HypergraphQ, fmt_] := + Module[{collapsed, expanded}, + collapsed = BoxForm`SummaryItem /@ { + {"VertexCount: ", VertexCount[hg]}, + {"EdgeCount: ", EdgeCount[hg]} + }; + expanded = BoxForm`SummaryItem /@ { + {"Symmetry: ", HypergraphSymmetry[hg]} + }; + BoxForm`ArrangeSummaryBox[ + Hypergraph, + hg, + getIcon[hg], + collapsed, + expanded, + fmt, + "Interpretable" -> True + ] + ]; diff --git a/README.md b/README.md index 7cc564b6..fa347fa2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## Set Substitution Systems -*SetReplace* is a [Wolfram Language](https://www.wolfram.com/language/) package for manipulating set substitution +_SetReplace_ is a [Wolfram Language](https://www.wolfram.com/language/) package for manipulating set substitution systems. To understand what a set substitution system does consider an unordered set of elements: ```wl @@ -21,7 +21,7 @@ We can set up an operation on this set which would take any of the two elements {a_, b_} :> {a + b} ``` -In *SetReplace*, this can be expressed as the following (the new element `1 + 2 -> 3` is put at the end) +In _SetReplace_, this can be expressed as the following (the new element `1 + 2 -> 3` is put at the end) ```wl In[] := SetReplace[{1, 2, 5, 3, 6}, {a_, b_} :> {a + b}] @@ -105,21 +105,21 @@ Exploring the hypergraph models of this variety is the primary purpose of this p ## Dependencies -You only need three things to use *SetReplace*: +You only need three things to use _SetReplace_: -* Windows, macOS 10.12+, or Linux. -* Windows only — +- Windows, macOS 10.12+, or Linux. +- Windows only — [Microsoft Visual C++ Redistributable 2015+](https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0). -* [Wolfram Language 12.3+](https://www.wolfram.com/language/) +- [Wolfram Language 12.3+](https://www.wolfram.com/language/) including [WolframScript](https://www.wolfram.com/wolframscript/). A free version is available as [Wolfram Engine](https://www.wolfram.com/engine/). -* A C++17 compiler to build the low-level part of the package. Instructions on how to set up a compiler to use in +- A C++17 compiler to build the low-level part of the package. Instructions on how to set up a compiler to use in WolframScript are [here](https://reference.wolfram.com/language/CCompilerDriver/tutorial/SpecificCompilers.html#509267359). ## Build Instructions -For users who wish to make use of *SetReplace* functionality, and not modify the source code itself, we recommend simply +For users who wish to make use of _SetReplace_ functionality, and not modify the source code itself, we recommend simply building and installing the paclet. To do this, run the following on the command line: @@ -131,11 +131,11 @@ cd ~/PATH-TO-CHECKOUT/SetReplace Please note that if you do not have GitLink installed, it will be installed for you. -Now that you have installed the *SetReplace* paclet, you should evaluate ``<< SetReplace` `` every time you start a +Now that you have installed the _SetReplace_ paclet, you should evaluate `` << SetReplace` `` every time you start a fresh Mathematica session. This will load the paclet and bring the various functions into scope, so that you can call them. -For more info about doing development on the *SetReplace* codebase and the associated workflows, see +For more info about doing development on the _SetReplace_ codebase and the associated workflows, see the [Contributing guide](.github/CONTRIBUTING.md#building-in-place). ### C++17 @@ -148,17 +148,17 @@ following, for instance, typically works on a Mac: COMPILER=CCompilerDriver\`ClangCompiler\`ClangCompiler COMPILER_INSTALLATION=/usr/bin ./install.wls ``` -Here `ClangCompiler` can be replaced with one of ``<< CCompilerDriver`; "Compiler" /. CCompilerDriver`CCompilers[Full]`` +Here `ClangCompiler` can be replaced with one of `` << CCompilerDriver`; "Compiler" /. CCompilerDriver`CCompilers[Full] `` , and `COMPILER_INSTALLATION` is a directory in which the compiler binary can be found. ## Contributing Keep in mind that this is an active research project. While we try to keep the main functionality backward compatible, it might change in the future as we adjust our models and find better ways of analysis. Keep that in mind when building -on top of *SetReplace*, and keep track of [git SHAs](Documentation/SymbolsAndFunctions/UtilityFunctions/BuildData.md) as +on top of _SetReplace_, and keep track of [git SHAs](Documentation/SymbolsAndFunctions/UtilityFunctions/BuildData.md) as you go. -*SetReplace* is an open-source project, and everyone is welcome to contribute. Read +_SetReplace_ is an open-source project, and everyone is welcome to contribute. Read our [contributing guidelines](.github/CONTRIBUTING.md) to get started. We have a [Discord server](https://discord.setreplace.org). If you would like to contribute but have questions or don't @@ -167,71 +167,72 @@ ideas. So, if you are interested, please join! # Symbols and Functions -* [SetReplace\*](Documentation/SymbolsAndFunctions/SetReplace.md) -* [ToPatternRules](Documentation/SymbolsAndFunctions/ToPatternRules.md) -* [WolframModel and WolframModelEvolutionObject](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/WolframModelAndWolframModelEvolutionObject.md) - * Properties - * [States](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/States.md) - * [Plots of States](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/PlotsOfStates.md) - * [Plots of Events](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/PlotsOfEvents.md) - * [All Edges throughout Evolution](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/AllEdgesThroughoutEvolution.md) - * [States as Edge Indices](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/StatesAsEdgeIndices.md) - * [Events](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/Events.md) - * [Events and States](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/EventsAndStates.md) - * [Creator and Destroyer Events](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/CreatorAndDestroyerEvents.md) - * [Causal Graphs](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/CausalGraphs.md) - * [Expression Separations](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/ExpressionSeparations.md) - * [MultiwayQ](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/MultiwayQ.md) - * [Rule Indices for Events](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/RuleIndicesForEvents.md) - * [Edge and Event Generations](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/EdgeAndEventGenerations.md) - * [Termination Reason](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/TerminationReason.md) - * [Generation Counts](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/GenerationCounts.md) - * [Event Counts](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/EventCounts.md) - * [Element Count Lists](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/ElementCountLists.md) - * [Final Element Counts](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/FinalElementCounts.md) - * [Total Element Counts](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/TotalElementCounts.md) - * [Rules](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/Rules.md) - * [Feature Association](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/FeatureAssociation.md) - * [Feature Vector](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/FeatureVector.md) - * [Version](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/Version.md) - * Options - * ["VertexNamingFunction"](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/VertexNamingFunction.md) - * ["IncludePartialGenerations"](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/IncludePartialGenerations.md) - * ["IncludeBoundaryEvents"](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/IncludeBoundaryEvents.md) - * ["EventOrderingFunction"](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/EventOrderingFunction.md) - * ["EventSelectionFunction"](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/EventSelectionFunction.md) - * ["EventDeduplication"](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/EventDeduplication.md) - * [Method](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/Method.md) - * [Time Constraint](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/TimeConstraint.md) -* [HypergraphPlot](Documentation/SymbolsAndFunctions/HypergraphPlot.md) -* [RulePlot of WolframModel](Documentation/SymbolsAndFunctions/RulePlotOfWolframModel.md) -* Utility Functions - * [CausalDensityDimension](Documentation/SymbolsAndFunctions/UtilityFunctions/CausalDensityDimension.md) - * [AcyclicGraphTake](Documentation/SymbolsAndFunctions/UtilityFunctions/AcyclicGraphTake.md) - * [IndexHypergraph](Documentation/SymbolsAndFunctions/UtilityFunctions/IndexHypergraph.md) - * [IsomorphicHypergraphQ](Documentation/SymbolsAndFunctions/UtilityFunctions/IsomorphicHypergraphQ.md) - * [HypergraphToGraph](Documentation/SymbolsAndFunctions/UtilityFunctions/HypergraphToGraph.md) - * [RandomHypergraph](Documentation/SymbolsAndFunctions/UtilityFunctions/RandomHypergraph.md) - * [Subhypergraph](Documentation/SymbolsAndFunctions/UtilityFunctions/Subhypergraph.md) - * [WolframModelRuleValue](Documentation/SymbolsAndFunctions/UtilityFunctions/WolframModelRuleValue.md) - * [GeneralizedGridGraph](Documentation/SymbolsAndFunctions/UtilityFunctions/GeneralizedGridGraph.md) - * [HypergraphAutomorphismGroup](Documentation/SymbolsAndFunctions/UtilityFunctions/HypergraphAutomorphismGroup.md) - * [HypergraphUnifications](Documentation/SymbolsAndFunctions/UtilityFunctions/HypergraphUnifications.md) - * [SetReplaceStyleData](Documentation/SymbolsAndFunctions/UtilityFunctions/SetReplaceStyleData.md) - * [Build Data](Documentation/SymbolsAndFunctions/UtilityFunctions/BuildData.md) +- [SetReplace\*](Documentation/SymbolsAndFunctions/SetReplace.md) +- [ToPatternRules](Documentation/SymbolsAndFunctions/ToPatternRules.md) +- [WolframModel and WolframModelEvolutionObject](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/WolframModelAndWolframModelEvolutionObject.md) + - Properties + - [States](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/States.md) + - [Plots of States](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/PlotsOfStates.md) + - [Plots of Events](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/PlotsOfEvents.md) + - [All Edges throughout Evolution](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/AllEdgesThroughoutEvolution.md) + - [States as Edge Indices](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/StatesAsEdgeIndices.md) + - [Events](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/Events.md) + - [Events and States](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/EventsAndStates.md) + - [Creator and Destroyer Events](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/CreatorAndDestroyerEvents.md) + - [Causal Graphs](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/CausalGraphs.md) + - [Expression Separations](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/ExpressionSeparations.md) + - [MultiwayQ](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/MultiwayQ.md) + - [Rule Indices for Events](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/RuleIndicesForEvents.md) + - [Edge and Event Generations](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/EdgeAndEventGenerations.md) + - [Termination Reason](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/TerminationReason.md) + - [Generation Counts](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/GenerationCounts.md) + - [Event Counts](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/EventCounts.md) + - [Element Count Lists](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/ElementCountLists.md) + - [Final Element Counts](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/FinalElementCounts.md) + - [Total Element Counts](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/TotalElementCounts.md) + - [Rules](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/Rules.md) + - [Feature Association](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/FeatureAssociation.md) + - [Feature Vector](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/FeatureVector.md) + - [Version](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/Version.md) + - Options + - ["VertexNamingFunction"](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/VertexNamingFunction.md) + - ["IncludePartialGenerations"](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/IncludePartialGenerations.md) + - ["IncludeBoundaryEvents"](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/IncludeBoundaryEvents.md) + - ["EventOrderingFunction"](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/EventOrderingFunction.md) + - ["EventSelectionFunction"](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/EventSelectionFunction.md) + - ["EventDeduplication"](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/EventDeduplication.md) + - [Method](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/Method.md) + - [Time Constraint](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Options/TimeConstraint.md) +- [Hypergraph](Documentation/SymbolsAndFunctions/Hypergraph.md) +- [HypergraphPlot](Documentation/SymbolsAndFunctions/HypergraphPlot.md) +- [RulePlot of WolframModel](Documentation/SymbolsAndFunctions/RulePlotOfWolframModel.md) +- Utility Functions + - [CausalDensityDimension](Documentation/SymbolsAndFunctions/UtilityFunctions/CausalDensityDimension.md) + - [AcyclicGraphTake](Documentation/SymbolsAndFunctions/UtilityFunctions/AcyclicGraphTake.md) + - [IndexHypergraph](Documentation/SymbolsAndFunctions/UtilityFunctions/IndexHypergraph.md) + - [IsomorphicHypergraphQ](Documentation/SymbolsAndFunctions/UtilityFunctions/IsomorphicHypergraphQ.md) + - [HypergraphToGraph](Documentation/SymbolsAndFunctions/UtilityFunctions/HypergraphToGraph.md) + - [RandomHypergraph](Documentation/SymbolsAndFunctions/UtilityFunctions/RandomHypergraph.md) + - [Subhypergraph](Documentation/SymbolsAndFunctions/UtilityFunctions/Subhypergraph.md) + - [WolframModelRuleValue](Documentation/SymbolsAndFunctions/UtilityFunctions/WolframModelRuleValue.md) + - [GeneralizedGridGraph](Documentation/SymbolsAndFunctions/UtilityFunctions/GeneralizedGridGraph.md) + - [HypergraphAutomorphismGroup](Documentation/SymbolsAndFunctions/UtilityFunctions/HypergraphAutomorphismGroup.md) + - [HypergraphUnifications](Documentation/SymbolsAndFunctions/UtilityFunctions/HypergraphUnifications.md) + - [SetReplaceStyleData](Documentation/SymbolsAndFunctions/UtilityFunctions/SetReplaceStyleData.md) + - [Build Data](Documentation/SymbolsAndFunctions/UtilityFunctions/BuildData.md) # Physics A hypothesis is that spacetime at small scales is a network, and the fundamental law of physics is a system similar to the one this package implements. -A slightly different version of this system was first introduced in *Stephen Wolfram*' +A slightly different version of this system was first introduced in _Stephen Wolfram_' s [A New Kind Of Science](https://www.wolframscience.com/nks/chap-9--fundamental-physics/). # Acknowledgements -In additional to commit authors and reviewers, *Stephen Wolfram* has contributed to the API design of some functions, -and *Jeremy Davis* has contributed to the visual style +In additional to commit authors and reviewers, _Stephen Wolfram_ has contributed to the API design of some functions, +and _Jeremy Davis_ has contributed to the visual style of [`HypergraphPlot`](Documentation/SymbolsAndFunctions/HypergraphPlot.md) , [`RulePlot`](Documentation/SymbolsAndFunctions/RulePlotOfWolframModel.md) and [`"CausalGraph"`](Documentation/SymbolsAndFunctions/WolframModelAndWolframModelEvolutionObject/Properties/CausalGraphs.md) diff --git a/Tests/Hypergraph.wlt b/Tests/Hypergraph.wlt new file mode 100644 index 00000000..8534fdd3 --- /dev/null +++ b/Tests/Hypergraph.wlt @@ -0,0 +1,72 @@ +<| + "HypergraphPlot" -> <| + "init" -> ( + Attributes[Global`testUnevaluated] = Attributes[Global`testSymbolLeak] = {HoldAll}; + Global`testUnevaluated[args___] := SetReplace`PackageScope`testUnevaluated[VerificationTest, args]; + Global`testSymbolLeak[args___] := SetReplace`PackageScope`testSymbolLeak[VerificationTest, args]; + + Global`$hypergraphSymmetries = SetReplace`Hypergraph`PackagePrivate`$hypergraphSymmetries; + ), + "tests" -> { + (* Argument Checks *) + + (** Argument count **) + + testUnevaluated[ + Hypergraph[], + {Hypergraph::argt} + ], + + testUnevaluated[ + Hypergraph[{{1, 1, 1}}, "Ordered", 1], + {Hypergraph::argt} + ], + + (** 1st argument **) + + testUnevaluated[ + Hypergraph[{1, 1, 1}], + {Hypergraph::invalidHyperedges} + ], + + (** 2nd argument **) + + testUnevaluated[ + Hypergraph[{{1, 1, 1}}, "Directed"], + {Hypergraph::invalidSymmetry} + ], + + (* Constructor *) + + VerificationTest[HypergraphQ[Hypergraph[{{1, 1, 1}}]]], + + VerificationTest[HypergraphQ[Hypergraph[{{1, {1}}, {{1}, x, y}}]]], + + (* Default 2nd argument *) + + VerificationTest[Hypergraph[{{1}}] === Hypergraph[{{1}}, "Ordered"]], + + (* Available symmetries *) + + VerificationTest[AllTrue[Hypergraph[{{1}}, #] & /@ $hypergraphSymmetries, HypergraphQ]], + + (* Accessors *) + + With[{hg = Hypergraph[{{1, 1, 2}, {2, 5, 4, 3}, {3, 6}}, "Unordered"]}, + { + VerificationTest[VertexList[hg], {1, 2, 5, 4, 3, 6}], + + VerificationTest[EdgeList[hg], {{1, 1, 2}, {2, 5, 4, 3}, {3, 6}}], + + VerificationTest[Normal[hg], EdgeList[hg]], + + VerificationTest[VertexCount[hg] === Length[VertexList[hg]] === 6], + + VerificationTest[EdgeCount[hg] === Length[EdgeList[hg]] === 3], + + VerificationTest[HypergraphSymmetry[hg], "Unordered"] + } + ] + } + |> +|>