-
Notifications
You must be signed in to change notification settings - Fork 1
/
portNode.ml
138 lines (119 loc) · 3.54 KB
/
portNode.ml
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
module type SymT =
sig
val compatible : (int -> int -> int -> int -> bool)
val rigid_bonds : bool
val rigid_ports : bool
val info : string
end
module Make (Symmetry:SymT) =
(struct
type t = {ag_id : int ; port_id : int ; label : int}
let arity = 2
let info = Symmetry.info
let has_rigid_ports = Symmetry.rigid_ports
let has_rigid_bonds = Symmetry.rigid_bonds
let label u = u.label
let id u = u.ag_id
let rename i u = {u with ag_id = i}
let compatible u v = Symmetry.compatible u.label u.port_id v.label v.port_id
let gluable u v = (*same id, same label and different ports*)
(id u = id v) && compatible u v
let compare = Pervasives.compare
let distinguishable u v =
id u <> id v || not (compatible u v)
let create l =
match l with
[i;p;l] -> {ag_id = i ; port_id = p ; label = l}
| _ -> failwith "Cannot parse node"
let to_string u =
(string_of_int u.ag_id)^"."^(string_of_int (u.port_id))
let to_dot u ?(highlight=None) i =
let ref_node = string_of_int i in
ref_node^" [label=\""^(string_of_int (label u))^"\" "^(Lib.Util.hi2str highlight)^"]"
let dot_of_edge u i v j =
let tl = string_of_int u.port_id in
let hl = string_of_int v.port_id in
Printf.sprintf "%d->%d [dir = none, taillabel = \"%s\", headlabel = \"%s\"]" i j tl hl
let tn = List.map (fun (l,l') -> (create l,create l'))
let coh edges (w,x) =
let ok u v =
if u.ag_id = v.ag_id then ((u.port_id != v.port_id) && (u.label = v.label))
else true
in
List.for_all
(fun (u,v) ->
ok u x && ok v x && ok u w && ok v w && ok w x
) edges
let library =
let void = [] in
let house =
[
([0;0;0],[1;0;0]) ;
([1;1;0],[2;1;0]) ;
([2;0;0],[3;0;0]) ;
([3;1;0],[0;1;0]) ;
([3;2;0],[4;0;0]) ;
([4;1;0]),[2;2;0]
]
in
let square =
[
([0;0;0],[1;0;0]) ;
([1;1;0],[2;1;0]) ;
([2;0;0],[3;0;0]) ;
([3;1;0],[0;1;0])
]
in
let osquare =
[
([0;0;0],[1;0;0]) ;
([0;1;0],[3;1;0]) ;
([1;1;0],[2;1;0]) ;
]
in
let dsquare =
[
([0;0;0],[1;0;0]) ;
([1;1;0],[2;1;0]) ;
([2;0;0],[3;0;0]) ;
([3;1;0],[0;1;0]) ;
([3;2;0],[1;2;0]) ;
]
in
let triangle =
[
([0;0;0],[1;0;0]) ;
([0;2;0],[2;0;0]) ;
([2;1;0],[1;2;0])
]
in
let one = [([0;0;0],[1;0;0])] in
let two = [([0;0;0],[1;0;0]);([2;0;0],[1;1;0])] in
let lib = Lib.StringMap.add "empty" (tn void) Lib.StringMap.empty in
let lib = Lib.StringMap.add "house" (tn house) lib
in
let lib = Lib.StringMap.add "square" (tn square) lib
in
let lib = Lib.StringMap.add "osquare" (tn osquare) lib
in
let lib = Lib.StringMap.add "dsquare" (tn dsquare) lib
in
let lib = Lib.StringMap.add "one" (tn one) lib in
let lib = Lib.StringMap.add "two" (tn two) lib in
Lib.StringMap.add "triangle" (tn triangle) lib
end:Node.NodeType)
module KappaNode =
Make (struct let compatible = fun l p l' p' -> l=l' && p=p' let info = "Kappa Graphs" let rigid_ports = true let rigid_bonds = true end)
module KappaNode01 = (*ports 0 and 1 of all agents are equivalent*)
Make
(struct
let compatible = fun l p l' p' ->
l=l' &&
if p = 0 || p=1 then p'=0 || p'=1
else p=p'
let info = "Kappa Graphs (0~1)"
let rigid_ports = false let rigid_bonds = true
end)
(*all ports of the same agents are equivalent!*)
module DegreeNode =
Make (struct let compatible = fun l _ l' _ -> (l=l') let info = "Port Graphs" let rigid_ports = false let rigid_bonds = true end)