-
Notifications
You must be signed in to change notification settings - Fork 9
/
AbsMorphism.java
135 lines (124 loc) · 4.28 KB
/
AbsMorphism.java
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
import java.util.Vector;
/******************************
* Copyright (c) 2003,2019 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
* *****************************/
class AbsMorphism
{ Map statemap;
Map transmap;
Map eventmap;
Statemachine abs;
Statemachine conc;
AbsMorphism()
{ statemap = new Map();
transmap = new Map();
eventmap = new Map();
}
public void print_morphism()
{ System.out.println("Event mapping");
eventmap.print_map();
System.out.println("State mapping");
statemap.print_map();
System.out.println("Transition mapping");
transmap.print_map();
}
public boolean build_map(Statemachine abs, Statemachine conc)
{ this.abs = abs;
this.conc = conc;
Vector processed = new Vector(conc.states.size());
Maplet mm = new Maplet(conc.initial_state, abs.initial_state);
statemap.add_element(mm);
System.out.println("Mapped " + mm.toString());
if (try_match(conc.initial_state,abs.initial_state,processed,abs,conc))
{ return true; }
else
{ statemap.clear();
eventmap.clear();
transmap.clear();
return false;
}
}
public boolean try_match(State currc, State curra, Vector processed,
Statemachine abs, Statemachine conc)
{ if (processed.contains(currc))
{ return true; }
else
{ processed.addElement(currc);
for (int i = 0; i < conc.transitions.size(); i++)
{ Transition t = (Transition) conc.transitions.elementAt(i);
if (t.source == currc)
{ Transition ta = abs.find_match(t.event,curra);
if (ta == null)
{ System.out.println("No abstract transition matching " + t);
return false;
}
else
{ System.out.println(t.target.label + " -> " + ta.target.label);
System.out.println(t.label + " -> " + ta.label);
if (statemap.in_domain(t.target))
{ State img = (State) statemap.apply(t.target);
if (img == ta.target)
{ transmap.add_pair(t,ta);
System.out.println("Mapped " + t + " to " + ta);
}
else
{ System.out.println("Target of " + ta +
" is not abstraction of " + t.target);
return false;
}
}
else
{ statemap.add_pair(t.target,ta.target);
transmap.add_pair(t,ta);
System.out.println("Mapped " + t + " to " + ta);
}
boolean bb = try_match(t.target,ta.target,processed,abs,conc); }
}
}
}
return true; /* No transitions from currc, or all succeeded */
}
public boolean checkTotality()
{ boolean ok = true;
Vector dom = transmap.domain();
Vector trs = conc.getTransitions();
if (dom.containsAll(trs)) {}
else
{ ok = false;
System.out.println("Some concrete transitions are not given abstractions ");
}
Vector sdom = statemap.domain();
Vector allstates = conc.getStates();
if (sdom.containsAll(allstates)) {}
else
{ ok = false;
System.out.println("Some concrete states are not given abstractions ");
}
return ok;
}
public boolean checkCompleteness() // adequacy conditions
{ Vector allabstract = new Vector(); // the abstract states of the map
for (int i = 0; i < statemap.elements.size(); i++)
{ Maplet mm = (Maplet) statemap.elements.get(i);
State st = (State) mm.dest;
if (allabstract.contains(st)) { }
else
{ allabstract.add(st); }
}
if (allabstract.containsAll(abs.getStates()))
{ System.out.println("State map is complete"); }
else
{ Vector vv = new Vector();
vv.addAll(abs.getStates());
vv.removeAll(allabstract);
System.out.println("State map is not complete, states: " + vv +
" have no concrete representation");
return false;
}
return true;
}
}