Skip to content
Snippets Groups Projects
Commit 2d182793 authored by “Khaoula's avatar “Khaoula
Browse files

Petri Net avec les types d'arcs, le Hashset pour les arcs sans Test Main

parent 4bc6c7d7
No related branches found
No related tags found
No related merge requests found
...@@ -20,8 +20,8 @@ public class MainPetriNet { ...@@ -20,8 +20,8 @@ public class MainPetriNet {
// Create arcs // Create arcs
Arc_ENTRANT a1 = new Arc_entrant_simple(p1, t1, 1, 1); Arc_ENTRANT a1 = new Arc_entrant_simple(p1, t1, 1, 1);
Arc_SORTANT a2 = new Arc_SORTANT(p2, t1, 1, 2); Arc_SORTANT a2 = new Arc_SORTANT(p2, t1, 1, 2);
Arc_ENTRANT a3 = new Arc_ENTRANT(p2, t2, 1); Arc_ENTRANT a3 = new Arc_entrant_simple(p2, t2, 1, 3);
Arc_SORTANT a4 = new Arc_SORTANT(p3, t2, 1); Arc_SORTANT a4 = new Arc_SORTANT(p3, t2, 1, 4);
// Add arcs to transitions // Add arcs to transitions
t1.ajouterArc_ENTRANT(a1); t1.ajouterArc_ENTRANT(a1);
...@@ -29,11 +29,11 @@ public class MainPetriNet { ...@@ -29,11 +29,11 @@ public class MainPetriNet {
t2.ajouterArc_ENTRANT(a3); t2.ajouterArc_ENTRANT(a3);
t2.ajouterArc_SORTANT(a4); t2.ajouterArc_SORTANT(a4);
// Add arcs to places // Add a place to each arc
//p1.addArc(a1); a1.setPlace(p1);
//p2.addArc(a2); a2.setPlace(p2);
//p2.addArc(a3); a3.setPlace(p2);
//p3.addArc(a4); a4.setPlace(p3);
// Add places and transitions to the Petri net // Add places and transitions to the Petri net
reseauPerti.ajouterPlace(p1); reseauPerti.ajouterPlace(p1);
...@@ -45,19 +45,13 @@ public class MainPetriNet { ...@@ -45,19 +45,13 @@ public class MainPetriNet {
// Display the Petri net // Display the Petri net
reseauPerti.afficherEtat(); reseauPerti.afficherEtat();
// Test the est_tirable method
System.out.println("t1 est tirable : " + t1.est_tirable());
System.out.println("t2 est tirable : " + t2.est_tirable());
// Test the tirer method // Test the tirer method
if (t1.est_tirable()) { // if (t1.est_tirable()) {
reseauPerti.tirerTransition(t1); // reseauPerti.tirerTransition(t1);
} // }
if (t2.est_tirable()) { // if (t2.est_tirable()) {
reseauPerti.tirerTransition(t2); // reseauPerti.tirerTransition(t2);
} // }
// Display the Petri net again
reseauPerti.afficherEtat();
} }
} }
\ No newline at end of file
...@@ -141,12 +141,12 @@ public class ReseauPerti implements PetriNetService { ...@@ -141,12 +141,12 @@ public class ReseauPerti implements PetriNetService {
* relier les arcs aux places et aux transitions par des flèches * relier les arcs aux places et aux transitions par des flèches
*/ */
// afficher Petri Net // // afficher Petri Net
System.out.println("Petri Net : "); // System.out.println("Petri Net : ");
// afficher les places, les arcs, le poid et les transitions // // afficher les places, les arcs, le poids et les transitions
for (Arc arc : arcs) { // for (Arc arc : arcs) {
System.out.println("Arc : " + arc.getPlace().getId() + " -> " + arc.getTransition().getId() + " : " + arc.getPoids()); // System.out.println("Arc : " + arc.getPlace().getId() + " -> " + arc.getTransition().getId() + " : " + arc.getPoids());
} // }
} }
......
...@@ -70,19 +70,31 @@ public class Transition { ...@@ -70,19 +70,31 @@ public class Transition {
est_tirable(); est_tirable();
// print the list of arcs entrants tirables List<String> arcs_ENTRANTS_TIRABLE_String = Arcs_ENTRANTS_TIRABLE_toString();
System.out.println("Arcs entrants tirable: " + this.arcs_ENTRANTS_TIRABLE
+ "Saisir l'arc entrant à tirer: ");
// copilot get input from user of the id of the arc entrant to tirer (java.util.Scanner) // print the list of arcs entrants tirables
System.out.println("Arcs entrants tirable: " + arcs_ENTRANTS_TIRABLE_String
+ "Saisir l'arc entrant à tirer: ");
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
int id = scanner.nextInt();
// find the Arc_ENTRANT by id
Arc_ENTRANT arc_ENTRANT_toTirer = null; int id;
for (Arc_ENTRANT arc_ENTRANT : this.arcs_ENTRANTS_TIRABLE) { Arc_ENTRANT arc_ENTRANT_toTirer;
if (arc_ENTRANT.getId() == id) {
arc_ENTRANT_toTirer = arc_ENTRANT; // Get the input from user of the id of the arc entrant to tirer (java.util.Scanner)
while (true) {
System.out.print("Enter the id: ");
String input = scanner.next();
try {
id = Integer.parseInt(input);
if (arcs_ENTRANTS_TIRABLE_String.contains(String.valueOf(id))) {
arc_ENTRANT_toTirer = arcs_ENTRANTS_TIRABLE.get(arcs_ENTRANTS_TIRABLE_String.indexOf(String.valueOf(id)));
break;
} else {
System.out.println("Invalid id. Please enter a valid id.");
}
} catch (NumberFormatException e) {
System.out.println("Invalid id. Please enter a valid integer.");
} }
} }
...@@ -93,5 +105,16 @@ public class Transition { ...@@ -93,5 +105,16 @@ public class Transition {
arc_SORTANT.valider(); arc_SORTANT.valider();
} }
System.out.println("Transition tirée avec succès");
}
// Add a method to get the list of arcs entrants tirable en String
public List<String> Arcs_ENTRANTS_TIRABLE_toString() {
List<String> arcs_ENTRANTS_TIRABLE_String = new ArrayList<String>();
for (Arc_ENTRANT arc_ENTRANT : arcs_ENTRANTS_TIRABLE) {
arcs_ENTRANTS_TIRABLE_String.add(String.valueOf(arc_ENTRANT.getId()));
}
return arcs_ENTRANTS_TIRABLE_String;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment