Skip to content

Commit 1021070

Browse files
committed
Source -> cleanup
1 parent 10bfe0c commit 1021070

30 files changed

+1267
-1182
lines changed

fr.lip6.move.gal.structural/src/fr/lip6/move/gal/graph/GraphSuffix.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ private static int reduceUnmarkedSuffix(SparsePetriNet spn, IntMatrixCol graph,
4444
IntMatrixCol tgraph = graph.transpose();
4545
Set<Integer> heads = new HashSet<>();
4646
for (int pid = 0; pid < tgraph.getColumnCount(); pid++) {
47-
if (tgraph.getColumn(pid).size() == 0 && spn.getMarks().get(pid) == 0 && !nonstable[pid])
47+
if (tgraph.getColumn(pid).size() == 0 && spn.getMarks().get(pid) == 0 && !nonstable[pid]) {
4848
heads.add(pid);
49+
}
4950
}
5051

5152
// 6. Calcul des suffixes des têtes
@@ -61,8 +62,9 @@ private static int reduceUnmarkedSuffix(SparsePetriNet spn, IntMatrixCol graph,
6162
nonstable[i] = true;
6263
reduced++;
6364
}
64-
if (!unStableSuffix.isEmpty())
65+
if (!unStableSuffix.isEmpty()) {
6566
doneProps.put("unMarkedSuffixTest", false, "UNMARKED_SUFFIX_TEST");
67+
}
6668
return reduced;
6769
}
6870

@@ -86,8 +88,9 @@ private static int reduceMarkedSuffix(SparsePetriNet spn, IntMatrixCol graph, bo
8688
nonstable[i] = true;
8789
reduced++;
8890
}
89-
if (!safeNodes.isEmpty())
91+
if (!safeNodes.isEmpty()) {
9092
doneProps.put("markedSuffixTest", false, "MARKED_SUFFIX_TEST");
93+
}
9194
return reduced;
9295
}
9396

@@ -119,8 +122,9 @@ private static int reduceTrivialScc(SparsePetriNet spn, DoneProperties doneProps
119122
BitSet bs = new BitSet();
120123

121124
for (int pid = 0; pid < spn.getPlaceCount(); pid++) {
122-
if (spn.getMarks().get(pid) > 0)
125+
if (spn.getMarks().get(pid) > 0) {
123126
bs.set(pid);
127+
}
124128
}
125129
sr.setProtected(bs);
126130

fr.lip6.move.gal.structural/src/fr/lip6/move/gal/graph/Tarjan.java

Lines changed: 95 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ private void dfs(int u) {
3737
for (int i = 0; i < adj.getColumn(u).size(); i++) {
3838
int v = adj.getColumn(u).keyAt(i);
3939

40-
if (!marked[v])
40+
if (!marked[v]) {
4141
dfs(v);
42-
if (low[v] < min)
42+
}
43+
if (low[v] < min) {
4344
min = low[v];
45+
}
4446
}
4547
if (min < low[u]) {
4648
low[u] = min;
@@ -74,17 +76,19 @@ public Set<Integer> parsePetriNet(ISparsePetriNet graph) {
7476
low = new int[n];
7577
adj = computeAdjacency(graph);
7678

77-
for (int u = 0; u < n; u++)
78-
if (!marked[u])
79+
for (int u = 0; u < n; u++) {
80+
if (!marked[u]) {
7981
dfs(u);
80-
82+
}
83+
}
84+
8185
Map<Integer, List<Integer>> sccs = new HashMap<>();
8286
for(int pid = 0; pid < id.length; pid++) {
83-
sccs.computeIfAbsent(id[pid], k -> new ArrayList<>()).add(pid);
84-
87+
sccs.computeIfAbsent(id[pid], k -> new ArrayList<>()).add(pid);
88+
8589
}
8690
Set<Integer> nonTrivialSCC = new HashSet<>();
87-
91+
8892
for(List<Integer> scc : sccs.values()) {
8993
if(scc.size() > 1 || adj.get(scc.get(0), scc.get(0)) == 1) {
9094
nonTrivialSCC.addAll(scc);
@@ -97,7 +101,7 @@ public Set<Integer> parsePetriNet(ISparsePetriNet graph) {
97101
public static Set<Integer> computePlacesInNonTrivialSCC (ISparsePetriNet spn) {
98102
IntMatrixCol graph = computeAdjacency(spn);
99103
Set<Integer> nonTrivialSCC = new HashSet<>();
100-
104+
101105
List<List<Integer>> sccs = searchForSCC(graph);
102106
for(List<Integer> scc : sccs) {
103107
if(scc.size() > 1 || graph.get(scc.get(0), scc.get(0)) == 1) {
@@ -106,7 +110,7 @@ public static Set<Integer> computePlacesInNonTrivialSCC (ISparsePetriNet spn) {
106110
}
107111
return nonTrivialSCC;
108112
}
109-
113+
110114
private static IntMatrixCol computeAdjacency(ISparsePetriNet graph) {
111115
IntMatrixCol adj = new IntMatrixCol(graph.getPlaceCount(), graph.getPlaceCount());
112116
IntMatrixCol flowPT = graph.getFlowPT();
@@ -123,91 +127,97 @@ private static IntMatrixCol computeAdjacency(ISparsePetriNet graph) {
123127
}
124128
return adj;
125129
}
126-
127-
128-
129-
130+
131+
132+
133+
130134
/**
131135
* Non recursive version based on Ivan Stoev proposal on SO :
132136
* https://stackoverflow.com/questions/46511682/non-recursive-version-of-tarjans-algorithm.
133-
*
137+
*
134138
* @param graph
135139
* @return the SCCs
136140
*/
137141
public static List<List<Integer>> searchForSCC(IntMatrixCol graph)
138142
{
139143
List<List<Integer>> stronglyConnectedComponents = new ArrayList<>();
140144

141-
int preCount = 0;
142-
int [] low = new int[graph.getColumnCount()];
143-
boolean [] visited = new boolean[graph.getColumnCount()];
144-
Stack<Integer> stack = new Stack<>();
145-
146-
Stack<Integer> minStack = new Stack<>();
147-
Stack<Integer> vStack = new Stack<>();
148-
Stack<Iterator<Integer>> enumeratorStack = new Stack<>();
149-
150-
Iterator<Integer> enumerator = IntStream.range(0, graph.getColumnCount()).iterator();
151-
while (true)
152-
{
153-
if (enumerator.hasNext())
154-
{
155-
int v = enumerator.next();
156-
if (!visited[v])
157-
{
158-
low[v] = preCount++;
159-
visited[v] = true;
160-
stack.push(v);
161-
int min = low[v];
162-
// Level down
163-
minStack.push(min);
164-
vStack.push(v);
165-
enumeratorStack.push(enumerator);
166-
enumerator = Arrays.stream(graph.getColumn(v).copyKeys()).iterator();
167-
}
168-
else if (minStack.size() > 0)
169-
{
170-
int min = minStack.pop();
171-
if (low[v] < min) min = low[v];
172-
minStack.push(min);
173-
}
174-
}
175-
else
176-
{
177-
// Level up
178-
if (enumeratorStack.size() == 0) break;
179-
180-
enumerator = enumeratorStack.pop();
181-
int v = vStack.pop();
182-
int min = minStack.pop();
183-
184-
if (min < low[v])
185-
{
186-
low[v] = min;
187-
}
188-
else
189-
{
190-
List<Integer> component = new ArrayList<>();
191-
192-
int w;
193-
do
194-
{
195-
w = stack.pop();
196-
component.add(w);
197-
low[w] = graph.getColumnCount();
198-
} while (w != v);
199-
stronglyConnectedComponents.add(component);
200-
}
201-
202-
if (minStack.size() > 0)
203-
{
204-
min = minStack.pop();
205-
if (low[v] < min) min = low[v];
206-
minStack.push(min);
207-
}
208-
}
209-
}
210-
return stronglyConnectedComponents;
145+
int preCount = 0;
146+
int [] low = new int[graph.getColumnCount()];
147+
boolean [] visited = new boolean[graph.getColumnCount()];
148+
Stack<Integer> stack = new Stack<>();
149+
150+
Stack<Integer> minStack = new Stack<>();
151+
Stack<Integer> vStack = new Stack<>();
152+
Stack<Iterator<Integer>> enumeratorStack = new Stack<>();
153+
154+
Iterator<Integer> enumerator = IntStream.range(0, graph.getColumnCount()).iterator();
155+
while (true)
156+
{
157+
if (enumerator.hasNext())
158+
{
159+
int v = enumerator.next();
160+
if (!visited[v])
161+
{
162+
low[v] = preCount++;
163+
visited[v] = true;
164+
stack.push(v);
165+
int min = low[v];
166+
// Level down
167+
minStack.push(min);
168+
vStack.push(v);
169+
enumeratorStack.push(enumerator);
170+
enumerator = Arrays.stream(graph.getColumn(v).copyKeys()).iterator();
171+
}
172+
else if (minStack.size() > 0)
173+
{
174+
int min = minStack.pop();
175+
if (low[v] < min) {
176+
min = low[v];
177+
}
178+
minStack.push(min);
179+
}
180+
}
181+
else
182+
{
183+
// Level up
184+
if (enumeratorStack.size() == 0) {
185+
break;
186+
}
187+
188+
enumerator = enumeratorStack.pop();
189+
int v = vStack.pop();
190+
int min = minStack.pop();
191+
192+
if (min < low[v])
193+
{
194+
low[v] = min;
195+
}
196+
else
197+
{
198+
List<Integer> component = new ArrayList<>();
199+
200+
int w;
201+
do
202+
{
203+
w = stack.pop();
204+
component.add(w);
205+
low[w] = graph.getColumnCount();
206+
} while (w != v);
207+
stronglyConnectedComponents.add(component);
208+
}
209+
210+
if (minStack.size() > 0)
211+
{
212+
min = minStack.pop();
213+
if (low[v] < min) {
214+
min = low[v];
215+
}
216+
minStack.push(min);
217+
}
218+
}
219+
}
220+
return stronglyConnectedComponents;
211221
}
212222

213223
}

fr.lip6.move.gal.structural/src/fr/lip6/move/gal/mcc/properties/ConcurrentHashDoneProperties.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ConcurrentHashDoneProperties implements DoneProperties {
1313
private static final int DEBUG = 0;
1414
private Map<String,Boolean> map = new ConcurrentHashMap<>();
1515
protected Map<String,List<String>> alias = new HashMap<>();
16-
16+
1717
@Override
1818
public boolean containsKey(Object arg0) {
1919
return map.containsKey(arg0);
@@ -36,9 +36,9 @@ public Boolean put(String prop, Boolean value, String techniques) {
3636
}
3737
}
3838
return b;
39-
39+
4040
}
41-
41+
4242
@Override
4343
public Boolean put(String prop, Integer value, String techniques) {
4444
Boolean b = map.put(prop, true);
@@ -59,7 +59,8 @@ public Set<String> keySet() {
5959
public int size() {
6060
return map.size();
6161
}
62-
62+
63+
@Override
6364
public Boolean getValue(String prop) {
6465
return map.get(prop);
6566
}
@@ -71,10 +72,11 @@ public boolean isFinished() {
7172

7273
@Override
7374
public void addAlias(String propToCheck, String aka) {
74-
alias.compute(propToCheck, (k,v) ->
75+
alias.compute(propToCheck, (k,v) ->
7576
{
76-
if (v==null)
77+
if (v==null) {
7778
v = new ArrayList<>();
79+
}
7880
v.add(aka);
7981
return v;
8082
});

fr.lip6.move.gal.structural/src/fr/lip6/move/gal/mcc/properties/DoneProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ public interface DoneProperties {
2222
public Boolean getValue(String prop);
2323

2424
boolean isFinished();
25-
25+
2626
void addAlias(String propToCheck, String aka);
2727
}

fr.lip6.move.gal.structural/src/fr/lip6/move/gal/mcc/properties/LTSMinPropertyPrinter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public class LTSMinPropertyPrinter extends PropertyPrinter {
1111
public LTSMinPropertyPrinter(PrintWriter pw) {
1212
super(pw, "p", false);
1313
}
14-
14+
1515
@Override
1616
public Void visit(AtomicPropRef apRef) {
17-
return apRef.getAp().getExpression().accept(this);
17+
return apRef.getAp().getExpression().accept(this);
1818
}
19-
19+
2020

2121
@Override
2222
public Void visit(TransRef transRef) {
@@ -29,5 +29,5 @@ public Void visit(VarRef varRef) {
2929
pw.append("p").append(Integer.toString(varRef.getValue()));
3030
return null;
3131
}
32-
32+
3333
}

fr.lip6.move.gal.structural/src/fr/lip6/move/gal/mcc/properties/MCCExporter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ public class MCCExporter {
1313
* Build MCC compliant representation of the provided SparsePetriNet and it's
1414
* properties.
1515
* NB : IOExceptions are not reported to caller.
16-
*
16+
*
1717
* @param pnmlpath path to build the model file in PNML format
1818
* @param proppath path to put the formulas in MCC XML format
1919
* @param spn the net which should have properties
2020
*/
2121
public static void exportToMCCFormat(String pnmlpath, String proppath, SparsePetriNet spn) {
2222
try {
2323
List<Integer> usedConstants = new ArrayList<>();
24-
if (!spn.getProperties().isEmpty())
24+
if (!spn.getProperties().isEmpty()) {
2525
usedConstants = PropertiesToPNML.transform(spn, proppath, new ConcurrentHashDoneProperties());
26+
}
2627
if (! usedConstants.isEmpty()) {
2728
// we exported constants to a place with index = current place count
2829
// to be consistent now add a trivially constant place with initial marking 1

0 commit comments

Comments
 (0)