diff --git a/src/main/java/org/petriNet/MainPetriNet.java b/src/main/java/org/petriNet/MainPetriNet.java index 2db6eea88082f4192d9d31907080d0f7d49526ae..d5078a636a4f7849febfa0f57ba62712f406e9b7 100644 --- a/src/main/java/org/petriNet/MainPetriNet.java +++ b/src/main/java/org/petriNet/MainPetriNet.java @@ -20,8 +20,8 @@ public class MainPetriNet { // Create arcs Arc_ENTRANT a1 = new Arc_entrant_simple(p1, t1, 1, 1); Arc_SORTANT a2 = new Arc_SORTANT(p2, t1, 1, 2); - Arc_ENTRANT a3 = new Arc_ENTRANT(p2, t2, 1); - Arc_SORTANT a4 = new Arc_SORTANT(p3, t2, 1); + Arc_ENTRANT a3 = new Arc_entrant_simple(p2, t2, 1, 3); + Arc_SORTANT a4 = new Arc_SORTANT(p3, t2, 1, 4); // Add arcs to transitions t1.ajouterArc_ENTRANT(a1); @@ -29,11 +29,11 @@ public class MainPetriNet { t2.ajouterArc_ENTRANT(a3); t2.ajouterArc_SORTANT(a4); - // Add arcs to places - //p1.addArc(a1); - //p2.addArc(a2); - //p2.addArc(a3); - //p3.addArc(a4); + // Add a place to each arc + a1.setPlace(p1); + a2.setPlace(p2); + a3.setPlace(p2); + a4.setPlace(p3); // Add places and transitions to the Petri net reseauPerti.ajouterPlace(p1); @@ -45,19 +45,13 @@ public class MainPetriNet { // Display the Petri net 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 - if (t1.est_tirable()) { - reseauPerti.tirerTransition(t1); - } - if (t2.est_tirable()) { - reseauPerti.tirerTransition(t2); - } - - // Display the Petri net again - reseauPerti.afficherEtat(); +// if (t1.est_tirable()) { +// reseauPerti.tirerTransition(t1); +// } +// if (t2.est_tirable()) { +// reseauPerti.tirerTransition(t2); +// } + } } \ No newline at end of file diff --git a/src/main/java/org/petriNet/ReseauPerti.java b/src/main/java/org/petriNet/ReseauPerti.java index 79f2b12442b82e8e51af60e7c8d4e8aa00ea8ff2..60e498b02e0ea2f68ffd5d07397d63a7ef83e22a 100644 --- a/src/main/java/org/petriNet/ReseauPerti.java +++ b/src/main/java/org/petriNet/ReseauPerti.java @@ -141,12 +141,12 @@ public class ReseauPerti implements PetriNetService { * relier les arcs aux places et aux transitions par des flèches */ - // afficher Petri Net - System.out.println("Petri Net : "); - // afficher les places, les arcs, le poid et les transitions - for (Arc arc : arcs) { - System.out.println("Arc : " + arc.getPlace().getId() + " -> " + arc.getTransition().getId() + " : " + arc.getPoids()); - } +// // afficher Petri Net +// System.out.println("Petri Net : "); +// // afficher les places, les arcs, le poids et les transitions +// for (Arc arc : arcs) { +// System.out.println("Arc : " + arc.getPlace().getId() + " -> " + arc.getTransition().getId() + " : " + arc.getPoids()); +// } } diff --git a/src/main/java/org/petriNet/Transition.java b/src/main/java/org/petriNet/Transition.java index 618e0dce2642aef44d8815be7edef317896cba68..e6f9a7323050f12a8411f9f722feb1d391720041 100644 --- a/src/main/java/org/petriNet/Transition.java +++ b/src/main/java/org/petriNet/Transition.java @@ -70,19 +70,31 @@ public class Transition { est_tirable(); - // print the list of arcs entrants tirables - System.out.println("Arcs entrants tirable: " + this.arcs_ENTRANTS_TIRABLE - + "Saisir l'arc entrant à tirer: "); + List<String> arcs_ENTRANTS_TIRABLE_String = Arcs_ENTRANTS_TIRABLE_toString(); - // 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); - int id = scanner.nextInt(); - // find the Arc_ENTRANT by id - Arc_ENTRANT arc_ENTRANT_toTirer = null; - for (Arc_ENTRANT arc_ENTRANT : this.arcs_ENTRANTS_TIRABLE) { - if (arc_ENTRANT.getId() == id) { - arc_ENTRANT_toTirer = arc_ENTRANT; + + int id; + Arc_ENTRANT arc_ENTRANT_toTirer; + + // 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 { 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; } }