From 3e1b1f162cc447f8521b72623f8bd40a17d671ee Mon Sep 17 00:00:00 2001 From: Asaad Dadoush Date: Sat, 14 Nov 2020 16:31:43 +0300 Subject: [PATCH 1/3] Add UID for Sedan / SUV / Truck --- src/SUV.java | 15 ++++++++++++++- src/Sedan.java | 20 ++++++++++++++++++-- src/Truck.java | 16 +++++++++++++--- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/SUV.java b/src/SUV.java index 2da980e..21cdc81 100644 --- a/src/SUV.java +++ b/src/SUV.java @@ -1,16 +1,29 @@ public class SUV extends CivilVehicle { - + private String UID; + private static int numeberOfSUV; private final int TIME_TO_FIX = 15; //in minutes public static final int MAX_FORWARD = 1300; public SUV(double vehicleSize){ super(vehicleSize); + generateUID(); } public int getTimeToFix(){ return TIME_TO_FIX; } + + private void generateUID() { + numeberOfSUV++; + this.UID = String.format("SUV%04d", numeberOfSUV); + + } + + public String getUID(){ + return this.UID; + } + } diff --git a/src/Sedan.java b/src/Sedan.java index 3f9de04..a9d1280 100644 --- a/src/Sedan.java +++ b/src/Sedan.java @@ -1,14 +1,30 @@ public class Sedan extends CivilVehicle { + private String UID; + private static int numeberOfSedan; private final int TIME_TO_FIX = 15; //in minutes public static final int MAX_FORWARD = 1500; // Meter/Min public Sedan(double vehicleSize){ super(vehicleSize); + generateUID(); } - - public int getTimeToFix(){ return TIME_TO_FIX; } + @Override + public int getTimeToFix(){ return TIME_TO_FIX; + + } + + private void generateUID() { + numeberOfSedan++; + this.UID = String.format("Sedan%04d", numeberOfSedan); + + } + + public String getUID(){ + return this.UID; + } + } diff --git a/src/Truck.java b/src/Truck.java index 310d81a..0ccb4d5 100644 --- a/src/Truck.java +++ b/src/Truck.java @@ -1,15 +1,25 @@ public class Truck extends CivilVehicle { - + private String UID; + private static int numeberOfTruck; private final int TIME_TO_FIX = 20; //in minutes - + // public static final int MAX_FORWARD = ????; //TODO what is the speed here ?? public Truck(double vehicleSize){ super(vehicleSize); + generateUID(); } public int getTimeToFix(){ return TIME_TO_FIX; } + private void generateUID() { + numeberOfTruck++; + this.UID = String.format("Truck%04d", numeberOfTruck); + } + + public String getUID(){ + return this.UID; + } + } -} From bb46419ed3be081c0fc3bb6ab01c90381ba0c1d7 Mon Sep 17 00:00:00 2001 From: Asaad Dadoush Date: Sat, 14 Nov 2020 21:27:32 +0300 Subject: [PATCH 2/3] Report --- src/MakkahCity.java | 81 +++++++++++++++++++++++++++++--------------- src/StreetNames.java | 7 ++-- 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/src/MakkahCity.java b/src/MakkahCity.java index 70a6792..b5296f7 100644 --- a/src/MakkahCity.java +++ b/src/MakkahCity.java @@ -3,10 +3,9 @@ import java.util.*; public class MakkahCity { private static final ArrayList listOfCampaigns = new ArrayList<>(); - private static final ArrayList listOfVehicles = new ArrayList<>(); private static final Route[] stdRoutes = new Route[6]; - private static final Street[] stdStreet = new Street[8]; + private static final Street[] stdStreet = new Street[9]; private static final PDate timeManager = new PDate( new GregorianCalendar(2020, Calendar.JANUARY, 1, 4, 0, 0), @@ -20,7 +19,7 @@ public class MakkahCity { generateCamps(District.ALMANSOOR, (int)getRandom(110, 160)); generateCamps(District.ALHIJRA, (int)getRandom(80, 110)); - //fillBusesToList(); + fillBusesToList(); //Make Streets makeStreets(); @@ -46,6 +45,8 @@ public class MakkahCity { //Start of every 10min if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) % 10 == 0){ addCivilVehicleNoise(); + printReport(); + System.out.println(); } if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) == getRandom(0,59) @@ -80,20 +81,21 @@ public class MakkahCity { } } } - Vehicle v = listOfVehicles.get(10); - if (v.getCurrentStreet() != null) { - System.out.printf("St: %s distance: %f total: %f %s\n", - v.getCurrentStreet().getName(), - v.getCurrentLocation(), - v.getTotalDistanceTraveled(), - timeManager.getCurrentTime()); - } +// Vehicle v = listOfVehicles.get(150); +// if (v.getCurrentStreet() != null) { +// System.out.printf("St: %s distance: %f total: %f %s\n", +// v.getCurrentStreet().getName(), +// v.getCurrentLocation(), +// v.getTotalDistanceTraveled(), +// timeManager.getCurrentTime()); + //} + + + //noise based on time of day (From PDate) - //TODO: [5]Streets move forward. //TODO: Get real car values. - //TODO: Get real street lengths - //TODO: UID For all vehicles + /* Output: @@ -135,14 +137,15 @@ public class MakkahCity { } private static void makeStreets(){ - stdStreet[StreetNames.KA_STREET.ordinal()] = new Street(22700,3, StreetNames.KA_STREET); - stdStreet[StreetNames.FOURTH_HIGHWAY.ordinal()] = new Street(24600,4, StreetNames.FOURTH_HIGHWAY); - stdStreet[StreetNames.KUDAY.ordinal()] = new Street(22000,3, StreetNames.KUDAY); - stdStreet[StreetNames.STREET1.ordinal()] = new Street(4000,2, StreetNames.STREET1); - stdStreet[StreetNames.STREET2.ordinal()] = new Street(7000,2,StreetNames.STREET2); - stdStreet[StreetNames.STREET3.ordinal()] = new Street(400,2, StreetNames.STREET3); - stdStreet[StreetNames.STREET4.ordinal()] = new Street(8200,2,StreetNames.STREET4); - stdStreet[StreetNames.IBRAHIM_ALKHALIL.ordinal()] = new Street(100,2, StreetNames.IBRAHIM_ALKHALIL); //TODO: [7]Change numbers + stdStreet[StreetNames.KA_STREET.ordinal()] = new Street(4700,3, StreetNames.KA_STREET); + stdStreet[StreetNames.FOURTH_HIGHWAY.ordinal()] = new Street(9700,4, StreetNames.FOURTH_HIGHWAY); + stdStreet[StreetNames.THIRD_HIGHWAY.ordinal()] = new Street(8200,3, StreetNames.THIRD_HIGHWAY); + stdStreet[StreetNames.STREET1.ordinal()] = new Street(7800,3, StreetNames.STREET1); + stdStreet[StreetNames.STREET2.ordinal()] = new Street(2400,3,StreetNames.STREET2); + stdStreet[StreetNames.STREET3.ordinal()] = new Street(4800,2, StreetNames.STREET3); + stdStreet[StreetNames.STREET4.ordinal()] = new Street(3800,3,StreetNames.STREET4); + stdStreet[StreetNames.STREET5.ordinal()] = new Street(3200,2, StreetNames.STREET5); + stdStreet[StreetNames.IBRAHIM_ALKHALIL.ordinal()] = new Street(4500,3, StreetNames.IBRAHIM_ALKHALIL); } private static void makeRoutes() { @@ -151,7 +154,7 @@ public class MakkahCity { new Street[]{ stdStreet[StreetNames.STREET1.ordinal()], stdStreet[StreetNames.STREET2.ordinal()], - stdStreet[StreetNames.KUDAY.ordinal()]}, + stdStreet[StreetNames.THIRD_HIGHWAY.ordinal()]}, District.ALHIJRA, Mashier.ARAFAT); stdRoutes[RouteName.mashierToAlHijra2.ordinal()] = new Route(new Street[]{ @@ -172,8 +175,8 @@ public class MakkahCity { new Street[]{ stdStreet[StreetNames.STREET1.ordinal()], stdStreet[StreetNames.STREET2.ordinal()], - stdStreet[StreetNames.KUDAY.ordinal()], - stdStreet[StreetNames.IBRAHIM_ALKHALIL.ordinal()]//TODO: [8]is actually half of ibrahim khalil. + stdStreet[StreetNames.THIRD_HIGHWAY.ordinal()], + stdStreet[StreetNames.STREET5.ordinal()]//TODO: [8]is actually half of ibrahim khalil. },District.ALMANSOOR, Mashier.ARAFAT); //Optimal for Almansoor @@ -207,7 +210,8 @@ public class MakkahCity { int numOfTruck = (int)getRandom(0, 2); if (street.getName() == StreetNames.FOURTH_HIGHWAY) numOfSedan = (int) (numOfSedan * 0.5); - if (street.getName() == StreetNames.STREET1) numOfSedan = (int) (numOfSedan * 1.5); //add more streets + if (street.getName() == StreetNames.STREET3) numOfSedan = (int) (numOfSedan * 1.5); + if (street.getName() == StreetNames.STREET5) numOfSedan = (int) (numOfSedan * 1.5); for (int x = 0; x < numOfSedan; x++) { Sedan car = new Sedan(getRandom(4, 5)); double pointOfEntry = getRandom(0, street.getLength()); @@ -221,7 +225,8 @@ public class MakkahCity { } if (street.getName() == StreetNames.FOURTH_HIGHWAY) numOfTruck = (int) (numOfTruck * 0.5); - if (street.getName() == StreetNames.STREET1) numOfTruck = (int) (numOfTruck * 1.5); //add more streets + if (street.getName() == StreetNames.STREET3) numOfTruck = (int) (numOfTruck * 1.5); + if (street.getName() == StreetNames.STREET5) numOfSedan = (int) (numOfSedan * 1.5); for (int x = 0; x < numOfTruck; x++) { Truck car = new Truck(getRandom(4, 5)); double pointOfEntry = getRandom(0, street.getLength()); @@ -234,7 +239,8 @@ public class MakkahCity { } if (street.getName() == StreetNames.FOURTH_HIGHWAY) numOfSUV = (int) (numOfSUV * 0.5); - if (street.getName() == StreetNames.STREET1) numOfSUV = (int) (numOfSUV * 1.5); //add more streets + if (street.getName() == StreetNames.STREET3) numOfSUV = (int) (numOfSUV * 1.5); + if (street.getName() == StreetNames.STREET5) numOfSedan = (int) (numOfSedan * 1.5); for (int x = 0; x < numOfSUV; x++) { SUV car = new SUV(getRandom(4, 5)); double pointOfEntry = getRandom(0, street.getLength()); @@ -312,5 +318,24 @@ public class MakkahCity { Route[] routesArray = new Route[routes.size()]; return routes.toArray(routesArray); } + + + + private static void printReport() { + for(Street street : stdStreet) { + System.out.printf("StreetName: %s NumberOfVheciles : %d Capcity: %f\n",street.getName().name(),street.getVehicles().size(), street.capcity()); + int qurter = (int) street.getLength()/4; + double capcity = 0; + for(int i = 0; i < 4; i++) { + capcity = street.capcityPoint(i * qurter, qurter * (i+1)); + System.out.printf("qurter%d : %.2f", (1+1) , capcity ); + } + System.out.println("\n"); + + + } + + + } } diff --git a/src/StreetNames.java b/src/StreetNames.java index 0a1ae9f..c7da1b0 100644 --- a/src/StreetNames.java +++ b/src/StreetNames.java @@ -4,12 +4,15 @@ public enum StreetNames { KA_STREET, - KUDAY, + THIRD_HIGHWAY, FOURTH_HIGHWAY, STREET1, STREET2, STREET3, STREET4, - IBRAHIM_ALKHALIL + STREET5, + IBRAHIM_ALKHALIL, + + } From 0458ff143e56241ca0f25328d5c9924f4c2a0595 Mon Sep 17 00:00:00 2001 From: EngOsamah <74116947+EngOsamah@users.noreply.github.com> Date: Sun, 15 Nov 2020 01:21:15 +0300 Subject: [PATCH 3/3] maybe this is going to be phase one --- src/MakkahCity.java | 112 +++++++++++++++++++++++++++++--------------- src/Street.java | 14 ++++-- 2 files changed, 85 insertions(+), 41 deletions(-) diff --git a/src/MakkahCity.java b/src/MakkahCity.java index b5296f7..b1b6fe9 100644 --- a/src/MakkahCity.java +++ b/src/MakkahCity.java @@ -15,9 +15,9 @@ public class MakkahCity { public static void main(String[] args) { //Gen Camp - generateCamps(District.ALAZIZIYA, (int)getRandom(70, 100)); - generateCamps(District.ALMANSOOR, (int)getRandom(110, 160)); - generateCamps(District.ALHIJRA, (int)getRandom(80, 110)); + generateCamps(District.ALAZIZIYA, (int)getRandom(700, 1000)); + generateCamps(District.ALMANSOOR, (int)getRandom(1000, 1200)); + generateCamps(District.ALHIJRA, (int)getRandom(850, 1100)); fillBusesToList(); @@ -36,7 +36,10 @@ public class MakkahCity { while(!timeManager.isEnded()) { //Start of Every hour if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) == 0){ - + if (isAllArrived()) { + System.out.println("\nAll campaigns have arrived befor " + timeManager.getCurrentTime()); + break; + } } //Start of Every half-hour if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) % 30 == 0){ @@ -45,8 +48,8 @@ public class MakkahCity { //Start of every 10min if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) % 10 == 0){ addCivilVehicleNoise(); - printReport(); - System.out.println(); + System.out.println("\n\n" + getStreetsReport()); + printFinalRep(); } if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) == getRandom(0,59) @@ -58,26 +61,31 @@ public class MakkahCity { Route route = vehicle.getRoute(); double currentLocation = vehicle.getCurrentLocation(); if (vehicle.getCurrentStreet() == null && - route.getStreets()[0].capcityPoint(0,1500) < 1) { + route.getStreets()[0].capcityPoint(0,1000) < 1) { vehicle.setCurrentStreet(route.getStreets()[0]); } - else if (vehicle.getCurrentStreet() != null && vehicle.getCurrentStreet().capcityPoint(currentLocation+1500, - currentLocation+1500*2) < 1 ) { //May test diff values. + if (vehicle.getCurrentStreet() != null && vehicle.getCurrentStreet().capcityPoint(currentLocation, + currentLocation+1000) < 1 ) { //May test diff values. if (currentLocation >= vehicle.getCurrentStreet().getLength()) { //Move to next street - vehicle.setCurrentLocation(0); int nxtIndex = route.indexOf(vehicle.getCurrentStreet()) + 1; - if (nxtIndex <= route.getStreets().length - 1) + if (nxtIndex <= route.getStreets().length - 1) { + if (vehicle.getRoute().getStreets()[nxtIndex].capcityPoint(0, 1000) < 1) { vehicle.setCurrentStreet(route.getStreets()[nxtIndex]); + vehicle.setCurrentLocation(0); + } + } else vehicle.arrive(); } if (!vehicle.isArrivedToDest()) { - if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD); - else if (vehicle instanceof Sedan) vehicle.move(Sedan.MAX_FORWARD); - else if (vehicle instanceof SUV) vehicle.move(SUV.MAX_FORWARD); - else if (vehicle instanceof Truck) vehicle.move(Bus.MAX_FORWARD); + double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(), + vehicle.getCurrentLocation()+1000)) ; + if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * factor ); + else if (vehicle instanceof Sedan) vehicle.move(Sedan.MAX_FORWARD * factor ); + else if (vehicle instanceof SUV) vehicle.move(SUV.MAX_FORWARD * factor ); + else if (vehicle instanceof Truck) vehicle.move(Bus.MAX_FORWARD * factor ); } } } @@ -90,11 +98,7 @@ public class MakkahCity { // timeManager.getCurrentTime()); //} - - //noise based on time of day (From PDate) - //TODO: [5]Streets move forward. - //TODO: Get real car values. /* @@ -104,6 +108,7 @@ public class MakkahCity { */ timeManager.step(Calendar.MINUTE, 1); } + //TODO: print final report } private static void setRoutesForCampaigns() { @@ -112,18 +117,6 @@ public class MakkahCity { } } - /* - This is not used. The campaign object sets the routes for the busses - */ - @Deprecated - private static void setUpCampaginRoute(Campaign camp, int routeName) { - Route route = stdRoutes[routeName]; - camp.setDestToHousingRoute(route); - //For now set all busses to one route - for(Vehicle vehicle : camp.getVehicles()){ - vehicle.setRoute(route); - } - } private static double getRandom(double min, double max) { return (Math.random() * (max - min) + min); @@ -323,19 +316,64 @@ public class MakkahCity { private static void printReport() { for(Street street : stdStreet) { - System.out.printf("StreetName: %s NumberOfVheciles : %d Capcity: %f\n",street.getName().name(),street.getVehicles().size(), street.capcity()); + System.out.printf("StreetName: %s NumberOfVheciles : %d Capcity: %f\n", + street.getName().name(),street.getVehicles().size(), street.capcity()); int qurter = (int) street.getLength()/4; double capcity = 0; for(int i = 0; i < 4; i++) { capcity = street.capcityPoint(i * qurter, qurter * (i+1)); - System.out.printf("qurter%d : %.2f", (1+1) , capcity ); + System.out.printf("qurter%d: %.2f ", (i+1) , capcity ); } - System.out.println("\n"); - - + System.out.println("\n"); + } + } + + + private static String getStreetsReport() { + String headerFormat = "******Streets report*****\n" + + "Time: %s\n"; + String report = ""; + report = report + String.format(headerFormat, timeManager.getCurrentTime()); + String entryFormat = "Street name: %-9s | remaining capacity: %%%-4s | cars: %d\n"; + for (Street street : stdStreet) { + int cap = street.getPercentRemainingCapacity(); + report = report + String.format(entryFormat, + street.getName().name(), + cap, + street.getVehicles().size()); } + return report; + } + + private static void printFinalRep() { + int numberOfBusses = 0; + int numberOfArrivedBuses = getNumberOfArrivedBusses(); + //Redundant loops slow down execution. find better sol. + for (Campaign campaign : listOfCampaigns) { + numberOfBusses += campaign.getNumberOfBusses(); + } + System.out.printf("Buses: %d Buses done: %d\n", + numberOfBusses, numberOfArrivedBuses); + } + + private static int getNumberOfArrivedBusses() { + int num = 0; + for (Campaign campaign : listOfCampaigns) { + for (Vehicle vehicle : campaign.getVehicles()){ + if (vehicle instanceof Bus && + vehicle.isArrivedToDest()) num++; + } + } + return num; + } + + private static boolean isAllArrived() { + for (Campaign campaign : listOfCampaigns) + for (Vehicle vehicle : campaign.getVehicles()) + if (!vehicle.isArrivedToDest()) + return false; - + return true; } } diff --git a/src/Street.java b/src/Street.java index 78edd6f..a76742f 100644 --- a/src/Street.java +++ b/src/Street.java @@ -56,15 +56,15 @@ public class Street { for(int i=0;i 1) + return 1; + else if (capcity < 0 ) + return 0; + else + return capcity; } }