Révision 2

Voir les différences:

petri/Readme.md
1
# Reseau de Petri
2
binome 2 Sean/Amaury
3

  
4
## Note de conception
5
Nous avons procédé à quelques modification par rapport a notre conception initiale.
6

  
7
Ainsi nous avons ajouté une methode *equals* aux classes arc et place. Ces methodes servent pour deleteArc() et deletePLace()
8

  
9
Nous avons également rajouté des methodes *toString* afin d'avoir une meilleur visibilité pour nos tests.
10

  
11
Nous avons aussi déclaré des constante ArcEntering, ArcOutering, qui sont des entier pour que lors de la declaration des arc le choix soit clair.
12

  
13
## Execution du code
14
Nous avons réalisé des tests "manuel" pour chaque classe et leurs methodes réspectivent. Pour les excuter il *faut executer la methode main de la classe*.
15

  
16

  
17
**Liste des tests effectuées :**
18
* place: changeToken(int i), isempty(), equals(),
19
* pour chaque classe Arc : isAtcive(), isPullable(), doTranstion() et equals(),
20
* transition : isPullable(),doTransition(),
21
* network : cas simple a 2 arc et 1 une transition, deletPlace(place),deleteArc(arc), deleteTransition(transtion), et les methodes add
22

  
petri/.settings/org.eclipse.jdt.core.prefs
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5
org.eclipse.jdt.core.compiler.compliance=1.8
6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11
org.eclipse.jdt.core.compiler.source=1.8
0 12

  
petri/.classpath
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4
	<classpathentry kind="src" path="src"/>
5
	<classpathentry kind="output" path="bin"/>
6
</classpath>
0 7

  
petri/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>petri</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
	</buildSpec>
14
	<natures>
15
		<nature>org.eclipse.jdt.core.javanature</nature>
16
	</natures>
17
</projectDescription>
0 18

  
petri/src/main/ArcInterface.java
1
package main;
2

  
3
public interface ArcInterface {
4
	
5
	public void doTransition();
6
	public boolean isPullable();
7
	public boolean isActive();
8

  
9
}
0 10

  
petri/src/main/Network.java
1
package main;
2

  
3

  
4
import java.util.ArrayList;
5
import java.util.List;
6

  
7
public class Network {
8
	public static int ArcOutering = 2;
9
	public static int ArcCleaner = 1;
10
	public static int ArcZero = 0;
11
	public static int ArcEntering = 3;
12
	
13
	private List<Place> placeList;
14
	private List<Transition> listTransition;	
15
	public Network() {
16
		this.placeList=new ArrayList<Place>();
17
		this.listTransition=new ArrayList<Transition>();
18

  
19
	}
20

  
21

  
22
	public void addTransition() {
23
		Transition transition = new Transition();
24
		listTransition.add(transition);
25
	}
26
	public void addPlace(int value) {
27
		Place place = new Place(value);
28
		placeList.add(place);
29
	}
30

  
31
	public void addArc(Transition transition, Place place, int value, int identifier) {
32

  
33
		if (identifier==ArcZero) {
34
			transition.getArcList().add(new ArcZero(place, value));
35
		}
36
		else if(identifier==ArcCleaner) {
37
			transition.getArcList().add(new ArcCleaner(place));
38
		}
39
		else if(identifier==ArcOutering) {
40
			transition.getArcList().add(new ArcOutering(place,value));			
41
		}else if(identifier==ArcEntering) {
42
			transition.getArcList().add( new ArcEntering(place,value));
43
		}
44

  
45
	}
46
	public void deleteArc(Arc a) {
47
		for(Transition transition: listTransition) {
48
			for(Arc arc:transition.getArcList()) {
49
				if(arc.equals(a)) {
50
					transition.getArcList().remove(arc);
51
				}
52
			}
53
			
54
		}
55

  
56
	}
57
	
58
	public void deletePlace( Place place) {
59
		for(Transition transition: listTransition) {
60
			for(Arc arc:transition.getArcList()) {
61
				if(arc.getPlace().equals(place)) {
62
					deleteArc( arc);
63
					placeList.remove(place);
64
				}
65
			}
66
			
67
		}
68
		
69
	}
70
	
71
	public void deleteTransition(Transition transition) {
72
	
73
		listTransition.remove(transition);
74
	}
75

  
76
	public void fire(Transition transition) {
77
		if (transition.isPullable()==true) {
78
			transition.doTransition();
79
		}
80
	}
81
	public String toString() {
82
		String res= "[";
83
		for(int i=0;listTransition.size()>i;i++ ) {
84
			res=res+"transtion "+i+" :"+listTransition.get(i).toString()+", ";
85
		}
86
		res=res+"]";
87
		return res;
88
	}
89
	public static void main(String[] args) {
90
		
91
		Network n0=new Network();
92
		n0.addPlace(5);
93
		n0.addPlace(4);
94
		n0.addTransition();
95
		n0.addArc(n0.listTransition.get(0), n0.placeList.get(0), 2, ArcEntering);
96
		n0.addArc(n0.listTransition.get(0), n0.placeList.get(1), 2, ArcOutering);
97
		System.out.println("");
98
		System.out.println("TEST 1 une transtion, un arcOutering un arcEntering");
99
		System.out.println("");
100
		System.out.println("situtation initial : ");
101
		System.out.println(n0);
102
		
103
		System.out.println("fire 1 : ");
104
		n0.fire(n0.listTransition.get(0));
105
		System.out.println(n0);
106
		
107
		System.out.println("fire 2 : ");
108
		n0.fire(n0.listTransition.get(0));
109
		System.out.println(n0);
110
		
111
		System.out.println("fire 3 : ");
112
		n0.fire(n0.listTransition.get(0));
113
		System.out.println(n0);
114
		
115
		
116
		Network n3=new Network();
117
		n3.addPlace(5);
118
		n3.addPlace(4);
119
		n3.addTransition();
120
		n3.addArc(n3.listTransition.get(0), n3.placeList.get(0), 2, ArcEntering);
121
		n3.addArc(n3.listTransition.get(0), n3.placeList.get(1), 2, ArcOutering);
122
		System.out.println("");
123
		System.out.println("TEST 2 delete place ");
124
		System.out.println("");
125
		System.out.println("BEFORE :");
126
		System.out.println(n3);
127
		System.out.println(n3.placeList);
128
		n3.deletePlace(n3.placeList.get(0));
129
		System.out.println("AFTER :");
130
		System.out.println(n3);
131
		System.out.println(n3.placeList);
132
		
133
		Network n1=new Network();
134
		n1.addPlace(5);
135
		n1.addPlace(4);
136
		n1.addTransition();
137
		n1.addArc(n1.listTransition.get(0), n1.placeList.get(0), 2, ArcEntering);
138
		n1.addArc(n1.listTransition.get(0), n1.placeList.get(1), 2, ArcOutering);
139
		
140
		System.out.println("");
141
		System.out.println("TEST 3 delete arc ");
142
		System.out.println("");
143
		System.out.println("BEFORE :");
144
		System.out.println(n1);
145
		System.out.println("liste des place :"+n1.placeList);
146
		n1.deleteArc(n1.listTransition.get(0).getArcList().get(0));
147
		System.out.println("AFTER :");
148
		System.out.println(n1);
149
		System.out.println("liste des place :"+n1.placeList);
150
		
151
		Network n2=new Network();
152
		n2.addPlace(5);
153
		n2.addPlace(4);
154
		n2.addTransition();
155
		n2.addArc(n2.listTransition.get(0), n2.placeList.get(0), 2, ArcEntering);
156
		n2.addArc(n2.listTransition.get(0), n2.placeList.get(1), 2, ArcOutering);
157
		
158
		System.out.println("");
159
		System.out.println("TEST 4 delete transition ");
160
		System.out.println("");
161
		System.out.println("BEFORE :");
162
		System.out.println(n2);
163
		System.out.println("liste des place :"+n2.placeList);
164
		n2.deleteTransition(n2.listTransition.get(0));
165
		System.out.println("AFTER :");
166
		System.out.println(n2);
167
		System.out.println("liste des place :"+n2.placeList);
168
		
169
		
170

  
171
	}
172

  
173
}
0 174

  
petri/src/main/Transition.java
1
package main;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
public class Transition {
7
	
8
	
9
	private List<Arc> arcList;
10
	
11
	public String toString() {
12
		String res= " [";
13
		for(int i=0;arcList.size()>i;i++ ) {
14
			res=res+arcList.get(i).toString()+" // ";
15
		}
16
		res=res+"] ";
17
		return res;
18
	}
19

  
20
	public Transition() {
21
		this.arcList=new ArrayList<Arc>();
22
	}
23
	
24

  
25
	public boolean isPullable() {
26
		int i=0;
27
		boolean res=true;
28
		while(i<this.arcList.size() && res==true) {
29
			res=this.arcList.get(i).isPullable();
30
			i=i+1;
31
		}
32
		return res;
33
	}
34
	
35
	public void doTransition() {
36
		if (this.isPullable()==true) {
37
			for (int i=0; i<arcList.size();i++) {
38
				arcList.get(i).doTransition();
39
			}
40
		}
41
	}
42
	public List<Arc> getArcList(){
43
		return this.arcList;
44
	}
45
	public static void main(String[] args) {
46
		System.out.println("TEST METHODS TRANSITION");
47
		
48
		Transition t1=new Transition();
49
		t1.arcList.add(new ArcOutering(new Place(4), 2));
50
		t1.arcList.add(new ArcEntering(new Place(4), 1));
51

  
52
		Transition t2=new Transition();
53
		t2.arcList.add(new ArcOutering(new Place(2), 3));
54
		t2.arcList.add(new ArcEntering(new Place(2), 3));
55
	
56
		System.out.println(" => method isPullable()");
57

  
58
		System.out.println(t1);
59
		System.out.println("true : "+t1.isPullable());
60
		System.out.println(t2);
61
		System.out.println("false : "+t2.isPullable());
62
		
63
		System.out.println(" => method doTranstion()");
64
		System.out.println("before : "+t1);
65
		t1.doTransition();
66
		System.out.println("after  : "+t1);
67

  
68

  
69
	}
70
}
0 71

  
petri/src/main/ArcCleaner.java
1
package main;
2

  
3
public class ArcCleaner extends Arc{
4
	
5

  
6
	public ArcCleaner(Place place) {
7
		super(place);
8
	
9
	}
10
	
11
	public void doTransition() {
12
		if (this.isActive()==true) {
13
			this.getPlace().changeToken(-this.getPlace().getToken());
14
		}
15
	}
16
	
17
	public boolean isActive() {
18
		return (this.getPlace().getToken()>0);
19
	}
20
	
21
	public boolean isPullable() {
22
		return this.isActive();
23
	}
24
	public String toString() {
25
		return "ArcCleaner,"+this.getPlace();
26
	}
27
	public static void main(String[] args) {
28
		System.out.println("TEST METHODS ARCCLEANER");
29
		
30
		System.out.println(" => method isActive()");
31
		Place emptyPlace = new Place(0);
32
		ArcCleaner arcc1 = new ArcCleaner(emptyPlace);
33
		Place place3 = new Place(3);
34
		ArcCleaner arcc2 = new ArcCleaner(place3);
35
		System.out.println("false : "+arcc1.isActive());
36
		System.out.println("true : "+arcc2.isActive());
37

  
38
	
39
		System.out.println(" => method isPullable()");
40
		System.out.println(arcc1);
41
		System.out.println("false : "+arcc1.isPullable());
42
		System.out.println(arcc2);
43
		System.out.println("true : "+arcc2.isPullable());
44

  
45
		System.out.println(" => method doTranstion()");
46
		System.out.println("before : "+arcc2);
47
		arcc2.doTransition();
48
		System.out.println("after  : "+arcc2);
49

  
50
	}
51
	
52
	
53

  
54
}
0 55

  
petri/src/main/ArcEntering.java
1
package main;
2

  
3
public class ArcEntering extends Arc{
4
	
5
	private int value;
6

  
7
	public ArcEntering(Place place, int value) {
8
		super(place);
9
		// TODO Auto-generated constructor stub
10
		this.value=value;
11
	}
12
	
13
	public void doTransition() {
14
		this.getPlace().changeToken(this.value);
15
	}
16
	
17
	public boolean isActive() {
18
		return true;
19
	}
20
	
21
	public boolean isPullable() {
22
		return true;
23
	}
24
	public String toString() {
25
		return "ArcEntering value:"+value+", "+this.getPlace();
26
	}
27
	public static void main(String[] args) {
28
		System.out.println("TEST METHODS ARCENTERING");
29
		
30
		System.out.println(" => method isActive()");
31
		Place emptyPlace = new Place(0);
32
		ArcEntering arce = new ArcEntering(emptyPlace, 3);
33
		System.out.println("true : "+arce.isActive());
34

  
35
	
36
		System.out.println(" => method isPullable()");
37
		Place place3 = new Place(3);
38
		ArcEntering arce2 = new ArcEntering(place3, 2);
39
		ArcEntering arce4 = new ArcEntering(place3, 4);
40
		System.out.println(arce2);
41
		System.out.println("true : "+arce2.isPullable());
42
		System.out.println(arce4);
43
		System.out.println("true : "+arce4.isPullable());
44
		
45
		System.out.println(" => method doTranstion()");
46
		System.out.println("before : "+arce2);
47
		arce2.doTransition();
48
		System.out.println("after  : "+arce2);
49
		System.out.println(" => method equals()");
50
		// the method equals is test here because arc is an abstract method
51
		System.out.println("true : "+arce2.equals(arce2));
52
		System.out.println("false : "+arce2.equals(arce4));
53
	}
54
	
55

  
56
}
0 57

  
petri/src/main/ArcOutering.java
1
package main;
2

  
3
public class ArcOutering extends Arc{
4
	
5
	private int value;
6

  
7
	public ArcOutering(Place place, int value) {
8
		super(place);
9
		this.value=value;
10
	}
11
	public String toString() {
12
		return "ArcOutering value:"+value+", "+this.getPlace();
13
	}
14
	
15
	public void doTransition() {
16
		this.getPlace().changeToken(this.value*(-1));
17
	}
18
	
19
	public boolean isActive() {
20
		return true;
21
	}
22
	
23
	public boolean isPullable() {
24
		return (this.getPlace().getToken()>=value);
25
	}
26
	public static void main(String[] args) {
27
		System.out.println("TEST METHODS ARCOUTERING");
28
		
29
		System.out.println(" => method isActive()");
30
		Place emptyPlace = new Place(0);
31
		ArcOutering arco = new ArcOutering(emptyPlace, 3);
32
		System.out.println("true : "+arco.isActive());
33

  
34
	
35
		System.out.println(" => method isPullable()");
36
		Place place3 = new Place(3);
37
		ArcOutering arco2 = new ArcOutering(place3, 2);
38
		ArcOutering arco4 = new ArcOutering(place3, 4);
39
		System.out.println(arco2);
40
		System.out.println("true : "+arco2.isPullable());
41
		System.out.println(arco4);
42
		System.out.println("false : "+arco4.isPullable());
43
		
44
		System.out.println(" => method doTranstion()");
45
		System.out.println("before : "+arco2);
46
		arco2.doTransition();
47
		System.out.println("after  : "+arco2);
48
		System.out.println(" => method equals()");
49
		// the method equals is test here because arc is an abstract method
50
		System.out.println("true : "+arco2.equals(arco2));
51
		System.out.println("false : "+arco2.equals(arco4));
52
	}
53

  
54

  
55
}
0 56

  
petri/src/main/Place.java
1
package main;
2

  
3
public class Place {
4
	
5
	private int token;
6
	
7
	public Place(int token) {
8
		this.token=token;
9
	}
10
	
11
	public int getToken() {
12
		return this.token;
13
	}
14
	public String toString() {
15
		return "Place Token : "+token;
16
	}
17
	
18
	public boolean isEmpty() {
19
		return (this.token==0);
20
	}
21
	
22
	public void changeToken(int i) {
23
		token += i;
24
	}
25
	
26
	public boolean equals(Object o) {
27
		if((o instanceof Place) &&(System.identityHashCode(((Place)o))==System.identityHashCode(this))) {
28
			return true;
29
		}
30
		else {
31
			return false;
32
		}
33
	}
34
	public static void main(String[] args) {
35
		System.out.println("TEST METHODS PLACE");
36
		
37
		System.out.println(" => method isEmpty()");
38
		Place emptyPlace = new Place(0);
39
		System.out.println("true : "+emptyPlace.isEmpty());
40
		Place notEmptyPlace = new Place(2);
41
		System.out.println("true : "+notEmptyPlace.isEmpty());
42
	
43
		System.out.println(" => method changeToken(int i)");
44
		Place place3 = new Place(3);
45
		place3.changeToken(5);
46
		System.out.println("3 + 5 = "+place3.getToken());
47
		place3.changeToken(-4);
48
		System.out.println("8 - 4 = "+place3.getToken());
49
		
50
		System.out.println(" => method equals()");
51
		Place place1 = new Place(0);
52
		Place place2 = new Place(0);
53
		System.out.println("true : "+place1.equals(place1));
54
		System.out.println("false : "+place1.equals(place2));
55
	}
56

  
57
}
0 58

  
petri/src/main/Arc.java
1
package main;
2

  
3
public abstract class Arc implements ArcInterface {
4
	
5
	private Place place;
6
	
7
	public Arc(Place place) {
8
		this.place=place;
9
	}
10
	
11
	public Place getPlace() {
12
		return this.place;
13
	}
14
	public boolean equals(Object o) {
15
		if((o instanceof Arc) &&(System.identityHashCode(((Arc)o))==System.identityHashCode(this))) {
16
			return true;
17
		}
18
		else {
19
			return false;
20
		}
21
		
22
	}
23

  
24
}
0 25

  
petri/src/main/ArcZero.java
1
package main;
2

  
3
public class ArcZero extends ArcOutering {
4
	
5
	public ArcZero(Place place, int value) {
6
		super(place, value);
7
		// TODO Auto-generated constructor stub
8
	}
9
	
10
	public void doTransition() {
11
	}
12
	public boolean isActive() {
13
		return (this.getPlace().getToken()==0);
14
	}
15
	public boolean isPullable() {
16
		return this.isActive();
17
	}
18
	public String toString() {
19
		return "ArcZero, "+this.getPlace(); 
20
	}
21
	public static void main(String[] args) {
22
		System.out.println("TEST METHODS ARCZERO");
23
		
24
		System.out.println(" => method isActive()");
25
		Place emptyPlace = new Place(0);
26
		ArcZero arcc1 = new ArcZero(emptyPlace,2);
27
		Place place3 = new Place(3);
28
		ArcZero arcc2 = new ArcZero(place3,2);
29
		System.out.println(arcc1);
30
		System.out.println("true : "+arcc1.isActive());
31
		System.out.println(arcc2);
32
		System.out.println("false : "+arcc2.isActive());
33

  
34
	
35
		System.out.println(" => method isPullable()");
36
		System.out.println(arcc1);
37
		System.out.println("false : "+arcc1.isPullable());
38
		System.out.println(arcc2);
39
		System.out.println("true : "+arcc2.isPullable());
40

  
41
		System.out.println(" => method doTranstion()");
42
		System.out.println("before : "+arcc2);
43
		arcc2.doTransition();
44
		System.out.println("after  : "+arcc2);
45

  
46
	}
47

  
48
}
0 49

  

Formats disponibles : Unified diff