forked from Kappa-Dev/ExtentionBases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.ml
72 lines (63 loc) · 2.24 KB
/
model.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
module Make (Node:Node.NodeType) =
struct
module Cat = Cat.Make (Node)
module Graph = Graph.Make (Node)
module Hom = Homomorphism.Make (Node)
let (|>) = Cat.(|>)
let (/|) = Cat.(/|)
type t = {rules : (Graph.t * Graph.t) Lib.IntMap.t ; obs : Graph.t Lib.IntMap.t ; dict : Lib.Dict.t}
type effect = {neg : Cat.arrows option ; pos : Cat.arrows option}
let add_rule name (l,r) m =
let id,dict = Lib.Dict.fresh m.dict in
let dict = Lib.Dict.add id name dict in
{rules = Lib.IntMap.add id (l,r) m.rules ; obs = Lib.IntMap.add id l m.obs ; dict = dict}
let get_rule id m = Lib.IntMap.find id m.rules
let get_obs id m = Lib.IntMap.find id m.obs
let add_obs name o m =
let id,dict = Lib.Dict.fresh m.dict in
let dict = Lib.Dict.add id name dict in
{m with obs = Lib.IntMap.add id o m.obs ; dict = dict}
let empty = {rules = Lib.IntMap.empty ; obs = Lib.IntMap.empty ; dict = Lib.Dict.empty}
let effect_of_rule (l,r) =
let minus g h =
let m = Graph.minus g h in
if Graph.is_empty m then None
else Some (Cat.identity m g)
in
{neg = minus l r ;
pos = minus r l
}
let witnesses_of_rule r m =
let enum_witnesses obs_name id_emb obs =
let h_eps = Cat.src id_emb in
List.fold_left
(fun tiles gluing_tile ->
match Cat.upper_bound gluing_tile with
None -> tiles
| Some (h_eps_to_w,_) ->
(*Checking that w and pi_eps have a sup.*)
match Cat.share h_eps_to_w id_emb with
[] -> tiles
| (_,tile)::_ ->
if Cat.upper_bound tile = None then tiles
else (obs_name,gluing_tile)::tiles
) [] (h_eps |> obs)
in
let build_witnesses effect observables =
Lib.IntMap.fold
(fun obs_id o (nw,pw) ->
let neg_witnesses =
match effect.neg with
None -> []
| Some neg -> enum_witnesses obs_id neg o
in
let pos_witnesses =
match effect.pos with
| None -> []
| Some pos -> enum_witnesses obs_id pos o
in
(neg_witnesses@nw, pos_witnesses@pw)
) observables ([],[])
in
build_witnesses (effect_of_rule r) m.obs
end