Merge lp:~danilovesky/workcraft/trunk-bug-1291931 into lp:workcraft

Proposed by Danil Sokolov
Status: Merged
Merged at revision: 495
Proposed branch: lp:~danilovesky/workcraft/trunk-bug-1291931
Merge into: lp:workcraft
Diff against target: 238 lines (+37/-147)
3 files modified
DfsPlugin/src/org/workcraft/plugins/dfs/VisualDfs.java (+1/-0)
STGPlugin/src/org/workcraft/plugins/stg/ReadArcsComplexityReduction.java (+0/-116)
STGPlugin/src/org/workcraft/plugins/stg/VisualSTG.java (+36/-31)
To merge this branch: bzr merge lp:~danilovesky/workcraft/trunk-bug-1291931
Reviewer Review Type Date Requested Status
Danil Sokolov Approve
Review via email: mp+214693@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Danil Sokolov (danilovesky) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'DfsPlugin/src/org/workcraft/plugins/dfs/VisualDfs.java'
--- DfsPlugin/src/org/workcraft/plugins/dfs/VisualDfs.java 2013-12-16 12:01:22 +0000
+++ DfsPlugin/src/org/workcraft/plugins/dfs/VisualDfs.java 2014-04-08 09:35:34 +0000
@@ -227,4 +227,5 @@
227 }227 }
228 return null;228 return null;
229 }229 }
230
230}231}
231\ No newline at end of file232\ No newline at end of file
232233
=== removed file 'STGPlugin/src/org/workcraft/plugins/stg/ReadArcsComplexityReduction.java'
--- STGPlugin/src/org/workcraft/plugins/stg/ReadArcsComplexityReduction.java 2013-09-16 17:03:15 +0000
+++ STGPlugin/src/org/workcraft/plugins/stg/ReadArcsComplexityReduction.java 1970-01-01 00:00:00 +0000
@@ -1,116 +0,0 @@
1package org.workcraft.plugins.stg;
2
3import java.util.HashMap;
4import java.util.HashSet;
5import java.util.LinkedList;
6
7import org.workcraft.dom.Connection;
8import org.workcraft.plugins.petri.Place;
9
10/*
11 * This class is obsolete as punf has -r option now to replicate the Petri net places sensed by read-arcs.
12 *
13 * @deprecated use -r option of punf instead.
14 */
15@Deprecated
16public class ReadArcsComplexityReduction {
17
18 public static STG reduce (STG source) {
19 STG net = new STG();
20 try
21 {
22 // TODO: doesn't work with multiple instances of the same type -- unfinished!
23
24 HashMap<SignalTransition, SignalTransition> oldNewTran = new HashMap<SignalTransition, SignalTransition>();
25
26 for(SignalTransition t : source.getSignalTransitions())
27 {
28 SignalTransition newt = net.createSignalTransition(t.getSignalName());
29 newt.setDirection(t.getDirection());
30 newt.setSignalType(t.getSignalType());
31 oldNewTran.put(t, newt);
32 }
33
34 // for each place in the original STG ...
35 for (Place p: source.getPlaces()) {
36 // count incoming and outgoing connections for each transition
37 HashMap<SignalTransition, Integer> ins = new HashMap<SignalTransition,Integer>();
38 HashMap<SignalTransition, Integer> outs = new HashMap<SignalTransition,Integer>();
39
40 for (Connection c: source.getConnections(p)) {
41 if (p==c.getFirst()) {
42 if (!outs.containsKey(c.getSecond()))
43 outs.put((SignalTransition)c.getSecond(),0);
44 outs.put((SignalTransition)c.getSecond(), outs.get((SignalTransition)c.getSecond())+1);
45 }
46 if (p==c.getSecond()) {
47 if (!ins.containsKey(c.getFirst()))
48 ins.put((SignalTransition)c.getFirst(),0);
49 ins.put((SignalTransition)c.getFirst(), ins.get((SignalTransition)c.getFirst())+1);
50 }
51 }
52
53 HashSet<SignalTransition> trans = new HashSet<SignalTransition>();
54 trans.addAll(ins.keySet());
55 trans.addAll(outs.keySet());
56
57 HashSet<SignalTransition> readATrans = new HashSet<SignalTransition>();
58
59 // determine transitions connected as read-arcs
60 for (SignalTransition t: trans) {
61
62 Integer inc = ins.get(t);
63 Integer outc = outs.get(t);
64 if (inc!=null&&outc!=null&&inc==1&&outc==1) {
65 // this is a read arc
66 readATrans.add(t);
67 }
68 }
69
70 LinkedList<Connection> cons = new LinkedList<Connection>();
71
72 // find all connections which are not read-arcs
73 for (Connection c: source.getConnections(p)) {
74 if (!readATrans.contains(c.getFirst())
75 &&!readATrans.contains(c.getSecond())) {
76 cons.add(c);
77 }
78 }
79
80 //
81 if (readATrans.size()==0) {
82 // if there are no read-arcs, simply copy all the connections
83 Place newP = net.createPlace();
84 for(Connection c: cons) {
85 if (c.getFirst()==p)
86 net.connect(newP, oldNewTran.get(c.getSecond()));
87 if (c.getSecond()==p)
88 net.connect(oldNewTran.get(c.getFirst()), newP);
89 }
90 } else {
91 // for each read-arc create a place, connect it correspondingly
92 for (SignalTransition t: readATrans) {
93 Place newP = net.createPlace();
94 newP.setTokens(p.getTokens());
95 net.connect(newP, oldNewTran.get(t));
96 net.connect(oldNewTran.get(t), newP);
97 for(Connection c: cons) {
98 if (c.getFirst()==p)
99 net.connect(newP, oldNewTran.get(c.getSecond()));
100 if (c.getSecond()==p)
101 net.connect(oldNewTran.get(c.getFirst()), newP);
102 }
103
104 }
105 }
106
107 }
108
109 } catch (Exception e) {
110 e.printStackTrace();
111 }
112
113 return net;
114 }
115
116}
1170
=== modified file 'STGPlugin/src/org/workcraft/plugins/stg/VisualSTG.java'
--- STGPlugin/src/org/workcraft/plugins/stg/VisualSTG.java 2014-04-03 15:39:57 +0000
+++ STGPlugin/src/org/workcraft/plugins/stg/VisualSTG.java 2014-04-08 09:35:34 +0000
@@ -71,34 +71,38 @@
7171
72 @Override72 @Override
73 public void validateConnection(Node first, Node second) throws InvalidConnectionException {73 public void validateConnection(Node first, Node second) throws InvalidConnectionException {
74 if (first==second) {74 if (first == second) {
75 throw new InvalidConnectionException ("Connections are only valid between different objects");75 throw new InvalidConnectionException ("Connections are only valid between different objects");
76 }76 }
77 77
78 if (first instanceof VisualPlace) {78 if (first instanceof VisualPlace) {
79 if (second instanceof VisualPlace)79 if (second instanceof VisualPlace) {
80 throw new InvalidConnectionException ("Arcs between places are not allowed");80 throw new InvalidConnectionException ("Arcs between places are not allowed");
81 if (second instanceof VisualConnection)81 }
82 throw new InvalidConnectionException ("Arcs between places and implicit places are not allowed");82 if (second instanceof VisualConnection) {
83 throw new InvalidConnectionException ("Arcs between places and implicit places are not allowed");
84 }
83 }85 }
8486
85 if (first instanceof VisualTransition) {87 if (first instanceof VisualTransition) {
86 if (second instanceof VisualConnection)88 if ((second instanceof VisualConnection) && !(second instanceof VisualImplicitPlaceArc)) {
87 if (! (second instanceof VisualImplicitPlaceArc))89 throw new InvalidConnectionException ("Only connections with arcs having implicit places are allowed");
88 throw new InvalidConnectionException ("Only connections with arcs having implicit places are allowed");90 }
91 if ((second instanceof VisualTransition) && (getConnection(first, second) != null)) {
92 throw new InvalidConnectionException ("This arc with implicit place already exisits");
93 }
89 }94 }
9095
91 if (first instanceof VisualConnection) {96 if (first instanceof VisualConnection) {
92 if (!(first instanceof VisualImplicitPlaceArc))97 if (!(first instanceof VisualImplicitPlaceArc)) {
93 throw new InvalidConnectionException ("Only connections with arcs having implicit places are allowed");98 throw new InvalidConnectionException ("Only connections with arcs having implicit places are allowed");
94 if (second instanceof VisualConnection)99 }
95 throw new InvalidConnectionException ("Arcs between places are not allowed");100 if (second instanceof VisualConnection) {
96 if (second instanceof VisualPlace)101 throw new InvalidConnectionException ("Arcs between places are not allowed");
97 throw new InvalidConnectionException ("Arcs between places are not allowed");102 }
98103 if (second instanceof VisualPlace) {
99 VisualImplicitPlaceArc con = (VisualImplicitPlaceArc) first;104 throw new InvalidConnectionException ("Arcs between places are not allowed");
100 if (con.getFirst() == second || con.getSecond() == second)105 }
101 throw new InvalidConnectionException ("Arc already exists");
102 }106 }
103 }107 }
104108
@@ -182,26 +186,19 @@
182 private void maybeMakeImplicit (VisualPlace place) {186 private void maybeMakeImplicit (VisualPlace place) {
183 final STGPlace stgPlace = (STGPlace)place.getReferencedPlace();187 final STGPlace stgPlace = (STGPlace)place.getReferencedPlace();
184 if ( stgPlace.isImplicit() ) {188 if ( stgPlace.isImplicit() ) {
185
186 MathConnection refCon1 = null, refCon2 = null;189 MathConnection refCon1 = null, refCon2 = null;
187
188 VisualComponent first = (VisualComponent) getPreset(place).iterator().next();190 VisualComponent first = (VisualComponent) getPreset(place).iterator().next();
189 VisualComponent second = (VisualComponent) getPostset(place).iterator().next();191 VisualComponent second = (VisualComponent) getPostset(place).iterator().next();
190
191 Collection<Connection> connections = new ArrayList<Connection> (getConnections(place));192 Collection<Connection> connections = new ArrayList<Connection> (getConnections(place));
192 for (Connection con: connections)193 for (Connection con: connections) {
193 if (con.getFirst() == place)194 if (con.getFirst() == place) {
194 refCon2 = ((VisualConnection)con).getReferencedConnection();195 refCon2 = ((VisualConnection)con).getReferencedConnection();
195 else if (con.getSecond() == place)196 } else if (con.getSecond() == place) {
196 refCon1 = ((VisualConnection)con).getReferencedConnection();197 refCon1 = ((VisualConnection)con).getReferencedConnection();
197198 }
198199 }
199 VisualImplicitPlaceArc con = new VisualImplicitPlaceArc(first, second, refCon1, refCon2, (STGPlace)place.getReferencedPlace());200 VisualImplicitPlaceArc con = new VisualImplicitPlaceArc(first, second, refCon1, refCon2, (STGPlace)place.getReferencedPlace());
200201 Hierarchy.getNearestAncestor(Hierarchy.getCommonParent(first, second), Container.class) .add(con);
201 Hierarchy.getNearestAncestor(
202 Hierarchy.getCommonParent(first, second), Container.class)
203 .add(con);
204
205 remove(place);202 remove(place);
206 // connections will get removed automatically by the hanging connection remover203 // connections will get removed automatically by the hanging connection remover
207 }204 }
@@ -243,4 +240,12 @@
243 return null;240 return null;
244 }241 }
245242
243
244 public Connection getConnection(Node first, Node second) {
245 for(Connection connection : getConnections(first)) {
246 if (connection.getSecond() == second) return connection;
247 }
248 return null;
249 }
250
246}251}

Subscribers

People subscribed via source and target branches