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 {
// 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
......@@ -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());
// }
}
......
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment