import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; public class Simulation { private static final int TRAVEL_TIME = 1000; private static final int Port_TIME = 500; private static final int BUSY_TIME = 3000; private static final int NUM_Bateau = 1; private static final int Bateau_CAPACITY = 2; private static final int NUM_PortS = 5; public static final int PORT = 4321; public static void main(String args[]) throws InterruptedException { Zonemarine office = new Zonemarine(NUM_PortS, NUM_Bateau, Bateau_CAPACITY, Port_TIME, TRAVEL_TIME); int[] p1Itinerary = { ((int)(Math.random() * 4 + 1)), ((int)(Math.random() * 4 + 1)), ((int)(Math.random() * 4 + 1)), ((int)(Math.random() * 4 + 1)), 0 }; int[] p2Itinerary = { ((int)(Math.random() * 4 + 1)), ((int)(Math.random() * 4 + 1)), ((int)(Math.random() * 4 + 1)), ((int)(Math.random() * 4 + 1)), 0 }; int[] p3Itinerary = { ((int)(Math.random() * 4 + 1)), ((int)(Math.random() * 4 + 1)), ((int)(Math.random() * 4 + 1)), ((int)(Math.random() * 4 + 1)), 0 }; int[] p4Itinerary = { ((int)(Math.random() * 4 + 1)), ((int)(Math.random() * 4 + 1)), ((int)(Math.random() * 4 + 1)), ((int)(Math.random() * 4 + 1)), 0 }; Vehicule P1 = new Vehicule("V1", p1Itinerary, BUSY_TIME, 0, office); Vehicule P2 = new Vehicule("V2", p2Itinerary, BUSY_TIME, 0, office); Vehicule P3 = new Vehicule("V3", p3Itinerary, BUSY_TIME, 0, office); Vehicule P4 = new Vehicule("V4", p4Itinerary, BUSY_TIME, 0, office); //////server///////////////////// ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(PORT); System.out.println("Server started."); while(true) { Socket socket = serverSocket.accept(); office.startBateau(); //P1.start(); //P2.start(); //P3.start(); //P4.start(); long startTime = System.currentTimeMillis(); P1.join(); P2.join(); //P3.join(); //P4.join(); long elapsedTime = System.currentTimeMillis()-(System.currentTimeMillis() - startTime); System.out.println(" temps total de la simulation: " + (elapsedTime- startTime) + " ms"); } } catch (Exception e) { e.printStackTrace(); } finally { try { serverSocket.close(); } catch (IOException e) { } } //////server///////////////////// } }