-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContext.jl
More file actions
39 lines (33 loc) · 890 Bytes
/
Context.jl
File metadata and controls
39 lines (33 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using VirtualPlantLab
module types
using VirtualPlantLab
struct Cell <: Node
state::Int64
end
end
import .types: Cell
function transfer(context)
if has_parent(context)
return (true, (parent(context), ))
else
return (false, ())
end
end
rule = Rule(Cell, lhs = transfer, rhs = (context, father) -> Cell(data(father).state), captures = true)
axiom = Cell(1) + Cell(0) + Cell(0)
pop = Graph(axiom = axiom, rules = rule)
getCell = Query(Cell)
apply(pop, getCell)
rewrite!(pop)
apply(pop, getCell)
rewrite!(pop)
apply(pop, getCell)
pop = Graph(axiom = axiom, rules = rule)
states = Int64[]
traverse_dfs(pop, fun = node -> push!(states, node.state))
states
rewrite!(pop)
states = Int64[]
traverse_dfs(pop, fun = node -> push!(states, node.state))
states
# This file was generated using Literate.jl, https://github.com/fredrikekre/Literate.jl