1 package net.kwfgrid.gworkflowdl.analysis;
2
3 import net.kwfgrid.gworkflowdl.structure.*;
4
5 /***
6 * Created by IntelliJ IDEA.
7 * User: hans
8 * Date: 14.10.2005
9 * Time: 16:42:47
10 * To change this template use File | Settings | File Templates.
11 */
12 public class ContactFree {
13
14 public static boolean isConactFree(Workflow wf) {
15 Place[] ps = wf.getPlaces();
16 boolean ret = true;
17 for (int i = 0; i < ps.length; i++) {
18 Place p = ps[i];
19 if (p.getCapacity() != Place.DEFAULT_CAPACITY) {
20 ret = false;
21 break;
22 }
23 }
24 return ret;
25 }
26
27 private static Place addCoPlace(Workflow wf, Place p) {
28
29 String id = "co-" + p.getID();
30 Place[] ps = wf.getPlaces();
31 boolean flag = true;
32 while (flag) {
33 boolean exists = false;
34 for (int i = 0; i < ps.length; i++) {
35 if (ps[i].getID().equals(id)) {
36 exists = true;
37 break;
38 }
39 }
40 if (exists) {
41 id = "co" + id;
42 } else {
43 flag = false;
44 }
45 }
46 Place cop = Factory.newPlace();
47 cop.setID(id);
48 wf.addPlace(cop);
49 return cop;
50 }
51
52 public static void makeContactFree(Workflow wf) {
53 Transition[] ts = wf.getTransitions();
54 Place[] ps = wf.getPlaces();
55 for (int i = 0; i < ps.length; i++) {
56 Place p = ps[i];
57 int cap = p.getCapacity();
58 if (cap != Place.DEFAULT_CAPACITY) {
59
60
61
62
63
64
65 Place cop = addCoPlace(wf, p);
66 int tnum = ps[i].getTokenNumber();
67 try {
68 for (int j = 0; j < cap - tnum; j++) {
69 Token t = Factory.newToken();
70
71
72
73
74
75 cop.addToken(t);
76 }
77 ps[i].setCapacity(Place.DEFAULT_CAPACITY);
78 } catch (CapacityException e) {
79
80 }
81 for (int j = 0; j < ts.length; j++) {
82 Edge[] in = ts[j].getInEdges();
83 Edge[] out = ts[j].getOutEdges();
84 for (int k = 0; k < in.length; k++) {
85 Place inp = in[k].getPlace();
86 if (inp.getID().equals(p.getID())) {
87 Edge oute = Factory.newEdge();
88 oute.setPlace(cop);
89 ts[j].addOutEdge(oute);
90 }
91 }
92 for (int k = 0; k < out.length; k++) {
93 Place outp = out[k].getPlace();
94 if (outp.getID().equals(p.getID())) {
95 Edge ine = Factory.newEdge();
96 ine.setPlace(cop);
97 ts[j].addInEdge(ine);
98 }
99 }
100 }
101 }
102 }
103
104 }
105 }
106
107