diff --git a/src/MakkahCity.java b/src/MakkahCity.java index b9c259d..16a336e 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(700, 1000)); - generateCamps(District.ALMANSOOR, (int)getRandom(1000, 1200)); - generateCamps(District.ALHIJRA, (int)getRandom(850, 1100)); + generateCamps(District.ALAZIZIYA, (int)getRandom(1200, 1400)); + generateCamps(District.ALMANSOOR, (int)getRandom(1600, 1800)); + generateCamps(District.ALHIJRA, (int)getRandom(1400, 1600)); fillBusesToList(); @@ -70,19 +70,11 @@ public class MakkahCity { if (currentLocation >= vehicle.getCurrentStreet().getLength()) { //Move to next street - int nxtIndex = route.indexOf(vehicle.getCurrentStreet()) + 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(); + vehicle.moveToNextStreet(); } if (!vehicle.isArrivedToDest()) { double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(), - vehicle.getCurrentLocation()+1000)) ; + vehicle.getCurrentLocation()+1000,vehicle)) ; 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 ); @@ -199,9 +191,9 @@ public class MakkahCity { private static void addCivilVehicleNoise() { for (Street street: stdStreet) { - int numOfSedan = (int)getRandom(7, 15); - int numOfSUV = (int)getRandom(5, 10); - int numOfTruck = (int)getRandom(0, 2); + int numOfSedan = (int)getRandom(40,50); + int numOfSUV = (int)getRandom(20,30); + int numOfTruck = (int)getRandom(10,12); if (street.getName() == StreetNames.FOURTH_HIGHWAY) numOfSedan = (int) (numOfSedan * 0.5); if (street.getName() == StreetNames.STREET3) numOfSedan = (int) (numOfSedan * 1.5); diff --git a/src/Route.java b/src/Route.java index 5c143b1..80163e3 100644 --- a/src/Route.java +++ b/src/Route.java @@ -60,4 +60,5 @@ public class Route { private void throwIllegal() { throw new IllegalArgumentException(); } + } diff --git a/src/Street.java b/src/Street.java index a76742f..d8ec503 100644 --- a/src/Street.java +++ b/src/Street.java @@ -7,6 +7,7 @@ public class Street { private ArrayList vehicles; private StreetNames name; + public Street(double length, int numberOfLanes, StreetNames name) { vehicles = new ArrayList<>(); @@ -56,7 +57,17 @@ public class Street { for(int i=0;i totalLength){ + percent = (int) (totalLength/totalLenthofCar); + percent *= 100; + percent += totalLength - (totalLength % totalLenthofCar); + } + else { + percent = (int)(totalLength - totalLenthofCar); + } + + return percent; } public int getPercentRemainingCapacity() { @@ -93,4 +104,38 @@ public class Street { else return capcity; } + + public double capcityPoint(double min, double max, Vehicle vehicle) { + + if(max > getLength() && getNextStreet(vehicle) != null) { + double reamingLength = max - getLength(); + double y = capcityPoint(min, getLength(),vehicle); + double z = getNextStreet(vehicle).capcityPoint(0, reamingLength, vehicle); + return ((y + z)/2); + } + double totalLength = (max - min) * numberOfLanes; + double totalLenthofCar=0; + for(int i=0;i= min && + vehicles.get(i).getCurrentLocation() <= max) + totalLenthofCar+=vehicles.get(i).getVehicleSize(); + } + double capcity = totalLenthofCar / totalLength; + if (capcity > 1) + return 1; + else if (capcity < 0 ) + return 0; + else + return capcity; + } + + public Street getNextStreet(Vehicle vehicle) { + int nextIndex = vehicle.getRoute().indexOf(vehicle.getCurrentStreet()) +1 ; + if(vehicle.getRoute().getStreets().length > nextIndex) + return (vehicle.getRoute().getStreets()[nextIndex]); + else + return null; + + + } } diff --git a/src/Vehicle.java b/src/Vehicle.java index ca2705f..f2d2f5e 100644 --- a/src/Vehicle.java +++ b/src/Vehicle.java @@ -126,4 +126,20 @@ public abstract class Vehicle { public void setTimeOfArrival(Date timeOfArrival) { this.timeOfArrival = timeOfArrival; } + + public void moveToNextStreet() { + + int nxtIndex = route.indexOf(this.getCurrentStreet()) + 1; + if (nxtIndex <= route.getStreets().length - 1) { + if (this.getRoute().getStreets()[nxtIndex].capcityPoint(0, 1000) < 1) { + this.setCurrentStreet(route.getStreets()[nxtIndex]); + this.setCurrentLocation(0); + } + } + else + this.arrive(); + } + } + +