maybe this is going to be phase one

This commit is contained in:
EngOsamah 2020-11-15 01:21:15 +03:00
parent bb46419ed3
commit 0458ff143e
2 changed files with 85 additions and 41 deletions

View File

@ -15,9 +15,9 @@ public class MakkahCity {
public static void main(String[] args) { public static void main(String[] args) {
//Gen Camp //Gen Camp
generateCamps(District.ALAZIZIYA, (int)getRandom(70, 100)); generateCamps(District.ALAZIZIYA, (int)getRandom(700, 1000));
generateCamps(District.ALMANSOOR, (int)getRandom(110, 160)); generateCamps(District.ALMANSOOR, (int)getRandom(1000, 1200));
generateCamps(District.ALHIJRA, (int)getRandom(80, 110)); generateCamps(District.ALHIJRA, (int)getRandom(850, 1100));
fillBusesToList(); fillBusesToList();
@ -36,7 +36,10 @@ public class MakkahCity {
while(!timeManager.isEnded()) { while(!timeManager.isEnded()) {
//Start of Every hour //Start of Every hour
if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) == 0){ 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 //Start of Every half-hour
if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) % 30 == 0){ if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) % 30 == 0){
@ -45,8 +48,8 @@ public class MakkahCity {
//Start of every 10min //Start of every 10min
if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) % 10 == 0){ if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) % 10 == 0){
addCivilVehicleNoise(); addCivilVehicleNoise();
printReport(); System.out.println("\n\n" + getStreetsReport());
System.out.println(); printFinalRep();
} }
if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) == getRandom(0,59) if (timeManager.getCurrentCalendar().get(Calendar.MINUTE) == getRandom(0,59)
@ -58,26 +61,31 @@ public class MakkahCity {
Route route = vehicle.getRoute(); Route route = vehicle.getRoute();
double currentLocation = vehicle.getCurrentLocation(); double currentLocation = vehicle.getCurrentLocation();
if (vehicle.getCurrentStreet() == null && if (vehicle.getCurrentStreet() == null &&
route.getStreets()[0].capcityPoint(0,1500) < 1) { route.getStreets()[0].capcityPoint(0,1000) < 1) {
vehicle.setCurrentStreet(route.getStreets()[0]); vehicle.setCurrentStreet(route.getStreets()[0]);
} }
else if (vehicle.getCurrentStreet() != null && vehicle.getCurrentStreet().capcityPoint(currentLocation+1500, if (vehicle.getCurrentStreet() != null && vehicle.getCurrentStreet().capcityPoint(currentLocation,
currentLocation+1500*2) < 1 ) { //May test diff values. currentLocation+1000) < 1 ) { //May test diff values.
if (currentLocation >= vehicle.getCurrentStreet().getLength()) { if (currentLocation >= vehicle.getCurrentStreet().getLength()) {
//Move to next street //Move to next street
vehicle.setCurrentLocation(0);
int nxtIndex = route.indexOf(vehicle.getCurrentStreet()) + 1; 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.setCurrentStreet(route.getStreets()[nxtIndex]);
vehicle.setCurrentLocation(0);
}
}
else else
vehicle.arrive(); vehicle.arrive();
} }
if (!vehicle.isArrivedToDest()) { if (!vehicle.isArrivedToDest()) {
if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD); double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(),
else if (vehicle instanceof Sedan) vehicle.move(Sedan.MAX_FORWARD); vehicle.getCurrentLocation()+1000)) ;
else if (vehicle instanceof SUV) vehicle.move(SUV.MAX_FORWARD); if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * factor );
else if (vehicle instanceof Truck) vehicle.move(Bus.MAX_FORWARD); 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()); // timeManager.getCurrentTime());
//} //}
//noise based on time of day (From PDate) //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); timeManager.step(Calendar.MINUTE, 1);
} }
//TODO: print final report
} }
private static void setRoutesForCampaigns() { 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) { private static double getRandom(double min, double max) {
return (Math.random() * (max - min) + min); return (Math.random() * (max - min) + min);
@ -323,19 +316,64 @@ public class MakkahCity {
private static void printReport() { private static void printReport() {
for(Street street : stdStreet) { 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; int qurter = (int) street.getLength()/4;
double capcity = 0; double capcity = 0;
for(int i = 0; i < 4; i++) { for(int i = 0; i < 4; i++) {
capcity = street.capcityPoint(i * qurter, qurter * (i+1)); 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;
} }
} }

View File

@ -56,15 +56,15 @@ public class Street {
for(int i=0;i<vehicles.size();i++) { for(int i=0;i<vehicles.size();i++) {
totalLenthofCar+=vehicles.get(i).getVehicleSize(); totalLenthofCar+=vehicles.get(i).getVehicleSize();
} }
return totalLength -(totalLenthofCar + 0.5*(vehicles.size() - 2)); return totalLength -totalLenthofCar;
} }
public int getPercentRemainingCapacity() { public int getPercentRemainingCapacity() {
return (int) (capcity()/(this.length*this.numberOfLanes))*100; return (int) (capcity()/(this.length*this.numberOfLanes)*100);
} }
public boolean canTakeVehicles( Vehicle vehicle ) { public boolean canTakeVehicles( Vehicle vehicle ) {
if ( vehicle.getVehicleSize() + 0.5 < capcity() ) if ( vehicle.getVehicleSize() < capcity() )
return true; return true;
else else
return false; return false;
@ -85,6 +85,12 @@ public class Street {
vehicles.get(i).getCurrentLocation() <= max) vehicles.get(i).getCurrentLocation() <= max)
totalLenthofCar+=vehicles.get(i).getVehicleSize(); totalLenthofCar+=vehicles.get(i).getVehicleSize();
} }
return totalLenthofCar / totalLength; double capcity = totalLenthofCar / totalLength;
if (capcity > 1)
return 1;
else if (capcity < 0 )
return 0;
else
return capcity;
} }
} }