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
1=== modified file 'DfsPlugin/src/org/workcraft/plugins/dfs/VisualDfs.java'
2--- DfsPlugin/src/org/workcraft/plugins/dfs/VisualDfs.java 2013-12-16 12:01:22 +0000
3+++ DfsPlugin/src/org/workcraft/plugins/dfs/VisualDfs.java 2014-04-08 09:35:34 +0000
4@@ -227,4 +227,5 @@
5 }
6 return null;
7 }
8+
9 }
10\ No newline at end of file
11
12=== removed file 'STGPlugin/src/org/workcraft/plugins/stg/ReadArcsComplexityReduction.java'
13--- STGPlugin/src/org/workcraft/plugins/stg/ReadArcsComplexityReduction.java 2013-09-16 17:03:15 +0000
14+++ STGPlugin/src/org/workcraft/plugins/stg/ReadArcsComplexityReduction.java 1970-01-01 00:00:00 +0000
15@@ -1,116 +0,0 @@
16-package org.workcraft.plugins.stg;
17-
18-import java.util.HashMap;
19-import java.util.HashSet;
20-import java.util.LinkedList;
21-
22-import org.workcraft.dom.Connection;
23-import org.workcraft.plugins.petri.Place;
24-
25-/*
26- * This class is obsolete as punf has -r option now to replicate the Petri net places sensed by read-arcs.
27- *
28- * @deprecated use -r option of punf instead.
29- */
30-@Deprecated
31-public class ReadArcsComplexityReduction {
32-
33- public static STG reduce (STG source) {
34- STG net = new STG();
35- try
36- {
37- // TODO: doesn't work with multiple instances of the same type -- unfinished!
38-
39- HashMap<SignalTransition, SignalTransition> oldNewTran = new HashMap<SignalTransition, SignalTransition>();
40-
41- for(SignalTransition t : source.getSignalTransitions())
42- {
43- SignalTransition newt = net.createSignalTransition(t.getSignalName());
44- newt.setDirection(t.getDirection());
45- newt.setSignalType(t.getSignalType());
46- oldNewTran.put(t, newt);
47- }
48-
49- // for each place in the original STG ...
50- for (Place p: source.getPlaces()) {
51- // count incoming and outgoing connections for each transition
52- HashMap<SignalTransition, Integer> ins = new HashMap<SignalTransition,Integer>();
53- HashMap<SignalTransition, Integer> outs = new HashMap<SignalTransition,Integer>();
54-
55- for (Connection c: source.getConnections(p)) {
56- if (p==c.getFirst()) {
57- if (!outs.containsKey(c.getSecond()))
58- outs.put((SignalTransition)c.getSecond(),0);
59- outs.put((SignalTransition)c.getSecond(), outs.get((SignalTransition)c.getSecond())+1);
60- }
61- if (p==c.getSecond()) {
62- if (!ins.containsKey(c.getFirst()))
63- ins.put((SignalTransition)c.getFirst(),0);
64- ins.put((SignalTransition)c.getFirst(), ins.get((SignalTransition)c.getFirst())+1);
65- }
66- }
67-
68- HashSet<SignalTransition> trans = new HashSet<SignalTransition>();
69- trans.addAll(ins.keySet());
70- trans.addAll(outs.keySet());
71-
72- HashSet<SignalTransition> readATrans = new HashSet<SignalTransition>();
73-
74- // determine transitions connected as read-arcs
75- for (SignalTransition t: trans) {
76-
77- Integer inc = ins.get(t);
78- Integer outc = outs.get(t);
79- if (inc!=null&&outc!=null&&inc==1&&outc==1) {
80- // this is a read arc
81- readATrans.add(t);
82- }
83- }
84-
85- LinkedList<Connection> cons = new LinkedList<Connection>();
86-
87- // find all connections which are not read-arcs
88- for (Connection c: source.getConnections(p)) {
89- if (!readATrans.contains(c.getFirst())
90- &&!readATrans.contains(c.getSecond())) {
91- cons.add(c);
92- }
93- }
94-
95- //
96- if (readATrans.size()==0) {
97- // if there are no read-arcs, simply copy all the connections
98- Place newP = net.createPlace();
99- for(Connection c: cons) {
100- if (c.getFirst()==p)
101- net.connect(newP, oldNewTran.get(c.getSecond()));
102- if (c.getSecond()==p)
103- net.connect(oldNewTran.get(c.getFirst()), newP);
104- }
105- } else {
106- // for each read-arc create a place, connect it correspondingly
107- for (SignalTransition t: readATrans) {
108- Place newP = net.createPlace();
109- newP.setTokens(p.getTokens());
110- net.connect(newP, oldNewTran.get(t));
111- net.connect(oldNewTran.get(t), newP);
112- for(Connection c: cons) {
113- if (c.getFirst()==p)
114- net.connect(newP, oldNewTran.get(c.getSecond()));
115- if (c.getSecond()==p)
116- net.connect(oldNewTran.get(c.getFirst()), newP);
117- }
118-
119- }
120- }
121-
122- }
123-
124- } catch (Exception e) {
125- e.printStackTrace();
126- }
127-
128- return net;
129- }
130-
131-}
132
133=== modified file 'STGPlugin/src/org/workcraft/plugins/stg/VisualSTG.java'
134--- STGPlugin/src/org/workcraft/plugins/stg/VisualSTG.java 2014-04-03 15:39:57 +0000
135+++ STGPlugin/src/org/workcraft/plugins/stg/VisualSTG.java 2014-04-08 09:35:34 +0000
136@@ -71,34 +71,38 @@
137
138 @Override
139 public void validateConnection(Node first, Node second) throws InvalidConnectionException {
140- if (first==second) {
141+ if (first == second) {
142 throw new InvalidConnectionException ("Connections are only valid between different objects");
143 }
144
145 if (first instanceof VisualPlace) {
146- if (second instanceof VisualPlace)
147- throw new InvalidConnectionException ("Arcs between places are not allowed");
148- if (second instanceof VisualConnection)
149- throw new InvalidConnectionException ("Arcs between places and implicit places are not allowed");
150+ if (second instanceof VisualPlace) {
151+ throw new InvalidConnectionException ("Arcs between places are not allowed");
152+ }
153+ if (second instanceof VisualConnection) {
154+ throw new InvalidConnectionException ("Arcs between places and implicit places are not allowed");
155+ }
156 }
157
158 if (first instanceof VisualTransition) {
159- if (second instanceof VisualConnection)
160- if (! (second instanceof VisualImplicitPlaceArc))
161- throw new InvalidConnectionException ("Only connections with arcs having implicit places are allowed");
162+ if ((second instanceof VisualConnection) && !(second instanceof VisualImplicitPlaceArc)) {
163+ throw new InvalidConnectionException ("Only connections with arcs having implicit places are allowed");
164+ }
165+ if ((second instanceof VisualTransition) && (getConnection(first, second) != null)) {
166+ throw new InvalidConnectionException ("This arc with implicit place already exisits");
167+ }
168 }
169
170 if (first instanceof VisualConnection) {
171- if (!(first instanceof VisualImplicitPlaceArc))
172- throw new InvalidConnectionException ("Only connections with arcs having implicit places are allowed");
173- if (second instanceof VisualConnection)
174- throw new InvalidConnectionException ("Arcs between places are not allowed");
175- if (second instanceof VisualPlace)
176- throw new InvalidConnectionException ("Arcs between places are not allowed");
177-
178- VisualImplicitPlaceArc con = (VisualImplicitPlaceArc) first;
179- if (con.getFirst() == second || con.getSecond() == second)
180- throw new InvalidConnectionException ("Arc already exists");
181+ if (!(first instanceof VisualImplicitPlaceArc)) {
182+ throw new InvalidConnectionException ("Only connections with arcs having implicit places are allowed");
183+ }
184+ if (second instanceof VisualConnection) {
185+ throw new InvalidConnectionException ("Arcs between places are not allowed");
186+ }
187+ if (second instanceof VisualPlace) {
188+ throw new InvalidConnectionException ("Arcs between places are not allowed");
189+ }
190 }
191 }
192
193@@ -182,26 +186,19 @@
194 private void maybeMakeImplicit (VisualPlace place) {
195 final STGPlace stgPlace = (STGPlace)place.getReferencedPlace();
196 if ( stgPlace.isImplicit() ) {
197-
198 MathConnection refCon1 = null, refCon2 = null;
199-
200 VisualComponent first = (VisualComponent) getPreset(place).iterator().next();
201 VisualComponent second = (VisualComponent) getPostset(place).iterator().next();
202-
203 Collection<Connection> connections = new ArrayList<Connection> (getConnections(place));
204- for (Connection con: connections)
205- if (con.getFirst() == place)
206+ for (Connection con: connections) {
207+ if (con.getFirst() == place) {
208 refCon2 = ((VisualConnection)con).getReferencedConnection();
209- else if (con.getSecond() == place)
210+ } else if (con.getSecond() == place) {
211 refCon1 = ((VisualConnection)con).getReferencedConnection();
212-
213-
214+ }
215+ }
216 VisualImplicitPlaceArc con = new VisualImplicitPlaceArc(first, second, refCon1, refCon2, (STGPlace)place.getReferencedPlace());
217-
218- Hierarchy.getNearestAncestor(
219- Hierarchy.getCommonParent(first, second), Container.class)
220- .add(con);
221-
222+ Hierarchy.getNearestAncestor(Hierarchy.getCommonParent(first, second), Container.class) .add(con);
223 remove(place);
224 // connections will get removed automatically by the hanging connection remover
225 }
226@@ -243,4 +240,12 @@
227 return null;
228 }
229
230+
231+ public Connection getConnection(Node first, Node second) {
232+ for(Connection connection : getConnections(first)) {
233+ if (connection.getSecond() == second) return connection;
234+ }
235+ return null;
236+ }
237+
238 }

Subscribers

People subscribed via source and target branches