Révision 5 petri/src/main/Network.java
Network.java | ||
---|---|---|
18 | 18 |
public static int ArcCleaner = 1; |
19 | 19 |
public static int ArcZero = 0; |
20 | 20 |
public static int ArcEntering = 3; |
21 |
|
|
21 |
|
|
22 | 22 |
private List<Place> placeList; |
23 | 23 |
private List<Transition> listTransition; |
24 | 24 |
public Network() { |
... | ... | |
36 | 36 |
Place place = new Place(value); |
37 | 37 |
placeList.add(place); |
38 | 38 |
} |
39 |
@SuppressWarnings("serial") |
|
40 |
public class UndefinedIdentifier extends Exception{ |
|
41 |
public UndefinedIdentifier() { |
|
42 |
super("the identifier cannot take this value"); |
|
43 |
} |
|
39 | 44 |
|
40 |
public void addArc(Transition transition, Place place, int value, int identifier) { |
|
45 |
} |
|
46 |
public void addArc(Transition transition, Place place, int value, int identifier) throws UndefinedIdentifier { |
|
41 | 47 |
|
42 | 48 |
if (identifier==ArcZero) { |
43 | 49 |
transition.getArcList().add(new ArcZero(place, value)); |
... | ... | |
49 | 55 |
transition.getArcList().add(new ArcOutering(place,value)); |
50 | 56 |
}else if(identifier==ArcEntering) { |
51 | 57 |
transition.getArcList().add( new ArcEntering(place,value)); |
58 |
}else { |
|
59 |
throw new UndefinedIdentifier(); |
|
52 | 60 |
} |
53 | 61 |
|
54 | 62 |
} |
55 | 63 |
public void deleteArc(Arc a) { |
64 |
Arc aToDelete = null; |
|
56 | 65 |
for(Transition transition: listTransition) { |
57 | 66 |
for(Arc arc:transition.getArcList()) { |
58 | 67 |
if(arc.equals(a)) { |
59 |
transition.getArcList().remove(arc); |
|
60 |
} |
|
68 |
aToDelete=arc; } |
|
61 | 69 |
} |
62 |
|
|
70 |
transition.getArcList().remove(aToDelete); |
|
63 | 71 |
} |
64 | 72 |
|
65 | 73 |
} |
66 |
|
|
74 |
|
|
67 | 75 |
public void deletePlace( Place place) { |
76 |
Arc aToDelete = null; |
|
68 | 77 |
for(Transition transition: listTransition) { |
69 | 78 |
for(Arc arc:transition.getArcList()) { |
70 | 79 |
if(arc.getPlace().equals(place)) { |
71 |
deleteArc( arc); |
|
72 |
placeList.remove(place); |
|
80 |
aToDelete=arc; |
|
73 | 81 |
} |
74 | 82 |
} |
75 |
|
|
83 |
deleteArc( aToDelete); |
|
84 |
placeList.remove(place); |
|
85 |
|
|
76 | 86 |
} |
77 |
|
|
87 |
|
|
78 | 88 |
} |
79 |
|
|
89 |
|
|
80 | 90 |
public void deleteTransition(Transition transition) { |
81 |
|
|
91 |
|
|
82 | 92 |
listTransition.remove(transition); |
83 | 93 |
} |
84 | 94 |
|
... | ... | |
95 | 105 |
res=res+"]"; |
96 | 106 |
return res; |
97 | 107 |
} |
98 |
public static void main(String[] args) throws UndefinedToken { |
|
99 |
|
|
108 |
public static void main(String[] args) throws UndefinedToken, UndefinedIdentifier {
|
|
109 |
|
|
100 | 110 |
Network n0=new Network(); |
101 | 111 |
n0.addPlace(5); |
102 | 112 |
n0.addPlace(4); |
... | ... | |
104 | 114 |
n0.addArc(n0.listTransition.get(0), n0.placeList.get(0), 2, ArcEntering); |
105 | 115 |
n0.addArc(n0.listTransition.get(0), n0.placeList.get(1), 2, ArcOutering); |
106 | 116 |
System.out.println(""); |
107 |
System.out.println("TEST 1 une transtion, un arcOutering un arcEntering");
|
|
117 |
System.out.println("RESEAU DE PETRI une transtion, un arcOutering un arcEntering");
|
|
108 | 118 |
System.out.println(""); |
109 | 119 |
System.out.println("situtation initial : "); |
110 | 120 |
System.out.println(n0); |
111 |
|
|
121 |
|
|
112 | 122 |
System.out.println("fire 1 : "); |
113 | 123 |
n0.fire(n0.listTransition.get(0)); |
114 | 124 |
System.out.println(n0); |
115 |
|
|
125 |
|
|
116 | 126 |
System.out.println("fire 2 : "); |
117 | 127 |
n0.fire(n0.listTransition.get(0)); |
118 | 128 |
System.out.println(n0); |
119 |
|
|
129 |
|
|
120 | 130 |
System.out.println("fire 3 : "); |
121 | 131 |
n0.fire(n0.listTransition.get(0)); |
122 | 132 |
System.out.println(n0); |
123 |
|
|
124 |
|
|
125 |
Network n3=new Network(); |
|
126 |
n3.addPlace(5); |
|
127 |
n3.addPlace(4); |
|
128 |
n3.addTransition(); |
|
129 |
n3.addArc(n3.listTransition.get(0), n3.placeList.get(0), 2, ArcEntering); |
|
130 |
n3.addArc(n3.listTransition.get(0), n3.placeList.get(1), 2, ArcOutering); |
|
131 |
System.out.println(""); |
|
132 |
System.out.println("TEST 2 delete place "); |
|
133 |
System.out.println(""); |
|
134 |
System.out.println("BEFORE :"); |
|
135 |
System.out.println(n3); |
|
136 |
System.out.println(n3.placeList); |
|
137 |
n3.deletePlace(n3.placeList.get(0)); |
|
138 |
System.out.println("AFTER :"); |
|
139 |
System.out.println(n3); |
|
140 |
System.out.println(n3.placeList); |
|
141 |
|
|
142 |
Network n1=new Network(); |
|
143 |
n1.addPlace(5); |
|
144 |
n1.addPlace(4); |
|
145 |
n1.addTransition(); |
|
146 |
n1.addArc(n1.listTransition.get(0), n1.placeList.get(0), 2, ArcEntering); |
|
147 |
n1.addArc(n1.listTransition.get(0), n1.placeList.get(1), 2, ArcOutering); |
|
148 |
|
|
149 |
System.out.println(""); |
|
150 |
System.out.println("TEST 3 delete arc "); |
|
151 |
System.out.println(""); |
|
152 |
System.out.println("BEFORE :"); |
|
153 |
System.out.println(n1); |
|
154 |
System.out.println("liste des place :"+n1.placeList); |
|
155 |
n1.deleteArc(n1.listTransition.get(0).getArcList().get(0)); |
|
156 |
System.out.println("AFTER :"); |
|
157 |
System.out.println(n1); |
|
158 |
System.out.println("liste des place :"+n1.placeList); |
|
159 |
|
|
160 |
Network n2=new Network(); |
|
161 |
n2.addPlace(5); |
|
162 |
n2.addPlace(4); |
|
163 |
n2.addTransition(); |
|
164 |
n2.addArc(n2.listTransition.get(0), n2.placeList.get(0), 2, ArcEntering); |
|
165 |
n2.addArc(n2.listTransition.get(0), n2.placeList.get(1), 2, ArcOutering); |
|
166 |
|
|
167 |
System.out.println(""); |
|
168 |
System.out.println("TEST 4 delete transition "); |
|
169 |
System.out.println(""); |
|
170 |
System.out.println("BEFORE :"); |
|
171 |
System.out.println(n2); |
|
172 |
System.out.println("liste des place :"+n2.placeList); |
|
173 |
n2.deleteTransition(n2.listTransition.get(0)); |
|
174 |
System.out.println("AFTER :"); |
|
175 |
System.out.println(n2); |
|
176 |
System.out.println("liste des place :"+n2.placeList); |
|
177 |
|
|
178 |
|
|
179 | 133 |
|
134 |
|
|
180 | 135 |
} |
181 | 136 |
|
182 | 137 |
|
Formats disponibles : Unified diff