{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "2c21cdd7",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Usask/Research/CategoryTheory/ABMs/act-abm/July7_2023_Project_toml`\n"
]
}
],
"source": [
"using Pkg;\n",
"Pkg.activate(\"July7_2023_Project_toml\");"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5046ea0a",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n",
"\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m `~/Usask/Research/CategoryTheory/ABMs/act-abm/July7_2023_Project_toml/Project.toml`\n",
"\u001b[33m⌅\u001b[39m \u001b[90m[725a01d3] \u001b[39m\u001b[92m+ AlgebraicRewriting v0.2.1\u001b[39m\n",
"\u001b[33m⌅\u001b[39m \u001b[90m[134e5e36] \u001b[39m\u001b[92m+ Catlab v0.15.5\u001b[39m\n",
" \u001b[90m[295af30f] \u001b[39m\u001b[92m+ Revise v3.5.13\u001b[39m\n",
"\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m `~/Usask/Research/CategoryTheory/ABMs/act-abm/July7_2023_Project_toml/Manifest.toml`\n",
" \u001b[90m[227ef7b5] \u001b[39m\u001b[92m+ ACSets v0.2.13\u001b[39m\n",
" \u001b[90m[23cfdc9f] \u001b[39m\u001b[92m+ AlgebraicInterfaces v0.1.1\u001b[39m\n",
"\u001b[33m⌅\u001b[39m \u001b[90m[725a01d3] \u001b[39m\u001b[92m+ AlgebraicRewriting v0.2.1\u001b[39m\n",
"\u001b[33m⌅\u001b[39m \u001b[90m[134e5e36] \u001b[39m\u001b[92m+ Catlab v0.15.5\u001b[39m\n",
" \u001b[90m[da1fd8a2] \u001b[39m\u001b[92m+ CodeTracking v1.3.5\u001b[39m\n",
" \u001b[90m[3da002f7] \u001b[39m\u001b[92m+ ColorTypes v0.11.4\u001b[39m\n",
" \u001b[90m[5ae59095] \u001b[39m\u001b[92m+ Colors v0.12.10\u001b[39m\n",
" \u001b[90m[861a8166] \u001b[39m\u001b[92m+ Combinatorics v1.0.2\u001b[39m\n",
" \u001b[90m[0fb5dd42] \u001b[39m\u001b[92m+ CompTime v0.1.2\u001b[39m\n",
" \u001b[90m[34da2185] \u001b[39m\u001b[92m+ Compat v4.12.0\u001b[39m\n",
" \u001b[90m[a81c6b42] \u001b[39m\u001b[92m+ Compose v0.9.5\u001b[39m\n",
" \u001b[90m[a8cc5b0e] \u001b[39m\u001b[92m+ Crayons v4.1.1\u001b[39m\n",
" \u001b[90m[9a962f9c] \u001b[39m\u001b[92m+ DataAPI v1.15.0\u001b[39m\n",
" \u001b[90m[864edb3b] \u001b[39m\u001b[92m+ DataStructures v0.18.16\u001b[39m\n",
" \u001b[90m[e2d170a0] \u001b[39m\u001b[92m+ DataValueInterfaces v1.0.0\u001b[39m\n",
" \u001b[90m[53c48c17] \u001b[39m\u001b[92m+ FixedPointNumbers v0.8.4\u001b[39m\n",
" \u001b[90m[6b9d7cbe] \u001b[39m\u001b[92m+ GeneralizedGenerated v0.3.3\u001b[39m\n",
" \u001b[90m[c8e1da08] \u001b[39m\u001b[92m+ IterTools v1.10.0\u001b[39m\n",
" \u001b[90m[82899510] \u001b[39m\u001b[92m+ IteratorInterfaceExtensions v1.0.0\u001b[39m\n",
" \u001b[90m[692b3bcd] \u001b[39m\u001b[92m+ JLLWrappers v1.5.0\u001b[39m\n",
" \u001b[90m[682c06a0] \u001b[39m\u001b[92m+ JSON v0.21.4\u001b[39m\n",
" \u001b[90m[0f8b85d8] \u001b[39m\u001b[92m+ JSON3 v1.14.0\u001b[39m\n",
" \u001b[90m[aa1ae85d] \u001b[39m\u001b[92m+ JuliaInterpreter v0.9.28\u001b[39m\n",
" \u001b[90m[b14d175d] \u001b[39m\u001b[92m+ JuliaVariables v0.2.4\u001b[39m\n",
" \u001b[90m[b964fa9f] \u001b[39m\u001b[92m+ LaTeXStrings v1.3.1\u001b[39m\n",
" \u001b[90m[9c8b4983] \u001b[39m\u001b[92m+ LightXML v0.9.1\u001b[39m\n",
" \u001b[90m[6f1432cf] \u001b[39m\u001b[92m+ LoweredCodeUtils v2.4.3\u001b[39m\n",
" \u001b[90m[d8e11817] \u001b[39m\u001b[92m+ MLStyle v0.4.17\u001b[39m\n",
" \u001b[90m[1914dd2f] \u001b[39m\u001b[92m+ MacroTools v0.5.12\u001b[39m\n",
" \u001b[90m[442fdcdd] \u001b[39m\u001b[92m+ Measures v0.3.2\u001b[39m\n",
" \u001b[90m[71a1bf82] \u001b[39m\u001b[92m+ NameResolution v0.1.5\u001b[39m\n",
" \u001b[90m[bac558e1] \u001b[39m\u001b[92m+ OrderedCollections v1.6.3\u001b[39m\n",
" \u001b[90m[69de0a69] \u001b[39m\u001b[92m+ Parsers v2.8.1\u001b[39m\n",
" \u001b[90m[2ae35dd2] \u001b[39m\u001b[92m+ Permutations v0.4.19\u001b[39m\n",
" \u001b[90m[aea7be01] \u001b[39m\u001b[92m+ PrecompileTools v1.2.0\u001b[39m\n",
" \u001b[90m[21216c6a] \u001b[39m\u001b[92m+ Preferences v1.4.1\u001b[39m\n",
" \u001b[90m[8162dcfd] \u001b[39m\u001b[92m+ PrettyPrint v0.2.0\u001b[39m\n",
" \u001b[90m[08abe8d2] \u001b[39m\u001b[92m+ PrettyTables v2.3.1\u001b[39m\n",
" \u001b[90m[189a3867] \u001b[39m\u001b[92m+ Reexport v1.2.2\u001b[39m\n",
" \u001b[90m[ae029012] \u001b[39m\u001b[92m+ Requires v1.3.0\u001b[39m\n",
" \u001b[90m[295af30f] \u001b[39m\u001b[92m+ Revise v3.5.13\u001b[39m\n",
" \u001b[90m[90137ffa] \u001b[39m\u001b[92m+ StaticArrays v1.9.1\u001b[39m\n",
" \u001b[90m[1e83bf80] \u001b[39m\u001b[92m+ StaticArraysCore v1.4.2\u001b[39m\n",
" \u001b[90m[892a3eda] \u001b[39m\u001b[92m+ StringManipulation v0.3.4\u001b[39m\n",
" \u001b[90m[6ec83bb0] \u001b[39m\u001b[92m+ StructEquality v2.1.0\u001b[39m\n",
" \u001b[90m[856f2bd8] \u001b[39m\u001b[92m+ StructTypes v1.10.0\u001b[39m\n",
" \u001b[90m[3783bdb8] \u001b[39m\u001b[92m+ TableTraits v1.0.1\u001b[39m\n",
" \u001b[90m[bd369af6] \u001b[39m\u001b[92m+ Tables v1.11.1\u001b[39m\n",
" \u001b[90m[94ce4f54] \u001b[39m\u001b[92m+ Libiconv_jll v1.17.0+0\u001b[39m\n",
" \u001b[90m[02c8fc9c] \u001b[39m\u001b[92m+ XML2_jll v2.12.2+0\u001b[39m\n",
" \u001b[90m[0dad84c5] \u001b[39m\u001b[92m+ ArgTools v1.1.1\u001b[39m\n",
" \u001b[90m[56f22d72] \u001b[39m\u001b[92m+ Artifacts\u001b[39m\n",
" \u001b[90m[2a0f44e3] \u001b[39m\u001b[92m+ Base64\u001b[39m\n",
" \u001b[90m[ade2ca70] \u001b[39m\u001b[92m+ Dates\u001b[39m\n",
" \u001b[90m[8ba89e20] \u001b[39m\u001b[92m+ Distributed\u001b[39m\n",
" \u001b[90m[f43a241f] \u001b[39m\u001b[92m+ Downloads v1.6.0\u001b[39m\n",
" \u001b[90m[7b1f6079] \u001b[39m\u001b[92m+ FileWatching\u001b[39m\n",
" \u001b[90m[b77e0a4c] \u001b[39m\u001b[92m+ InteractiveUtils\u001b[39m\n",
" \u001b[90m[b27032c2] \u001b[39m\u001b[92m+ LibCURL v0.6.3\u001b[39m\n",
" \u001b[90m[76f85450] \u001b[39m\u001b[92m+ LibGit2\u001b[39m\n",
" \u001b[90m[8f399da3] \u001b[39m\u001b[92m+ Libdl\u001b[39m\n",
" \u001b[90m[37e2e46d] \u001b[39m\u001b[92m+ LinearAlgebra\u001b[39m\n",
" \u001b[90m[56ddb016] \u001b[39m\u001b[92m+ Logging\u001b[39m\n",
" \u001b[90m[d6f4376e] \u001b[39m\u001b[92m+ Markdown\u001b[39m\n",
" \u001b[90m[a63ad114] \u001b[39m\u001b[92m+ Mmap\u001b[39m\n",
" \u001b[90m[ca575930] \u001b[39m\u001b[92m+ NetworkOptions v1.2.0\u001b[39m\n",
" \u001b[90m[44cfe95a] \u001b[39m\u001b[92m+ Pkg v1.9.2\u001b[39m\n",
" \u001b[90m[de0858da] \u001b[39m\u001b[92m+ Printf\u001b[39m\n",
" \u001b[90m[3fa0cd96] \u001b[39m\u001b[92m+ REPL\u001b[39m\n",
" \u001b[90m[9a3f8284] \u001b[39m\u001b[92m+ Random\u001b[39m\n",
" \u001b[90m[ea8e919c] \u001b[39m\u001b[92m+ SHA v0.7.0\u001b[39m\n",
" \u001b[90m[9e88b42a] \u001b[39m\u001b[92m+ Serialization\u001b[39m\n",
" \u001b[90m[6462fe0b] \u001b[39m\u001b[92m+ Sockets\u001b[39m\n",
" \u001b[90m[2f01184e] \u001b[39m\u001b[92m+ SparseArrays\u001b[39m\n",
" \u001b[90m[10745b16] \u001b[39m\u001b[92m+ Statistics v1.9.0\u001b[39m\n",
" \u001b[90m[fa267f1f] \u001b[39m\u001b[92m+ TOML v1.0.3\u001b[39m\n",
" \u001b[90m[a4e569a6] \u001b[39m\u001b[92m+ Tar v1.10.0\u001b[39m\n",
" \u001b[90m[8dfed614] \u001b[39m\u001b[92m+ Test\u001b[39m\n",
" \u001b[90m[cf7118a7] \u001b[39m\u001b[92m+ UUIDs\u001b[39m\n",
" \u001b[90m[4ec0a83e] \u001b[39m\u001b[92m+ Unicode\u001b[39m\n",
" \u001b[90m[e66e0078] \u001b[39m\u001b[92m+ CompilerSupportLibraries_jll v1.0.5+0\u001b[39m\n",
" \u001b[90m[deac9b47] \u001b[39m\u001b[92m+ LibCURL_jll v7.84.0+0\u001b[39m\n",
" \u001b[90m[29816b5a] \u001b[39m\u001b[92m+ LibSSH2_jll v1.10.2+0\u001b[39m\n",
" \u001b[90m[c8ffd9c3] \u001b[39m\u001b[92m+ MbedTLS_jll v2.28.2+0\u001b[39m\n",
" \u001b[90m[14a3606d] \u001b[39m\u001b[92m+ MozillaCACerts_jll v2022.10.11\u001b[39m\n",
" \u001b[90m[4536629a] \u001b[39m\u001b[92m+ OpenBLAS_jll v0.3.21+4\u001b[39m\n",
" \u001b[90m[bea87d4a] \u001b[39m\u001b[92m+ SuiteSparse_jll v5.10.1+6\u001b[39m\n",
" \u001b[90m[83775a58] \u001b[39m\u001b[92m+ Zlib_jll v1.2.13+0\u001b[39m\n",
" \u001b[90m[8e850b90] \u001b[39m\u001b[92m+ libblastrampoline_jll v5.8.0+0\u001b[39m\n",
" \u001b[90m[8e850ede] \u001b[39m\u001b[92m+ nghttp2_jll v1.48.0+0\u001b[39m\n",
" \u001b[90m[3f19e933] \u001b[39m\u001b[92m+ p7zip_jll v17.4.0+0\u001b[39m\n",
"\u001b[36m\u001b[1m Info\u001b[22m\u001b[39m Packages marked with \u001b[33m⌅\u001b[39m have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m`\n",
"\u001b[32m\u001b[1mPrecompiling\u001b[22m\u001b[39m project...\n",
"\u001b[32m ✓ \u001b[39mCatlab\n",
"\u001b[32m ✓ \u001b[39mAlgebraicRewriting\n",
" 2 dependencies successfully precompiled in 31 seconds. 56 already precompiled.\n",
"\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n",
"\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m `~/Usask/Research/CategoryTheory/ABMs/act-abm/July7_2023_Project_toml/Project.toml`\n",
" \u001b[90m[6ec83bb0] \u001b[39m\u001b[92m+ StructEquality v2.1.0\u001b[39m\n",
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/Usask/Research/CategoryTheory/ABMs/act-abm/July7_2023_Project_toml/Manifest.toml`\n",
"\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n",
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/Usask/Research/CategoryTheory/ABMs/act-abm/July7_2023_Project_toml/Project.toml`\n",
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/Usask/Research/CategoryTheory/ABMs/act-abm/July7_2023_Project_toml/Manifest.toml`\n"
]
}
],
"source": [
"import Pkg; Pkg.add(\"Revise\")\n",
"import Pkg; Pkg.add(\"StructEquality\")\n",
"import Pkg; Pkg.add(\"AlgebraicRewriting\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "66492f3a",
"metadata": {},
"outputs": [],
"source": [
"using AlgebraicRewriting;"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "5a06840f",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"dot\", Catlab.Graphics.Graphviz.Statement[Catlab.Graphics.Graphviz.Node(\"n1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"V\")), Catlab.Graphics.Graphviz.Node(\"n2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"E\")), Catlab.Graphics.Graphviz.Node(\"n3\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"Sheep\")), Catlab.Graphics.Graphviz.Node(\"n4\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"Wolf\")), Catlab.Graphics.Graphviz.Node(\"n5\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:shape => \"point\", :xlabel => \"Dir\")), Catlab.Graphics.Graphviz.Node(\"n6\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:shape => \"point\", :xlabel => \"Eng\")), Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID(\"n2\", \"\", \"\"), Catlab.Graphics.Graphviz.NodeID(\"n1\", \"\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"src\")), Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID(\"n2\", \"\", \"\"), Catlab.Graphics.Graphviz.NodeID(\"n1\", \"\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"tgt\")), Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID(\"n3\", \"\", \"\"), Catlab.Graphics.Graphviz.NodeID(\"n1\", \"\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"sheep_loc\")), Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID(\"n4\", \"\", \"\"), Catlab.Graphics.Graphviz.NodeID(\"n1\", \"\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"wolf_loc\")), Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID(\"n1\", \"\", \"\"), Catlab.Graphics.Graphviz.NodeID(\"n6\", \"\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"grass_eng\")), Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID(\"n3\", \"\", \"\"), Catlab.Graphics.Graphviz.NodeID(\"n6\", \"\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"sheep_eng\")), Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID(\"n4\", \"\", \"\"), Catlab.Graphics.Graphviz.NodeID(\"n6\", \"\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"wolf_eng\")), Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID(\"n3\", \"\", \"\"), Catlab.Graphics.Graphviz.NodeID(\"n5\", \"\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"sheep_dir\")), Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID(\"n4\", \"\", \"\"), Catlab.Graphics.Graphviz.NodeID(\"n5\", \"\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"wolf_dir\")), Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID(\"n2\", \"\", \"\"), Catlab.Graphics.Graphviz.NodeID(\"n5\", \"\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"dir\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:margin => \"0\", :shape => \"ellipse\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}())"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using Revise, Random, Test, StructEquality\n",
"using Catlab, Catlab.CategoricalAlgebra, Catlab.Graphs, Catlab.Graphics, Catlab.Programs\n",
"Random.seed!(124);\n",
"\n",
"@present SchLV <: SchGraph begin\n",
" (Sheep,Wolf)::Ob\n",
" sheep_loc::Hom(Sheep, V)\n",
" wolf_loc::Hom(Wolf, V)\n",
"\n",
" (Dir,Eng)::AttrType\n",
" grass_eng::Attr(V, Eng)\n",
" sheep_eng::Attr(Sheep, Eng)\n",
" wolf_eng::Attr(Wolf, Eng)\n",
" sheep_dir::Attr(Sheep, Dir)\n",
" wolf_dir::Attr(Wolf, Dir)\n",
" dir::Attr(E, Dir)\n",
"end;\n",
"to_graphviz(SchLV; prog=\"dot\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "7058095c",
"metadata": {},
"outputs": [],
"source": [
"@present SchLV′ <: SchLV begin\n",
" Coord::AttrType \n",
" coord::Attr(V,Coord)\n",
"end;"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "cfa87a0d",
"metadata": {},
"outputs": [],
"source": [
"import Catlab.CategoricalAlgebra: left, right\n",
"\n",
"function right(s::Symbol) \n",
" if s == :N return :E\n",
" elseif s == :S return :W \n",
" elseif s == :E return :S \n",
" elseif s == :W return :N \n",
" end\n",
"end\n",
"function left(s::Symbol) \n",
" if s == :N return :W\n",
" elseif s == :S return :E \n",
" elseif s == :E return :N \n",
" elseif s == :W return :S \n",
" end\n",
"end\n",
"\n",
"\n",
"\n",
"@acset_type LV_Generic(SchLV) <: HasGraph\n",
"const LV = LV_Generic{Symbol, Int}\n",
"\n",
"@acset_type LV′_Generic(SchLV′) <: HasGraph\n",
"const LV′ = LV′_Generic{Symbol, Int, Tuple{Int,Int}};\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "980575a3",
"metadata": {},
"outputs": [],
"source": [
"using AlgebraicRewriting\n",
"Swap = Migrate(\n",
" Dict(:Sheep=>:Wolf, :Wolf=>:Sheep), \n",
" Dict([:sheep_loc=>:wolf_loc, :wolf_loc=>:sheep_loc,\n",
" :sheep_eng=>:wolf_eng, :wolf_eng=>:sheep_eng,:grass_eng =>:grass_eng,\n",
" :sheep_dir=>:wolf_dir, :wolf_dir=>:sheep_dir,]), LV);"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "fcf1780a",
"metadata": {},
"outputs": [],
"source": [
"Coords = Migrate(\n",
" Dict(x=>x for x in Symbol.(SchLV.generators[:Ob])), \n",
" Dict(x=>x for x in Symbol.(SchLV.generators[:Hom])), \n",
" LV′; delta=false);"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "24acd69b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"
LV′ {V:4, E:16, Sheep:2, Wolf:2, Dir:0, Eng:0, Coord:0}\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 1 | \n",
" (0, 0) | \n",
"
\n",
" \n",
" 2 | \n",
" 15 | \n",
" (0, 1) | \n",
"
\n",
" \n",
" 3 | \n",
" 22 | \n",
" (1, 0) | \n",
"
\n",
" \n",
" 4 | \n",
" 0 | \n",
" (1, 1) | \n",
"
\n",
" \n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 1 | \n",
" 3 | \n",
" E | \n",
"
\n",
" \n",
" 2 | \n",
" 1 | \n",
" 3 | \n",
" W | \n",
"
\n",
" \n",
" 3 | \n",
" 1 | \n",
" 2 | \n",
" N | \n",
"
\n",
" \n",
" 4 | \n",
" 1 | \n",
" 2 | \n",
" S | \n",
"
\n",
" \n",
" 5 | \n",
" 2 | \n",
" 4 | \n",
" E | \n",
"
\n",
" \n",
" 6 | \n",
" 2 | \n",
" 4 | \n",
" W | \n",
"
\n",
" \n",
" 7 | \n",
" 2 | \n",
" 1 | \n",
" N | \n",
"
\n",
" \n",
" 8 | \n",
" 2 | \n",
" 1 | \n",
" S | \n",
"
\n",
" \n",
" 9 | \n",
" 3 | \n",
" 1 | \n",
" E | \n",
"
\n",
" \n",
" 10 | \n",
" 3 | \n",
" 1 | \n",
" W | \n",
"
\n",
" \n",
" 11 | \n",
" 3 | \n",
" 4 | \n",
" N | \n",
"
\n",
" \n",
" 12 | \n",
" 3 | \n",
" 4 | \n",
" S | \n",
"
\n",
" \n",
" 13 | \n",
" 4 | \n",
" 2 | \n",
" E | \n",
"
\n",
" \n",
" 14 | \n",
" 4 | \n",
" 2 | \n",
" W | \n",
"
\n",
" \n",
" 15 | \n",
" 4 | \n",
" 3 | \n",
" N | \n",
"
\n",
" \n",
" 16 | \n",
" 4 | \n",
" 3 | \n",
" S | \n",
"
\n",
" \n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 3 | \n",
" 5 | \n",
" N | \n",
"
\n",
" \n",
" 2 | \n",
" 4 | \n",
" 5 | \n",
" E | \n",
"
\n",
" \n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 1 | \n",
" 5 | \n",
" N | \n",
"
\n",
" \n",
" 2 | \n",
" 2 | \n",
" 5 | \n",
" N | \n",
"
\n",
" \n",
"
\n",
"
\n"
],
"text/plain": [
"LV′ {V:4, E:16, Sheep:2, Wolf:2, Dir:0, Eng:0, Coord:0}\n",
"┌───┬───────────┬────────┐\n",
"│\u001b[1m V \u001b[0m│\u001b[1m grass_eng \u001b[0m│\u001b[1m coord \u001b[0m│\n",
"├───┼───────────┼────────┤\n",
"│\u001b[1m 1 \u001b[0m│ 1 │ (0, 0) │\n",
"│\u001b[1m 2 \u001b[0m│ 15 │ (0, 1) │\n",
"│\u001b[1m 3 \u001b[0m│ 22 │ (1, 0) │\n",
"│\u001b[1m 4 \u001b[0m│ 0 │ (1, 1) │\n",
"└───┴───────────┴────────┘\n",
"┌────┬─────┬─────┬─────┐\n",
"│\u001b[1m E \u001b[0m│\u001b[1m src \u001b[0m│\u001b[1m tgt \u001b[0m│\u001b[1m dir \u001b[0m│\n",
"├────┼─────┼─────┼─────┤\n",
"│\u001b[1m 1 \u001b[0m│ 1 │ 3 │ E │\n",
"│\u001b[1m 2 \u001b[0m│ 1 │ 3 │ W │\n",
"│\u001b[1m 3 \u001b[0m│ 1 │ 2 │ N │\n",
"│\u001b[1m 4 \u001b[0m│ 1 │ 2 │ S │\n",
"│\u001b[1m 5 \u001b[0m│ 2 │ 4 │ E │\n",
"│\u001b[1m 6 \u001b[0m│ 2 │ 4 │ W │\n",
"│\u001b[1m 7 \u001b[0m│ 2 │ 1 │ N │\n",
"│\u001b[1m 8 \u001b[0m│ 2 │ 1 │ S │\n",
"│\u001b[1m 9 \u001b[0m│ 3 │ 1 │ E │\n",
"│\u001b[1m 10 \u001b[0m│ 3 │ 1 │ W │\n",
"│\u001b[1m 11 \u001b[0m│ 3 │ 4 │ N │\n",
"│\u001b[1m 12 \u001b[0m│ 3 │ 4 │ S │\n",
"│\u001b[1m 13 \u001b[0m│ 4 │ 2 │ E │\n",
"│\u001b[1m 14 \u001b[0m│ 4 │ 2 │ W │\n",
"│\u001b[1m 15 \u001b[0m│ 4 │ 3 │ N │\n",
"│\u001b[1m 16 \u001b[0m│ 4 │ 3 │ S │\n",
"└────┴─────┴─────┴─────┘\n",
"┌───────┬───────────┬───────────┬───────────┐\n",
"│\u001b[1m Sheep \u001b[0m│\u001b[1m sheep_loc \u001b[0m│\u001b[1m sheep_eng \u001b[0m│\u001b[1m sheep_dir \u001b[0m│\n",
"├───────┼───────────┼───────────┼───────────┤\n",
"│\u001b[1m 1 \u001b[0m│ 3 │ 5 │ N │\n",
"│\u001b[1m 2 \u001b[0m│ 4 │ 5 │ E │\n",
"└───────┴───────────┴───────────┴───────────┘\n",
"┌──────┬──────────┬──────────┬──────────┐\n",
"│\u001b[1m Wolf \u001b[0m│\u001b[1m wolf_loc \u001b[0m│\u001b[1m wolf_eng \u001b[0m│\u001b[1m wolf_dir \u001b[0m│\n",
"├──────┼──────────┼──────────┼──────────┤\n",
"│\u001b[1m 1 \u001b[0m│ 1 │ 5 │ N │\n",
"│\u001b[1m 2 \u001b[0m│ 2 │ 5 │ N │\n",
"└──────┴──────────┴──────────┴──────────┘\n"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function create_grid(n::Int)\n",
" lv = LV′()\n",
" coords = Dict()\n",
" # Initialize grass 50% green, 50% uniformly between 0-30\n",
" for i in 0:n-1\n",
" for j in 0:n-1\n",
" coords[i=>j] = add_part!(lv, :V; grass_eng=max(0,rand(-30:30)), coord=(i,j))\n",
" end\n",
" end\n",
" for i in 0:n-1\n",
" for j in 0:n-1\n",
" add_part!(lv, :E; src=coords[i=>j], tgt=coords[mod(i+1,n)=>j], dir=:E)\n",
" add_part!(lv, :E; src=coords[i=>j], tgt=coords[mod(i-1,n)=>j], dir=:W)\n",
" add_part!(lv, :E; src=coords[i=>j], tgt=coords[i=>mod(j+1,n)], dir=:N)\n",
" add_part!(lv, :E; src=coords[i=>j], tgt=coords[i=>mod(j-1,n)], dir=:S)\n",
" end\n",
" end\n",
" return lv\n",
"end\n",
"\n",
"\"\"\"\n",
"`n` is the length of the grid.\n",
"`sheep` and `wolves` are the fraction of spaces that are \n",
"populated with that animal\n",
"\"\"\"\n",
"function initialize(n::Int, sheep::Float64, wolves::Float64)::LV′\n",
" grid = create_grid(n)\n",
" args = [(sheep, :Sheep, :sheep_loc, :sheep_eng, :sheep_dir),\n",
" (wolves, :Wolf, :wolf_loc, :wolf_eng, :wolf_dir)]\n",
" for (n_, name, loc, eng, d) in args\n",
" for _ in 1:round(Int,n_*n^2)\n",
" dic = Dict([eng => 5, loc => rand(vertices(grid)),\n",
" d => rand([:N,:E,:S,:W])])\n",
" add_part!(grid, name; dic...)\n",
" end\n",
" end\n",
" return grid\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "01e93812",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
LV′ {V:4, E:16, Sheep:2, Wolf:2, Dir:0, Eng:0, Coord:0}\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 0 | \n",
" (0, 0) | \n",
"
\n",
" \n",
" 2 | \n",
" 12 | \n",
" (0, 1) | \n",
"
\n",
" \n",
" 3 | \n",
" 0 | \n",
" (1, 0) | \n",
"
\n",
" \n",
" 4 | \n",
" 0 | \n",
" (1, 1) | \n",
"
\n",
" \n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 1 | \n",
" 3 | \n",
" E | \n",
"
\n",
" \n",
" 2 | \n",
" 1 | \n",
" 3 | \n",
" W | \n",
"
\n",
" \n",
" 3 | \n",
" 1 | \n",
" 2 | \n",
" N | \n",
"
\n",
" \n",
" 4 | \n",
" 1 | \n",
" 2 | \n",
" S | \n",
"
\n",
" \n",
" 5 | \n",
" 2 | \n",
" 4 | \n",
" E | \n",
"
\n",
" \n",
" 6 | \n",
" 2 | \n",
" 4 | \n",
" W | \n",
"
\n",
" \n",
" 7 | \n",
" 2 | \n",
" 1 | \n",
" N | \n",
"
\n",
" \n",
" 8 | \n",
" 2 | \n",
" 1 | \n",
" S | \n",
"
\n",
" \n",
" 9 | \n",
" 3 | \n",
" 1 | \n",
" E | \n",
"
\n",
" \n",
" 10 | \n",
" 3 | \n",
" 1 | \n",
" W | \n",
"
\n",
" \n",
" 11 | \n",
" 3 | \n",
" 4 | \n",
" N | \n",
"
\n",
" \n",
" 12 | \n",
" 3 | \n",
" 4 | \n",
" S | \n",
"
\n",
" \n",
" 13 | \n",
" 4 | \n",
" 2 | \n",
" E | \n",
"
\n",
" \n",
" 14 | \n",
" 4 | \n",
" 2 | \n",
" W | \n",
"
\n",
" \n",
" 15 | \n",
" 4 | \n",
" 3 | \n",
" N | \n",
"
\n",
" \n",
" 16 | \n",
" 4 | \n",
" 3 | \n",
" S | \n",
"
\n",
" \n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 4 | \n",
" 5 | \n",
" W | \n",
"
\n",
" \n",
" 2 | \n",
" 1 | \n",
" 5 | \n",
" N | \n",
"
\n",
" \n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 3 | \n",
" 5 | \n",
" E | \n",
"
\n",
" \n",
" 2 | \n",
" 3 | \n",
" 5 | \n",
" N | \n",
"
\n",
" \n",
"
\n",
"
\n"
],
"text/plain": [
"LV′ {V:4, E:16, Sheep:2, Wolf:2, Dir:0, Eng:0, Coord:0}\n",
"┌───┬───────────┬────────┐\n",
"│\u001b[1m V \u001b[0m│\u001b[1m grass_eng \u001b[0m│\u001b[1m coord \u001b[0m│\n",
"├───┼───────────┼────────┤\n",
"│\u001b[1m 1 \u001b[0m│ 0 │ (0, 0) │\n",
"│\u001b[1m 2 \u001b[0m│ 12 │ (0, 1) │\n",
"│\u001b[1m 3 \u001b[0m│ 0 │ (1, 0) │\n",
"│\u001b[1m 4 \u001b[0m│ 0 │ (1, 1) │\n",
"└───┴───────────┴────────┘\n",
"┌────┬─────┬─────┬─────┐\n",
"│\u001b[1m E \u001b[0m│\u001b[1m src \u001b[0m│\u001b[1m tgt \u001b[0m│\u001b[1m dir \u001b[0m│\n",
"├────┼─────┼─────┼─────┤\n",
"│\u001b[1m 1 \u001b[0m│ 1 │ 3 │ E │\n",
"│\u001b[1m 2 \u001b[0m│ 1 │ 3 │ W │\n",
"│\u001b[1m 3 \u001b[0m│ 1 │ 2 │ N │\n",
"│\u001b[1m 4 \u001b[0m│ 1 │ 2 │ S │\n",
"│\u001b[1m 5 \u001b[0m│ 2 │ 4 │ E │\n",
"│\u001b[1m 6 \u001b[0m│ 2 │ 4 │ W │\n",
"│\u001b[1m 7 \u001b[0m│ 2 │ 1 │ N │\n",
"│\u001b[1m 8 \u001b[0m│ 2 │ 1 │ S │\n",
"│\u001b[1m 9 \u001b[0m│ 3 │ 1 │ E │\n",
"│\u001b[1m 10 \u001b[0m│ 3 │ 1 │ W │\n",
"│\u001b[1m 11 \u001b[0m│ 3 │ 4 │ N │\n",
"│\u001b[1m 12 \u001b[0m│ 3 │ 4 │ S │\n",
"│\u001b[1m 13 \u001b[0m│ 4 │ 2 │ E │\n",
"│\u001b[1m 14 \u001b[0m│ 4 │ 2 │ W │\n",
"│\u001b[1m 15 \u001b[0m│ 4 │ 3 │ N │\n",
"│\u001b[1m 16 \u001b[0m│ 4 │ 3 │ S │\n",
"└────┴─────┴─────┴─────┘\n",
"┌───────┬───────────┬───────────┬───────────┐\n",
"│\u001b[1m Sheep \u001b[0m│\u001b[1m sheep_loc \u001b[0m│\u001b[1m sheep_eng \u001b[0m│\u001b[1m sheep_dir \u001b[0m│\n",
"├───────┼───────────┼───────────┼───────────┤\n",
"│\u001b[1m 1 \u001b[0m│ 4 │ 5 │ W │\n",
"│\u001b[1m 2 \u001b[0m│ 1 │ 5 │ N │\n",
"└───────┴───────────┴───────────┴───────────┘\n",
"┌──────┬──────────┬──────────┬──────────┐\n",
"│\u001b[1m Wolf \u001b[0m│\u001b[1m wolf_loc \u001b[0m│\u001b[1m wolf_eng \u001b[0m│\u001b[1m wolf_dir \u001b[0m│\n",
"├──────┼──────────┼──────────┼──────────┤\n",
"│\u001b[1m 1 \u001b[0m│ 3 │ 5 │ E │\n",
"│\u001b[1m 2 \u001b[0m│ 3 │ 5 │ N │\n",
"└──────┴──────────┴──────────┴──────────┘\n"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X = initialize(2, 0.5,0.5)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "7f7cd0b5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"view_LV (generic function with 2 methods)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using Catlab.Graphics.Graphviz: Attributes, Statement, Node, Digraph\n",
"using Catlab.Graphics.Graphviz\n",
"\n",
"supscript_d = Dict([\n",
" '1'=>'¹', '2'=>'²', '3'=>'³', '4'=>'⁴', '5'=>'⁵','6'=>'⁶', '7'=>'⁷', '8'=>'⁸', \n",
" '9'=>'⁹', '0'=>'⁰', 'x'=>'ˣ', 'y'=>'ʸ','z'=>'ᶻ','a'=>'ᵃ','b'=>'ᵇ','c'=>'ᶜ',\n",
" 'd'=>'ᵈ'])\n",
"supscript(x::String) = join([get(supscript_d, c, c) for c in x])\n",
"\n",
"function view_LV(p::ACSetTransformation; name=\"G\", title=\"\")\n",
" if nparts(dom(p),:Wolf) == 1 \n",
" star = :Wolf=>p[:Wolf](1)\n",
" elseif nparts(dom(p),:Sheep) == 1 \n",
" star = :Sheep=>p[:Sheep](1)\n",
" elseif nparts(dom(p),:V) == 1 \n",
" star = :V=>p[:V](1)\n",
" else\n",
" star = nothing\n",
" end\n",
" view_LV(codom(p); name=name, title=title, star=star)\n",
"end \n",
"function view_LV(p::LV′; name=\"G\", title=\"\", star=nothing)\n",
" pstr = [\"$(i),$(j)!\" for (i,j) in p[:coord]]\n",
" stmts = Statement[]\n",
" for s in 1:nv(p)\n",
" st = (star == (:V=>s)) ? \"*\" : \"\"\n",
" gv = p[s, :grass_eng]\n",
" col = gv == 0 ? \"lightgreen\" : \"tan\"\n",
" push!(stmts,Node(\"v$s\", Attributes(\n",
" :label=>gv == 0 ? \"\" : string(gv)*st,\n",
" :shape=>\"circle\",\n",
" :color=> col, :pos=>pstr[s])))\n",
" end\n",
" d = Dict([:E=>(1,0),:N=>(0,1), :S=>(0,-1),:W=>(-1,0),])\n",
"\n",
" args = [(:true,:Wolf,:wolf_loc,:wolf_eng,:wolf_dir),\n",
" (false, :Sheep, :sheep_loc, :sheep_eng,:sheep_dir)]\n",
"\n",
" for (is_wolf, prt, loc, eng, dr) in args\n",
" for w in parts(p, prt)\n",
" st = (star == ((is_wolf ? :Wolf : :Sheep) => w)) ? \"*\" : \"\"\n",
" e = only(incident(p,p[w,loc], :src) ∩ incident(p,p[w,dr], :dir))\n",
" s = src(p,e)\n",
" dx, dy = d[p[e, :dir]]\n",
" (sx,sy) = p[s,:coord]\n",
"\n",
" L, R = 0.25, 0.1\n",
" wx = sx+L*dx+R*rand()\n",
" wy = sy+L*dy+R*rand()\n",
" ID = \"$(is_wolf ? :w : :s)$w\"\n",
" append!(stmts,[Node(ID, Attributes(\n",
" :label=>\"$w\"*supscript(\"$(p[w,eng])\")*st,\n",
" :shape=>\"square\", :width=>\"0.3px\", :height=>\"0.3px\", :fixedsize=>\"true\",\n",
" :pos=>\"$(wx),$(wy)!\",:color=> is_wolf ? \"red\" : \"lightblue\"))])\n",
" end\n",
" end\n",
"\n",
" g = Graphviz.Digraph(name, Statement[stmts...]; prog=\"neato\",\n",
" graph_attrs=Attributes(:label=>title, :labelloc=>\"t\"),\n",
" node_attrs=Attributes(:shape=>\"plain\", :style=>\"filled\"))\n",
" return g\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "24639e21",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"neato\", Statement[Node(\"v1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1\", :shape => \"circle\", :color => \"tan\", :pos => \"0,0!\")), Node(\"v2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"15\", :shape => \"circle\", :color => \"tan\", :pos => \"0,1!\")), Node(\"v3\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"22\", :shape => \"circle\", :color => \"tan\", :pos => \"1,0!\")), Node(\"v4\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,1!\")), Node(\"w1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.06849654266579729,0.2933390970151203!\", :color => \"red\")), Node(\"w2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.004255329021628751,1.3339814389671707!\", :color => \"red\")), Node(\"s1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.010499613794431,0.2616284602207712!\", :color => \"lightblue\")), Node(\"s2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.301572086719917,1.013784448366333!\", :color => \"lightblue\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :labelloc => \"t\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:shape => \"plain\", :style => \"filled\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}())"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"view_LV(X)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "deda5c79",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"neato\", Statement[Node(\"v1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1\", :shape => \"circle\", :color => \"tan\", :pos => \"0,0!\")), Node(\"v2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"15\", :shape => \"circle\", :color => \"tan\", :pos => \"0,1!\")), Node(\"v3\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"22\", :shape => \"circle\", :color => \"tan\", :pos => \"1,0!\")), Node(\"v4\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,1!\")), Node(\"w1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵*\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.04055871848385959,0.28953034194361493!\", :color => \"red\")), Node(\"w2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.04544456128547683,1.3352441625858422!\", :color => \"red\")), Node(\"s1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.053629505296321,0.31738803366916657!\", :color => \"lightblue\")), Node(\"s2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.2585447432953236,1.0485103191268235!\", :color => \"lightblue\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :labelloc => \"t\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:shape => \"plain\", :style => \"filled\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}())"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"const Var = AttrVar # shorthand\n",
"Base.isless(x::Var,y::Var) = x.val < y.val\n",
"\n",
"\"\"\"Visualize a LV with a distinguished focus\"\"\"\n",
"function view_LV(p::ACSetTransformation; name=\"G\", title=\"\")\n",
" if nparts(dom(p),:Wolf) == 1 \n",
" star = :Wolf=>p[:Wolf](1)\n",
" elseif nparts(dom(p),:Sheep) == 1 \n",
" star = :Sheep=>p[:Sheep](1)\n",
" elseif nparts(dom(p),:V) == 1 \n",
" star = :V=>p[:V](1)\n",
" else\n",
" star = nothing\n",
" end\n",
" view_LV(codom(p); name=name, title=title, star=star)\n",
"end\n",
"\n",
"yLV = yoneda_cache(LV); # compute representables\n",
"\n",
"# Empty agent type\n",
"I = LV()\n",
"# Generic sheep agent\n",
"S = @acset_colim yLV begin s::Sheep end\n",
"# Generic wolf agent\n",
"W = Swap(S)\n",
"# Generic grass agent\n",
"G = @acset_colim yLV begin v::V end\n",
"\n",
"N = Dict(W=>\"W\",S=>\"S\",G=>\"G\", I=>\"\") # names for visualization\n",
"\n",
"\n",
"view_LV(homomorphism(Coords(W), X)) # a distinguished wolf"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "b741afba",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"neato\", Statement[Node(\"v1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"22\", :shape => \"circle\", :color => \"tan\", :pos => \"1,0!\")), Node(\"v2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1\", :shape => \"circle\", :color => \"tan\", :pos => \"0,0!\")), Node(\"v3\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"15\", :shape => \"circle\", :color => \"tan\", :pos => \"0,1!\")), Node(\"v4\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,1!\")), Node(\"w1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.061954935908587805,0.26293927591835253!\", :color => \"red\")), Node(\"w2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.08516421807581895,1.3175968447635291!\", :color => \"red\")), Node(\"s1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.7599599619142068,0.0476178591913291!\", :color => \"lightblue\")), Node(\"s2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.2929574844314107,1.0519683238450952!\", :color => \"lightblue\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :labelloc => \"t\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:shape => \"plain\", :style => \"filled\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}())"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rl = Rule(id(S),id(S); expr=(Dir=[xs->left(only(xs))],))\n",
"rr = Rule(id(S),id(S); expr=(Dir=[xs->right(only(xs))],));\n",
"\n",
"view_LV(rewrite(Coords(rl), X)) # a sheep has rotated left"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "96436ebd",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"dot\", Statement[Subgraph(\"\", Statement[Node(\"n0in1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:id => \"in1\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:rank => \"source\", :rankdir => \"LR\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:style => \"invis\", :shape => \"none\", :label => \"\", :width => \"0.333\", :height => \"0\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:style => \"invis\")), Subgraph(\"\", Statement[Node(\"n0out1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:id => \"out1\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:rank => \"sink\", :rankdir => \"LR\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:style => \"invis\", :shape => \"none\", :label => \"\", :width => \"0.333\", :height => \"0\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:style => \"invis\")), Node(\"n1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:color => \"black\", :comment => \"turn_left\", :fillcolor => \"lightblue\", :id => \"n1\", :label => Catlab.Graphics.Graphviz.Html(\"\"), :style => \"filled\")), Edge(NodeID[NodeID(\"n0in1\", \"s\", \"\"), NodeID(\"n1\", \"in1\", \"n\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:comment => \"S\", :id => \"e1\", :label => \"S\")), Edge(NodeID[NodeID(\"n1\", \"out1\", \"s\"), NodeID(\"n0out1\", \"n\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:comment => \"S\", :id => \"e2\", :label => \"S\")), Edge(NodeID[NodeID(\"n1\", \"out2\", \"s\"), NodeID(\"n0out1\", \"n\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:comment => \"S\", :id => \"e3\", :label => \"S\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:fontname => \"Serif\", :label => \"\", :labelloc => \"t\", :rankdir => \"TB\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:fontname => \"Serif\", :shape => \"none\", :width => \"0\", :height => \"0\", :margin => \"0\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:arrowsize => \"0.5\", :fontname => \"Serif\"))"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sheep_rotate_l = tryrule(RuleApp(:turn_left, rl, S))\n",
"sheep_rotate_r = tryrule(RuleApp(:turn_right, rr, S))\n",
"\n",
"view_sched(sheep_rotate_l; names=N)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "3ffc417a",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"neato\", Statement[Node(\"v1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"22\", :shape => \"circle\", :color => \"tan\", :pos => \"0,0!\")), Node(\"v2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1\", :shape => \"circle\", :color => \"tan\", :pos => \"1,0!\")), Node(\"v3\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"15\", :shape => \"circle\", :color => \"tan\", :pos => \"0,1!\")), Node(\"v4\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,1!\")), Node(\"w1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.0338319999367087,0.2715144903507484!\", :color => \"red\")), Node(\"w2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.09955524312849022,1.2524208221537232!\", :color => \"red\")), Node(\"s1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁴\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.005154834855672,0.31898952213249837!\", :color => \"lightblue\")), Node(\"s2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.3480552534673957,1.0906437076648072!\", :color => \"lightblue\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :labelloc => \"t\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:shape => \"plain\", :style => \"filled\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}())"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s_fwd_l = @acset_colim yLV begin e::E; s::Sheep; sheep_loc(s)==src(e) end \n",
"s_fwd_i = @acset_colim yLV begin e::E end\n",
"s_fwd_r = @acset_colim yLV begin e::E; s::Sheep; sheep_loc(s)==tgt(e) end \n",
"s_n = @acset_colim yLV begin \n",
" e::E; s::Sheep; sheep_loc(s)==src(e); sheep_eng(s)==0 \n",
"end\n",
"\n",
"\n",
"sheep_fwd_rule = Rule(\n",
" homomorphism(s_fwd_i, s_fwd_l; monic=true),\n",
" homomorphism(s_fwd_i, s_fwd_r; monic=true),\n",
" ac=[AppCond(homomorphism(s_fwd_l, s_n), false)],\n",
" expr=(Eng=Dict(3=>vs->vs[3]-1), Dir=Dict(2=>vs->vs[2]))\n",
")\n",
"\n",
"sheep_fwd = tryrule(RuleApp(:move_fwd, sheep_fwd_rule, \n",
" homomorphism(S,s_fwd_l), homomorphism(S,s_fwd_r)))\n",
"\n",
"view_LV(rewrite(Coords(sheep_fwd_rule), X))"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "8b39bd6d",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"neato\", Statement[Node(\"v1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"30\", :shape => \"circle\", :color => \"tan\", :pos => \"1,1!\")), Node(\"v2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1\", :shape => \"circle\", :color => \"tan\", :pos => \"0,0!\")), Node(\"v3\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"15\", :shape => \"circle\", :color => \"tan\", :pos => \"0,1!\")), Node(\"v4\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"22\", :shape => \"circle\", :color => \"tan\", :pos => \"1,0!\")), Node(\"w1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.07036570973503435,0.3213120282469349!\", :color => \"red\")), Node(\"w2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.08407644091544102,1.263405607784062!\", :color => \"red\")), Node(\"s1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁹\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.2857788074006897,1.0433429055016346!\", :color => \"lightblue\")), Node(\"s2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.062613408317212,0.33590339061194174!\", :color => \"lightblue\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :labelloc => \"t\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:shape => \"plain\", :style => \"filled\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}())"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Eat grass + 4eng\n",
"#-----------------\n",
"# Grass is at 0 - meaning it's ready to be eaten\n",
"s_eat_pac = @acset_colim yLV begin s::Sheep; grass_eng(sheep_loc(s))==0 end\n",
"\n",
"se_rule = Rule(id(S), id(S); expr=(Eng=[vs->vs[1]+4,vs->30],), \n",
" ac=[AppCond(homomorphism(S,s_eat_pac))])\n",
"sheep_eat = tryrule(RuleApp(:Sheep_eat, se_rule, S))\n",
"sheep_eat = tryrule(RuleApp(:Sheep_eat, se_rule, S))\n",
"view_LV(rewrite(Coords(se_rule), X))"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "94b57963",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Rule{:DPO}(ACSetTransformation((V = FinFunction([1], 1, 1), E = FinFunction(Int64[], 0, 0), Sheep = FinFunction(Int64[], 0, 1), Wolf = FinFunction([1], 1, 1), Dir = VarFunction{Symbol}(FinDomFunction(Union{AttrVar, Symbol}[AttrVar(2)], FinSet(1), TypeSet(Union{AttrVar, Symbol})), FinSet(2)), Eng = VarFunction{Int64}(FinDomFunction(Union{AttrVar, Int64}[AttrVar(3), AttrVar(1)], FinSet(2), TypeSet(Union{AttrVar, Int64})), FinSet(3))), LV {V:1, E:0, Sheep:0, Wolf:1, Dir:1, Eng:2}, LV {V:1, E:0, Sheep:1, Wolf:1, Dir:2, Eng:3}), ACSetTransformation((V = id(FinSet(1)), E = id(FinSet(0)), Sheep = id(FinSet(0)), Wolf = id(FinSet(1)), Dir = VarFunction{Symbol}(FinDomFunction(Union{AttrVar, Symbol}[AttrVar(1)], FinSet(1), TypeSet(Union{AttrVar, Symbol})), FinSet(1)), Eng = VarFunction{Int64}(FinDomFunction(Union{AttrVar, Int64}[AttrVar(1), AttrVar(2)], FinSet(2), TypeSet(Union{AttrVar, Int64})), FinSet(2))), LV {V:1, E:0, Sheep:0, Wolf:1, Dir:1, Eng:2}, LV {V:1, E:0, Sheep:0, Wolf:1, Dir:1, Eng:2}), Constraint[], false, Dict{Symbol, Dict{Int64, Union{Nothing, Function}}}(:Eng => Dict(2 => var\"#47#49\"(), 1 => var\"#46#48\"()), :Dir => Dict(1 => AlgebraicRewriting.Rewrite.Utils.var\"#4#8\"{Vector{AttrVar}}(AttrVar[AttrVar(2)]))))"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w_eat_l = @acset_colim yLV begin s::Sheep; w::Wolf; sheep_loc(s)==wolf_loc(w) end\n",
"\n",
"we_rule = Rule(homomorphism(W, w_eat_l), id(W); expr=(Eng=[vs->vs[3]+20,vs->vs[1]],))"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "7107be80",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"Rule{:DPO}(ACSetTransformation((V = FinFunction([1], 1, 1), E = FinFunction(Int64[], 0, 0), Sheep = FinFunction(Int64[], 0, 1), Wolf = FinFunction([1], 1, 1), Dir = VarFunction{Symbol}(FinDomFunction(Union{AttrVar, Symbol}[AttrVar(2)], FinSet(1), TypeSet(Union{AttrVar, Symbol})), FinSet(2)), Eng = VarFunction{Int64}(FinDomFunction(Union{AttrVar, Int64}[AttrVar(3), AttrVar(1)], FinSet(2), TypeSet(Union{AttrVar, Int64})), FinSet(3)), Coord = VarFunction{Tuple{Int64, Int64}}(FinDomFunction(Union{AttrVar, Tuple{Int64, Int64}}[AttrVar(1)], FinSet(1), TypeSet(Union{AttrVar, Tuple{Int64, Int64}})), FinSet(1))), LV′ {V:1, E:0, Sheep:0, Wolf:1, Dir:1, Eng:2, Coord:1}, LV′ {V:1, E:0, Sheep:1, Wolf:1, Dir:2, Eng:3, Coord:1}), ACSetTransformation((V = FinFunction([1], 1, 1), E = FinFunction(Int64[], 0, 0), Sheep = FinFunction(Int64[], 0, 0), Wolf = FinFunction([1], 1, 1), Dir = VarFunction{Symbol}(FinDomFunction(Union{AttrVar, Symbol}[AttrVar(1)], FinSet(1), TypeSet(Union{AttrVar, Symbol})), FinSet(1)), Eng = VarFunction{Int64}(FinDomFunction(Union{AttrVar, Int64}[AttrVar(1), AttrVar(2)], FinSet(2), TypeSet(Union{AttrVar, Int64})), FinSet(2)), Coord = VarFunction{Tuple{Int64, Int64}}(FinDomFunction(Union{AttrVar, Tuple{Int64, Int64}}[AttrVar(1)], FinSet(1), TypeSet(Union{AttrVar, Tuple{Int64, Int64}})), FinSet(1))), LV′ {V:1, E:0, Sheep:0, Wolf:1, Dir:1, Eng:2, Coord:1}, LV′ {V:1, E:0, Sheep:0, Wolf:1, Dir:1, Eng:2, Coord:1}), Constraint[], false, Dict{Symbol, Dict{Int64, Union{Nothing, Function}}}(:Eng => Dict(2 => var\"#43#45\"(), 1 => var\"#42#44\"()), :Coord => Dict(1 => AlgebraicRewriting.Rewrite.Utils.var\"#4#8\"{Vector{AttrVar}}(AttrVar[AttrVar(1)])), :Dir => Dict(1 => AlgebraicRewriting.Rewrite.Utils.var\"#4#8\"{Vector{AttrVar}}(AttrVar[AttrVar(2)]))))"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Coords(we_rule)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "39023520",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Schedule(WiringDiagram{AlgebraicRewriting.Schedules.Theories.ThTracedMonoidalWithBidiagonals}([LV {V:1, E:0, Sheep:0, Wolf:1, Dir:1, Eng:2}], [LV {V:1, E:0, Sheep:0, Wolf:1, Dir:1, Eng:2}], \n",
"[ -2 => {inputs},\n",
" -1 => {outputs},\n",
" 1 => Box(\"Wolf_eat\", [LV:\n",
" V = 1:1\n",
" E = 1:0\n",
" Sheep = 1:0\n",
" Wolf = 1:1\n",
" Dir = 1:1\n",
" Eng = 1:2\n",
" src : E → V = Int64[]\n",
" tgt : E → V = Int64[]\n",
" sheep_loc : Sheep → V = Int64[]\n",
" wolf_loc : Wolf → V = [1]\n",
" grass_eng : V → Eng = AttrVar[AttrVar(2)]\n",
" sheep_eng : Sheep → Eng = Int64[]\n",
" wolf_eng : Wolf → Eng = AttrVar[AttrVar(1)]\n",
" sheep_dir : Sheep → Dir = Symbol[]\n",
" wolf_dir : Wolf → Dir = AttrVar[AttrVar(1)]\n",
" dir : E → Dir = Symbol[]], [LV:\n",
" V = 1:1\n",
" E = 1:0\n",
" Sheep = 1:0\n",
" Wolf = 1:1\n",
" Dir = 1:1\n",
" Eng = 1:2\n",
" src : E → V = Int64[]\n",
" tgt : E → V = Int64[]\n",
" sheep_loc : Sheep → V = Int64[]\n",
" wolf_loc : Wolf → V = [1]\n",
" grass_eng : V → Eng = AttrVar[AttrVar(2)]\n",
" sheep_eng : Sheep → Eng = Int64[]\n",
" wolf_eng : Wolf → Eng = AttrVar[AttrVar(1)]\n",
" sheep_dir : Sheep → Dir = Symbol[]\n",
" wolf_dir : Wolf → Dir = AttrVar[AttrVar(1)]\n",
" dir : E → Dir = Symbol[],LV:\n",
" V = 1:1\n",
" E = 1:0\n",
" Sheep = 1:0\n",
" Wolf = 1:1\n",
" Dir = 1:1\n",
" Eng = 1:2\n",
" src : E → V = Int64[]\n",
" tgt : E → V = Int64[]\n",
" sheep_loc : Sheep → V = Int64[]\n",
" wolf_loc : Wolf → V = [1]\n",
" grass_eng : V → Eng = AttrVar[AttrVar(2)]\n",
" sheep_eng : Sheep → Eng = Int64[]\n",
" wolf_eng : Wolf → Eng = AttrVar[AttrVar(1)]\n",
" sheep_dir : Sheep → Dir = Symbol[]\n",
" wolf_dir : Wolf → Dir = AttrVar[AttrVar(1)]\n",
" dir : E → Dir = Symbol[]]) ],\n",
"[ Wire((-2,1) => (1,1)),\n",
" Wire((1,1) => (-1,1)),\n",
" Wire((1,2) => (-1,1)) ]), compose(Wolf_eat,mmerge(LV:\n",
" V = 1:1\n",
" E = 1:0\n",
" Sheep = 1:0\n",
" Wolf = 1:1\n",
" Dir = 1:1\n",
" Eng = 1:2\n",
" src : E → V = Int64[]\n",
" tgt : E → V = Int64[]\n",
" sheep_loc : Sheep → V = Int64[]\n",
" wolf_loc : Wolf → V = [1]\n",
" grass_eng : V → Eng = AttrVar[AttrVar(2)]\n",
" sheep_eng : Sheep → Eng = Int64[]\n",
" wolf_eng : Wolf → Eng = AttrVar[AttrVar(1)]\n",
" sheep_dir : Sheep → Dir = Symbol[]\n",
" wolf_dir : Wolf → Dir = AttrVar[AttrVar(1)]\n",
" dir : E → Dir = Symbol[])))"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"wolf_eat = tryrule(RuleApp(:Wolf_eat, we_rule, W))"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "4d4f1add",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"dot\", Statement[Subgraph(\"\", Statement[Node(\"n0in1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:id => \"in1\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:rank => \"source\", :rankdir => \"LR\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:style => \"invis\", :shape => \"none\", :label => \"\", :width => \"0.333\", :height => \"0\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:style => \"invis\")), Subgraph(\"\", Statement[Node(\"n0out1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:id => \"out1\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:rank => \"sink\", :rankdir => \"LR\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:style => \"invis\", :shape => \"none\", :label => \"\", :width => \"0.333\", :height => \"0\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:style => \"invis\")), Node(\"n1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:color => \"black\", :comment => \"Wolf_eat\", :fillcolor => \"lightblue\", :id => \"n1\", :label => Catlab.Graphics.Graphviz.Html(\"\"), :style => \"filled\")), Edge(NodeID[NodeID(\"n0in1\", \"s\", \"\"), NodeID(\"n1\", \"in1\", \"n\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:comment => \"W\", :id => \"e1\", :label => \"W\")), Edge(NodeID[NodeID(\"n1\", \"out1\", \"s\"), NodeID(\"n0out1\", \"n\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:comment => \"W\", :id => \"e2\", :label => \"W\")), Edge(NodeID[NodeID(\"n1\", \"out2\", \"s\"), NodeID(\"n0out1\", \"n\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:comment => \"W\", :id => \"e3\", :label => \"W\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:fontname => \"Serif\", :label => \"\", :labelloc => \"t\", :rankdir => \"TB\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:fontname => \"Serif\", :shape => \"none\", :width => \"0\", :height => \"0\", :margin => \"0\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:arrowsize => \"0.5\", :fontname => \"Serif\"))"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"view_sched(wolf_eat; names=N)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "e42a7506",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X[1,:wolf_loc]"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "80f9c4b7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"LV′\u001b[90m (alias for \u001b[39m\u001b[90mLV′_Generic{Symbol, Int64, Tuple{Int64, Int64}}\u001b[39m\u001b[90m)\u001b[39m"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"typeof(X)"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "4bbdb373",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
LV′ {V:4, E:16, Sheep:2, Wolf:2, Dir:0, Eng:0, Coord:0}\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 0 | \n",
" (0, 0) | \n",
"
\n",
" \n",
" 2 | \n",
" 12 | \n",
" (0, 1) | \n",
"
\n",
" \n",
" 3 | \n",
" 0 | \n",
" (1, 0) | \n",
"
\n",
" \n",
" 4 | \n",
" 0 | \n",
" (1, 1) | \n",
"
\n",
" \n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 1 | \n",
" 3 | \n",
" E | \n",
"
\n",
" \n",
" 2 | \n",
" 1 | \n",
" 3 | \n",
" W | \n",
"
\n",
" \n",
" 3 | \n",
" 1 | \n",
" 2 | \n",
" N | \n",
"
\n",
" \n",
" 4 | \n",
" 1 | \n",
" 2 | \n",
" S | \n",
"
\n",
" \n",
" 5 | \n",
" 2 | \n",
" 4 | \n",
" E | \n",
"
\n",
" \n",
" 6 | \n",
" 2 | \n",
" 4 | \n",
" W | \n",
"
\n",
" \n",
" 7 | \n",
" 2 | \n",
" 1 | \n",
" N | \n",
"
\n",
" \n",
" 8 | \n",
" 2 | \n",
" 1 | \n",
" S | \n",
"
\n",
" \n",
" 9 | \n",
" 3 | \n",
" 1 | \n",
" E | \n",
"
\n",
" \n",
" 10 | \n",
" 3 | \n",
" 1 | \n",
" W | \n",
"
\n",
" \n",
" 11 | \n",
" 3 | \n",
" 4 | \n",
" N | \n",
"
\n",
" \n",
" 12 | \n",
" 3 | \n",
" 4 | \n",
" S | \n",
"
\n",
" \n",
" 13 | \n",
" 4 | \n",
" 2 | \n",
" E | \n",
"
\n",
" \n",
" 14 | \n",
" 4 | \n",
" 2 | \n",
" W | \n",
"
\n",
" \n",
" 15 | \n",
" 4 | \n",
" 3 | \n",
" N | \n",
"
\n",
" \n",
" 16 | \n",
" 4 | \n",
" 3 | \n",
" S | \n",
"
\n",
" \n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 4 | \n",
" 5 | \n",
" W | \n",
"
\n",
" \n",
" 2 | \n",
" 1 | \n",
" 5 | \n",
" N | \n",
"
\n",
" \n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 2 | \n",
" 5 | \n",
" E | \n",
"
\n",
" \n",
" 2 | \n",
" 3 | \n",
" 5 | \n",
" N | \n",
"
\n",
" \n",
"
\n",
"
\n"
],
"text/plain": [
"LV′ {V:4, E:16, Sheep:2, Wolf:2, Dir:0, Eng:0, Coord:0}\n",
"┌───┬───────────┬────────┐\n",
"│\u001b[1m V \u001b[0m│\u001b[1m grass_eng \u001b[0m│\u001b[1m coord \u001b[0m│\n",
"├───┼───────────┼────────┤\n",
"│\u001b[1m 1 \u001b[0m│ 0 │ (0, 0) │\n",
"│\u001b[1m 2 \u001b[0m│ 12 │ (0, 1) │\n",
"│\u001b[1m 3 \u001b[0m│ 0 │ (1, 0) │\n",
"│\u001b[1m 4 \u001b[0m│ 0 │ (1, 1) │\n",
"└───┴───────────┴────────┘\n",
"┌────┬─────┬─────┬─────┐\n",
"│\u001b[1m E \u001b[0m│\u001b[1m src \u001b[0m│\u001b[1m tgt \u001b[0m│\u001b[1m dir \u001b[0m│\n",
"├────┼─────┼─────┼─────┤\n",
"│\u001b[1m 1 \u001b[0m│ 1 │ 3 │ E │\n",
"│\u001b[1m 2 \u001b[0m│ 1 │ 3 │ W │\n",
"│\u001b[1m 3 \u001b[0m│ 1 │ 2 │ N │\n",
"│\u001b[1m 4 \u001b[0m│ 1 │ 2 │ S │\n",
"│\u001b[1m 5 \u001b[0m│ 2 │ 4 │ E │\n",
"│\u001b[1m 6 \u001b[0m│ 2 │ 4 │ W │\n",
"│\u001b[1m 7 \u001b[0m│ 2 │ 1 │ N │\n",
"│\u001b[1m 8 \u001b[0m│ 2 │ 1 │ S │\n",
"│\u001b[1m 9 \u001b[0m│ 3 │ 1 │ E │\n",
"│\u001b[1m 10 \u001b[0m│ 3 │ 1 │ W │\n",
"│\u001b[1m 11 \u001b[0m│ 3 │ 4 │ N │\n",
"│\u001b[1m 12 \u001b[0m│ 3 │ 4 │ S │\n",
"│\u001b[1m 13 \u001b[0m│ 4 │ 2 │ E │\n",
"│\u001b[1m 14 \u001b[0m│ 4 │ 2 │ W │\n",
"│\u001b[1m 15 \u001b[0m│ 4 │ 3 │ N │\n",
"│\u001b[1m 16 \u001b[0m│ 4 │ 3 │ S │\n",
"└────┴─────┴─────┴─────┘\n",
"┌───────┬───────────┬───────────┬───────────┐\n",
"│\u001b[1m Sheep \u001b[0m│\u001b[1m sheep_loc \u001b[0m│\u001b[1m sheep_eng \u001b[0m│\u001b[1m sheep_dir \u001b[0m│\n",
"├───────┼───────────┼───────────┼───────────┤\n",
"│\u001b[1m 1 \u001b[0m│ 4 │ 5 │ W │\n",
"│\u001b[1m 2 \u001b[0m│ 1 │ 5 │ N │\n",
"└───────┴───────────┴───────────┴───────────┘\n",
"┌──────┬──────────┬──────────┬──────────┐\n",
"│\u001b[1m Wolf \u001b[0m│\u001b[1m wolf_loc \u001b[0m│\u001b[1m wolf_eng \u001b[0m│\u001b[1m wolf_dir \u001b[0m│\n",
"├──────┼──────────┼──────────┼──────────┤\n",
"│\u001b[1m 1 \u001b[0m│ 2 │ 5 │ E │\n",
"│\u001b[1m 2 \u001b[0m│ 3 │ 5 │ N │\n",
"└──────┴──────────┴──────────┴──────────┘\n"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bf0d9b47",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 34,
"id": "63ffb56c",
"metadata": {
"scrolled": true
},
"outputs": [
{
"ename": "LoadError",
"evalue": "MethodError: no method matching view_LV(::Nothing)\n\n\u001b[0mClosest candidates are:\n\u001b[0m view_LV(\u001b[91m::ACSetTransformation\u001b[39m; name, title)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[35mMain\u001b[39m \u001b[90m\u001b[4mIn[18]:5\u001b[24m\u001b[39m\n\u001b[0m view_LV(\u001b[91m::LV′\u001b[39m; name, title, star)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[35mMain\u001b[39m \u001b[90m\u001b[4mIn[15]:22\u001b[24m\u001b[39m\n",
"output_type": "error",
"traceback": [
"MethodError: no method matching view_LV(::Nothing)\n\n\u001b[0mClosest candidates are:\n\u001b[0m view_LV(\u001b[91m::ACSetTransformation\u001b[39m; name, title)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[35mMain\u001b[39m \u001b[90m\u001b[4mIn[18]:5\u001b[24m\u001b[39m\n\u001b[0m view_LV(\u001b[91m::LV′\u001b[39m; name, title, star)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[35mMain\u001b[39m \u001b[90m\u001b[4mIn[15]:22\u001b[24m\u001b[39m\n",
"",
"Stacktrace:",
" [1] top-level scope",
" @ In[34]:7"
]
}
],
"source": [
"# note that the below fails even if only one of the following \"wolf_eat\" invocations is included\n",
"wolf_eat = tryrule(RuleApp(:Wolf_eat, we_rule, W))\n",
"\n",
"wolf_eat = tryrule(RuleApp(:Wolf_eat, we_rule, W))\n",
" \n",
"X[1,:wolf_loc] = 2 # put the wolf with the sheep -- NB: *** NDO found that the sheep are not at this location, and the code breaks accordingly.\n",
"view_LV(rewrite(Coords(we_rule), X))"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "b8f4d8e3",
"metadata": {},
"outputs": [],
"source": [
"# this confirms the source of the problem being that the rewrite rule returns you\n",
"rewrite(Coords(we_rule), X)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "dfb2a876",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"neato\", Statement[Node(\"v1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,1!\")), Node(\"v2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"0,0!\")), Node(\"v3\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"12\", :shape => \"circle\", :color => \"tan\", :pos => \"0,1!\")), Node(\"v4\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,0!\")), Node(\"w1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1²⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.283445016120271,1.0581242738758512!\", :color => \"red\")), Node(\"w2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.0983001575535452,0.2648596336526238!\", :color => \"red\")), Node(\"s1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.013943393323564847,0.33367715730613945!\", :color => \"lightblue\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :labelloc => \"t\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:shape => \"plain\", :style => \"filled\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}())"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#trying the below with the CORRECT location for the sheep\n",
"X[1,:wolf_loc] = 4 # put the wolf with the sheep\n",
"view_LV(rewrite(Coords(we_rule), X))"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "d2e8b690",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
LV′ {V:4, E:16, Sheep:2, Wolf:2, Dir:0, Eng:0, Coord:0}\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 0 | \n",
" (0, 0) | \n",
"
\n",
" \n",
" 2 | \n",
" 12 | \n",
" (0, 1) | \n",
"
\n",
" \n",
" 3 | \n",
" 0 | \n",
" (1, 0) | \n",
"
\n",
" \n",
" 4 | \n",
" 0 | \n",
" (1, 1) | \n",
"
\n",
" \n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 1 | \n",
" 3 | \n",
" E | \n",
"
\n",
" \n",
" 2 | \n",
" 1 | \n",
" 3 | \n",
" W | \n",
"
\n",
" \n",
" 3 | \n",
" 1 | \n",
" 2 | \n",
" N | \n",
"
\n",
" \n",
" 4 | \n",
" 1 | \n",
" 2 | \n",
" S | \n",
"
\n",
" \n",
" 5 | \n",
" 2 | \n",
" 4 | \n",
" E | \n",
"
\n",
" \n",
" 6 | \n",
" 2 | \n",
" 4 | \n",
" W | \n",
"
\n",
" \n",
" 7 | \n",
" 2 | \n",
" 1 | \n",
" N | \n",
"
\n",
" \n",
" 8 | \n",
" 2 | \n",
" 1 | \n",
" S | \n",
"
\n",
" \n",
" 9 | \n",
" 3 | \n",
" 1 | \n",
" E | \n",
"
\n",
" \n",
" 10 | \n",
" 3 | \n",
" 1 | \n",
" W | \n",
"
\n",
" \n",
" 11 | \n",
" 3 | \n",
" 4 | \n",
" N | \n",
"
\n",
" \n",
" 12 | \n",
" 3 | \n",
" 4 | \n",
" S | \n",
"
\n",
" \n",
" 13 | \n",
" 4 | \n",
" 2 | \n",
" E | \n",
"
\n",
" \n",
" 14 | \n",
" 4 | \n",
" 2 | \n",
" W | \n",
"
\n",
" \n",
" 15 | \n",
" 4 | \n",
" 3 | \n",
" N | \n",
"
\n",
" \n",
" 16 | \n",
" 4 | \n",
" 3 | \n",
" S | \n",
"
\n",
" \n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 4 | \n",
" 5 | \n",
" W | \n",
"
\n",
" \n",
" 2 | \n",
" 1 | \n",
" 5 | \n",
" N | \n",
"
\n",
" \n",
"
\n",
"
\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 1 | \n",
" 4 | \n",
" 5 | \n",
" E | \n",
"
\n",
" \n",
" 2 | \n",
" 3 | \n",
" 5 | \n",
" N | \n",
"
\n",
" \n",
"
\n",
"
\n"
],
"text/plain": [
"LV′ {V:4, E:16, Sheep:2, Wolf:2, Dir:0, Eng:0, Coord:0}\n",
"┌───┬───────────┬────────┐\n",
"│\u001b[1m V \u001b[0m│\u001b[1m grass_eng \u001b[0m│\u001b[1m coord \u001b[0m│\n",
"├───┼───────────┼────────┤\n",
"│\u001b[1m 1 \u001b[0m│ 0 │ (0, 0) │\n",
"│\u001b[1m 2 \u001b[0m│ 12 │ (0, 1) │\n",
"│\u001b[1m 3 \u001b[0m│ 0 │ (1, 0) │\n",
"│\u001b[1m 4 \u001b[0m│ 0 │ (1, 1) │\n",
"└───┴───────────┴────────┘\n",
"┌────┬─────┬─────┬─────┐\n",
"│\u001b[1m E \u001b[0m│\u001b[1m src \u001b[0m│\u001b[1m tgt \u001b[0m│\u001b[1m dir \u001b[0m│\n",
"├────┼─────┼─────┼─────┤\n",
"│\u001b[1m 1 \u001b[0m│ 1 │ 3 │ E │\n",
"│\u001b[1m 2 \u001b[0m│ 1 │ 3 │ W │\n",
"│\u001b[1m 3 \u001b[0m│ 1 │ 2 │ N │\n",
"│\u001b[1m 4 \u001b[0m│ 1 │ 2 │ S │\n",
"│\u001b[1m 5 \u001b[0m│ 2 │ 4 │ E │\n",
"│\u001b[1m 6 \u001b[0m│ 2 │ 4 │ W │\n",
"│\u001b[1m 7 \u001b[0m│ 2 │ 1 │ N │\n",
"│\u001b[1m 8 \u001b[0m│ 2 │ 1 │ S │\n",
"│\u001b[1m 9 \u001b[0m│ 3 │ 1 │ E │\n",
"│\u001b[1m 10 \u001b[0m│ 3 │ 1 │ W │\n",
"│\u001b[1m 11 \u001b[0m│ 3 │ 4 │ N │\n",
"│\u001b[1m 12 \u001b[0m│ 3 │ 4 │ S │\n",
"│\u001b[1m 13 \u001b[0m│ 4 │ 2 │ E │\n",
"│\u001b[1m 14 \u001b[0m│ 4 │ 2 │ W │\n",
"│\u001b[1m 15 \u001b[0m│ 4 │ 3 │ N │\n",
"│\u001b[1m 16 \u001b[0m│ 4 │ 3 │ S │\n",
"└────┴─────┴─────┴─────┘\n",
"┌───────┬───────────┬───────────┬───────────┐\n",
"│\u001b[1m Sheep \u001b[0m│\u001b[1m sheep_loc \u001b[0m│\u001b[1m sheep_eng \u001b[0m│\u001b[1m sheep_dir \u001b[0m│\n",
"├───────┼───────────┼───────────┼───────────┤\n",
"│\u001b[1m 1 \u001b[0m│ 4 │ 5 │ W │\n",
"│\u001b[1m 2 \u001b[0m│ 1 │ 5 │ N │\n",
"└───────┴───────────┴───────────┴───────────┘\n",
"┌──────┬──────────┬──────────┬──────────┐\n",
"│\u001b[1m Wolf \u001b[0m│\u001b[1m wolf_loc \u001b[0m│\u001b[1m wolf_eng \u001b[0m│\u001b[1m wolf_dir \u001b[0m│\n",
"├──────┼──────────┼──────────┼──────────┤\n",
"│\u001b[1m 1 \u001b[0m│ 4 │ 5 │ E │\n",
"│\u001b[1m 2 \u001b[0m│ 3 │ 5 │ N │\n",
"└──────┴──────────┴──────────┴──────────┘\n"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "097830c2",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"neato\", Statement[Node(\"v1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,1!\")), Node(\"v2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"0,0!\")), Node(\"v3\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"12\", :shape => \"circle\", :color => \"tan\", :pos => \"0,1!\")), Node(\"v4\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,0!\")), Node(\"w1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1²⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.324491275926018,1.0622545939098518!\", :color => \"red\")), Node(\"w2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.0053740348101448,0.2549293997928652!\", :color => \"red\")), Node(\"s1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.061434857578459526,0.29033497733613584!\", :color => \"lightblue\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :labelloc => \"t\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:shape => \"plain\", :style => \"filled\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}())"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# note that the below fails even if only one of the following \"wolf_eat\" invocations is included\n",
"wolf_eat = tryrule(RuleApp(:Wolf_eat, we_rule, W))\n",
"\n",
"wolf_eat = tryrule(RuleApp(:Wolf_eat, we_rule, W))\n",
" \n",
"X[1,:wolf_loc] = 4 # put the wolf with the sheep\n",
"view_LV(rewrite(Coords(we_rule), X))"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "6c5509c5",
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"neato\", Statement[Node(\"v1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,1!\")), Node(\"v2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"0,0!\")), Node(\"v3\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"12\", :shape => \"circle\", :color => \"tan\", :pos => \"0,1!\")), Node(\"v4\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,0!\")), Node(\"w1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1²⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.2714212056247363,1.0858190750096561!\", :color => \"red\")), Node(\"w2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.0518431565424968,0.30839782681250255!\", :color => \"red\")), Node(\"s1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.09695290621242357,0.2975733146081277!\", :color => \"lightblue\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :labelloc => \"t\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:shape => \"plain\", :style => \"filled\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}())"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# note that the below fails even if only one of the following \"wolf_eat\" invocations is included\n",
"wolf_eat = tryrule(RuleApp(:Wolf_eat, we_rule, W))\n",
"\n",
"X[1,:wolf_loc] = 4 # put the wolf with the sheep (correct address) \n",
"view_LV(rewrite(Coords(we_rule), X))"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "7816974b",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"dot\", Statement[Subgraph(\"\", Statement[Node(\"n0in1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:id => \"in1\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:rank => \"source\", :rankdir => \"LR\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:style => \"invis\", :shape => \"none\", :label => \"\", :width => \"0.333\", :height => \"0\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:style => \"invis\")), Subgraph(\"\", Statement[Node(\"n0out1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:id => \"out1\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:rank => \"sink\", :rankdir => \"LR\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:style => \"invis\", :shape => \"none\", :label => \"\", :width => \"0.333\", :height => \"0\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:style => \"invis\")), Node(\"n1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:color => \"black\", :comment => \"starve\", :fillcolor => \"lightblue\", :id => \"n1\", :label => Catlab.Graphics.Graphviz.Html(\"\"), :style => \"filled\")), Node(\"n2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:color => \"black\", :comment => \"\", :fillcolor => \"lavender\", :id => \"n2\", :label => Catlab.Graphics.Graphviz.Html(\"\"), :style => \"filled\")), Edge(NodeID[NodeID(\"n0in1\", \"s\", \"\"), NodeID(\"n1\", \"in1\", \"n\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:comment => \"S\", :id => \"e1\", :label => \"S\")), Edge(NodeID[NodeID(\"n1\", \"out2\", \"s\"), NodeID(\"n2\", \"in1\", \"n\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:comment => \"S\", :id => \"e2\", :label => \"S\")), Edge(NodeID[NodeID(\"n1\", \"out1\", \"s\"), NodeID(\"n0out1\", \"n\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:comment => \"\", :id => \"e3\", :label => \"\")), Edge(NodeID[NodeID(\"n2\", \"out1\", \"s\"), NodeID(\"n0out1\", \"n\", \"\")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:comment => \"\", :id => \"e4\", :label => \"\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:fontname => \"Serif\", :label => \"\", :labelloc => \"t\", :rankdir => \"TB\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:fontname => \"Serif\", :shape => \"none\", :width => \"0\", :height => \"0\", :margin => \"0\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:arrowsize => \"0.5\", :fontname => \"Serif\"))"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Die if 0 eng\n",
"#-------------\n",
"s_die_l = @acset_colim yLV begin s::Sheep; sheep_eng(s)==0 end \n",
"\n",
"sheep_die_rule = Rule(homomorphism(G, s_die_l), id(G))\n",
"sheep_starve = (RuleApp(:starve, sheep_die_rule, \n",
" homomorphism(S,s_die_l), create(G))\n",
" ⋅ (id([I]) ⊗ Weaken(create(S))) ⋅ merge_wires(I))\n",
"\n",
"view_sched(sheep_starve; names=N)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "63cc3404",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"neato\", Statement[Node(\"v1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,1!\")), Node(\"v2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"0,0!\")), Node(\"v3\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"12\", :shape => \"circle\", :color => \"tan\", :pos => \"0,1!\")), Node(\"v4\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,0!\")), Node(\"w1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.281947788490046,1.0659916916178562!\", :color => \"red\")), Node(\"w2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.0948080890756835,0.33458180827351286!\", :color => \"red\")), Node(\"s1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1³\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.7702198866699627,1.0507109586669932!\", :color => \"lightblue\")), Node(\"s2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2³\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.8226164017440437,1.0944824655265233!\", :color => \"lightblue\")), Node(\"s3\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"3⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.01551824146469032,0.32001903312470475!\", :color => \"lightblue\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :labelloc => \"t\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:shape => \"plain\", :style => \"filled\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}())"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s_reprod_r = @acset_colim yLV begin (x,y)::Sheep; sheep_loc(x)==sheep_loc(y) end\n",
"\n",
"sheep_reprod_rule = Rule(\n",
" homomorphism(G, S),\n",
" homomorphism(G, s_reprod_r); \n",
" expr=(Dir=[vs->vs[1],vs->vs[1]], Eng=[vs->vs[2], \n",
" fill(vs->round(Int, vs[1]/2, RoundUp), 2)...],)\n",
" )\n",
"\n",
"\n",
"sheep_reprod = RuleApp(:reproduce, sheep_reprod_rule, \n",
" id(S), homomorphism(S, s_reprod_r)) |> tryrule\n",
"\n",
"view_LV(rewrite(Coords(sheep_reprod_rule), X))\n"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "215677dd",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"Catlab.Graphics.Graphviz.Graph(\"G\", true, \"neato\", Statement[Node(\"v1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"11\", :shape => \"circle\", :color => \"tan\", :pos => \"0,1!\")), Node(\"v2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"0,0!\")), Node(\"v3\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,0!\")), Node(\"v4\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :shape => \"circle\", :color => \"lightgreen\", :pos => \"1,1!\")), Node(\"w1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.257235291686873,1.0522285128192137!\", :color => \"red\")), Node(\"w2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"1.0021286008315382,0.27952073275749506!\", :color => \"red\")), Node(\"s1\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"1⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.7916706192984608,1.0652711855236812!\", :color => \"lightblue\")), Node(\"s2\", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"2⁵\", :shape => \"square\", :width => \"0.3px\", :height => \"0.3px\", :fixedsize => \"true\", :pos => \"0.023232632932794553,0.32032924351948766!\", :color => \"lightblue\"))], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => \"\", :labelloc => \"t\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:shape => \"plain\", :style => \"filled\"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}())"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"g_inc_n = deepcopy(G)\n",
"set_subpart!(g_inc_n,1, :grass_eng, 0); \n",
"rem_part!(g_inc_n, :Eng, 1)\n",
"\n",
"g_inc_rule = Rule(id(G), id(G);\n",
" ac=[AppCond(homomorphism(G, g_inc_n), false)],\n",
" expr=(Eng=[vs->only(vs)-1],))\n",
"g_inc = RuleApp(:GrassIncrements,g_inc_rule, G) |> tryrule\n",
"\n",
"view_LV(rewrite(Coords(g_inc_rule), X))"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "c1147bdb",
"metadata": {},
"outputs": [
{
"ename": "LoadError",
"evalue": "MethodError: no method matching mk_sched(::NamedTuple{(), Tuple{}}, ::NamedTuple{(:init,), Tuple{Symbol}}, ::NamedTuple{(:S, :I, :G, :turn, :maybe, :lft, :rght, :fwd, :repro, :starve), Tuple{LV, LV, LV, Conditional, Conditional, Vararg{Schedule, 5}}}, ::Expr)\n\n\u001b[0mClosest candidates are:\n\u001b[0m mk_sched(::NamedTuple, ::NamedTuple, \u001b[91m::Names\u001b[39m, \u001b[91m::Union{AbstractDict, NamedTuple}\u001b[39m, \u001b[91m::Expr\u001b[39m)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[36mAlgebraicRewriting\u001b[39m \u001b[90m~/.julia/packages/AlgebraicRewriting/S1Bfw/src/schedules/\u001b[39m\u001b[90m\u001b[4mWiring.jl:52\u001b[24m\u001b[39m\n",
"output_type": "error",
"traceback": [
"MethodError: no method matching mk_sched(::NamedTuple{(), Tuple{}}, ::NamedTuple{(:init,), Tuple{Symbol}}, ::NamedTuple{(:S, :I, :G, :turn, :maybe, :lft, :rght, :fwd, :repro, :starve), Tuple{LV, LV, LV, Conditional, Conditional, Vararg{Schedule, 5}}}, ::Expr)\n\n\u001b[0mClosest candidates are:\n\u001b[0m mk_sched(::NamedTuple, ::NamedTuple, \u001b[91m::Names\u001b[39m, \u001b[91m::Union{AbstractDict, NamedTuple}\u001b[39m, \u001b[91m::Expr\u001b[39m)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[36mAlgebraicRewriting\u001b[39m \u001b[90m~/.julia/packages/AlgebraicRewriting/S1Bfw/src/schedules/\u001b[39m\u001b[90m\u001b[4mWiring.jl:52\u001b[24m\u001b[39m\n",
"",
"Stacktrace:",
" [1] top-level scope",
" @ In[47]:6"
]
}
],
"source": [
"# Stuff that happens once per sheep \n",
"#----------------------------------\n",
"\n",
"# 25% chance of left turn, 25% chance of right turn, 50% stay in same direction\n",
"# 50% chance of reproducing\n",
"general = mk_sched((;),(init=:S,), (\n",
" S = S, I = I, G = G,\n",
" turn = const_cond([1.,2.,1.], S; name=:turn), \n",
" maybe = uniform(2, S), \n",
" lft = sheep_rotate_l, \n",
" rght = sheep_rotate_r, \n",
" fwd = sheep_fwd, \n",
" repro = sheep_reprod, \n",
" starve = sheep_starve), \n",
" quote \n",
" out_l, out_str, out_r = turn(init)\n",
" moved = fwd([lft(out_l), out_str, rght(out_r)]) \n",
" out_repro, out_no_repro = maybe(moved)\n",
" return starve([repro(out_repro), out_no_repro])\n",
"end)\n",
"view_sched(general; names=N)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.3",
"language": "julia",
"name": "julia-1.9"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}