Hajj-simulation/src/MakkahCity.java

173 lines
5.1 KiB
Java
Raw Normal View History

import java.util.*;
2020-11-08 01:05:52 +01:00
public class MakkahCity {
private static final ArrayList<Campaign> listOfCampaigns = new ArrayList<>();
private static final ArrayList<Vehicle> listOfVehicles = new ArrayList<>();
private static final Route[] stdRoutes = new Route[9];
private static final Street[] stdStreet = new Street[8];
private static final PDate timeManager = new PDate(
new GregorianCalendar(2020, Calendar.JANUARY, 1, 8, 0, 0),
new GregorianCalendar(2020, Calendar.JANUARY, 2, 8, 0, 0)
);
2020-11-08 01:05:52 +01:00
public static void main(String[] args) {
//Gen Camp
2020-11-10 14:45:35 +01:00
generateCamps(District.ALAZIZIYA, getRandom(70, 100));
generateCamps(District.ALMANSOOR, getRandom(110, 160));
generateCamps(District.ALHIJRA, getRandom(80, 110));
2020-11-10 15:06:28 +01:00
fillBusesToList();
2020-11-10 15:06:28 +01:00
//Make Streets
makeStreets();
//Make Routes
makeRoutes();
//Set Routes for Campaigns
setRoutesForCampaigns();
2020-11-10 18:48:32 +01:00
//TODO: Set Schedule for Campaigns
while(!timeManager.isEnded()) {
timeManager.step(Calendar.MINUTE, 1);
System.out.println(timeManager.getCurrentTime());
2020-11-10 18:48:32 +01:00
//TODO: add civil cars in loop iterations. (noise)
//TODO: Move busses and vehicles.
//TODO: Update streets.
//TODO: Streets move forward.
//TODO: update vehicles on street.
}
}
private static void setRoutesForCampaigns() {
for (Campaign camp : listOfCampaigns){
if (camp.getHotelDistrict() == District.ALAZIZIYA) {
setUpCampaginRoute(camp, RouteName.mashierToAlAzizi1);
}
else if (camp.getHotelDistrict() == District.ALMANSOOR){
setUpCampaginRoute(camp, RouteName.mashierToAlMansoor2);
}
else {
setUpCampaginRoute(camp, RouteName.mashierToAlHijra1);
}
}
}
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 int getRandom(int min, int max) {
return (int)(Math.random() * (max - min) + min);
}
private static void generateCamps(District area, int count) {
for (int i = 0; i < count; i++){
Campaign camp = new Campaign(area, getRandom(10, 15));
listOfCampaigns.add(camp);
}
}
private static void makeStreets(){
2020-11-10 14:45:35 +01:00
stdStreet[StreetNames.KA_STREET] = new Street(22700,3);
stdStreet[StreetNames.FOURTH_HIGHWAY] = new Street(24600,4);
stdStreet[StreetNames.KUDAY] = new Street(22000,3);
2020-11-10 14:45:35 +01:00
stdStreet[StreetNames.STREET1] = new Street(4000,2);
stdStreet[StreetNames.STREET2] = new Street(7000,2);
stdStreet[StreetNames.STREET3] = new Street(400,2);
stdStreet[StreetNames.STREET4] = new Street(8200,2);
stdStreet[StreetNames.IBRAHIM_ALKHALIL] = new Street(100,2); //TODO: Change numbers
2020-11-08 01:05:52 +01:00
}
private static void makeRoutes() {
stdRoutes[RouteName.mashierToAlHijra1] = new Route(
new Street[]{
stdStreet[StreetNames.STREET1],
stdStreet[StreetNames.STREET2],
stdStreet[StreetNames.KUDAY]},
District.ALHIJRA, Mashier.ARAFAT);
stdRoutes[RouteName.mashierToAlHijra2] = new Route(new Street[]{
stdStreet[StreetNames.STREET1],
stdStreet[StreetNames.FOURTH_HIGHWAY],
stdStreet[StreetNames.STREET4]
},District.ALAZIZIYA, Mashier.ARAFAT);
stdRoutes[RouteName.mashierToAlMansoor1] = new Route(
new Street[]{
stdStreet[StreetNames.STREET1],
stdStreet[StreetNames.STREET2],
stdStreet[StreetNames.KA_STREET],
stdStreet[StreetNames.STREET3]
},District.ALMANSOOR, Mashier.ARAFAT);
stdRoutes[RouteName.mashierToAlMansoor2] = new Route(
new Street[]{
stdStreet[StreetNames.STREET1],
stdStreet[StreetNames.STREET2],
stdStreet[StreetNames.KUDAY],
stdStreet[StreetNames.IBRAHIM_ALKHALIL]//TODO: is actually half of ibrahim khalil.
},District.ALMANSOOR, Mashier.ARAFAT);
//Optimal for Almansoor
stdRoutes[RouteName.mashierToAlMansoor3] = new Route(
new Street[]{
stdStreet[StreetNames.STREET1],
stdStreet[StreetNames.FOURTH_HIGHWAY],
stdStreet[StreetNames.IBRAHIM_ALKHALIL]
},District.ALMANSOOR, Mashier.ARAFAT);
stdRoutes[RouteName.mashierToAlAzizi1] = new Route(
new Street[]{
stdStreet[StreetNames.STREET1],
stdStreet[StreetNames.STREET2],
stdStreet[StreetNames.KA_STREET]
},District.ALAZIZIYA, Mashier.ARAFAT);
}
private static void fillBusesToList() {
for (Campaign camp : listOfCampaigns) {
listOfVehicles.addAll(camp.getVehicles());
}
}
2020-11-10 18:48:32 +01:00
/**
* Generates 'noise' cars to be used in streets
* @param numberOfCars
* @return Array of 70% Sedans and 30% SUVs
*/
private static CivilVehicle[] generateCivilVehicles(int numberOfCars) {
CivilVehicle[] cars = new CivilVehicle[numberOfCars];
int sedans = (int)(numberOfCars*0.7);
int SUVs = numberOfCars - sedans;
for (int i = 0; i < sedans; i++) {
cars[i] = new Sedan(getRandom(25,32)/10);
}
for (int i = 0; i < SUVs; i++) {
cars[sedans+i] = new SUV(getRandom(35,45)/10);
}
return cars;
}
public static PDate getTimeManager() {
return timeManager;
}
2020-11-08 01:05:52 +01:00
}