Compare commits

...

5 Commits

Author SHA1 Message Date
20cfeb268c Amend prev commit about checks 2021-01-11 02:37:28 +03:00
200c06bfac Skip done vehicles:
Skip done cars improves perf greatly.
    Tested in parallel with previous commit
    and results in faster exc when sim has more/less
    generated cars.
2021-01-11 01:53:31 +03:00
7ffbe689bc Discard special cases for general implementation:
Instead of checking instance of veh,
    use the abstract method getMaxSpeed()
    with a given factor.

    This should reduce redundant checks
    (Wasted CPU cycles). Thus, run is
    a tiny bit faster.
2021-01-10 23:48:22 +03:00
612c00a3f1 Reindent (No Change) 2021-01-10 22:00:25 +03:00
69c1a19ed9 Memory usage improvements:
- Use smaller number types int -> short
    saves in heap size.

    - Save UID of vehicles as int (4 Bytes)
    or short (2 Bytes) and when needed, make
    a String as UID. A string would take up
    (16 Bytes).
2021-01-10 21:57:51 +03:00
7 changed files with 187 additions and 198 deletions

View File

@ -1,11 +1,11 @@
public class Bus extends CivilVehicle { public class Bus extends CivilVehicle {
private String UID; private int UID;
private Campaign campaign; private Campaign campaign;
private static int numeberOfBuses; private static int numeberOfBuses;
private final int TIME_TO_FIX = 20; //in minutes private final short TIME_TO_FIX = 20; //in minutes
public static final int MAX_FORWARD = 900; //Meter/Min public static final short MAX_FORWARD = 900; //Meter/Min
public static final double STD_BUS_SIZE = 10; public static final double STD_BUS_SIZE = 10;
@ -40,11 +40,11 @@ public class Bus extends CivilVehicle {
private void generateUID() { private void generateUID() {
numeberOfBuses++; numeberOfBuses++;
this.UID = String.format("BUS%04d", numeberOfBuses); this.UID = numeberOfBuses;
} }
public String getUID(){ public String getUID(){
return this.UID; return String.format("BUS%04d", UID);
} }
public Campaign getCampaign() { public Campaign getCampaign() {

View File

@ -467,7 +467,6 @@ public class GUI_History {
} }
public String avgTimeOfTrip() { public String avgTimeOfTrip() {
//TODO: does output diff value even after all have arrived.
Calendar now = new GregorianCalendar(); Calendar now = new GregorianCalendar();
now.setTime(currenttimeManager); now.setTime(currenttimeManager);
Calendar from = (GregorianCalendar)now.clone(); Calendar from = (GregorianCalendar)now.clone();

View File

@ -251,7 +251,7 @@ public class GUI_ViewStreet {
if (vehicles.isEmpty()) return; if (vehicles.isEmpty()) return;
vehicleData = new Object[vehicles.size()][6]; vehicleData = new Object[vehicles.size()][6];
for (int i = 0; i < vehicles.size(); i++) { for (int i = 0; i < vehicles.size(); i++) {
vehicleData[i][0] = vehicles.get(i).getUID();// TODO: There is an Exception error here; vehicleData[i][0] = vehicles.get(i).getUID();
if (vehicles.get(i) instanceof Bus) if (vehicles.get(i) instanceof Bus)
vehicleData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name(); vehicleData[i][1] = ((Bus)vehicles.get(i)).getCampaign().getHotelDistrict().name();
else vehicleData[i][1] = "Local Vehicle"; else vehicleData[i][1] = "Local Vehicle";

View File

@ -17,8 +17,8 @@ public class MakkahCity {
private static Date allArrivedToHotelsTime; private static Date allArrivedToHotelsTime;
private static final PDate firstDayTimeMan = new PDate( private static final PDate firstDayTimeMan = new PDate(
new GregorianCalendar(1442, Calendar.JANUARY, 9, 4, 0, 0), new GregorianCalendar(1442, Calendar.JANUARY, 9, 4, 0, 0),
new GregorianCalendar(1442, Calendar.JANUARY, 9, 18, 0, 0) new GregorianCalendar(1442, Calendar.JANUARY, 9, 18, 0, 0)
); );
private static final PDate lastDayTimeMan = new PDate( private static final PDate lastDayTimeMan = new PDate(
@ -46,17 +46,16 @@ public class MakkahCity {
private static JLabel lblNumOfDonebuses; private static JLabel lblNumOfDonebuses;
private static JLabel lblMaximumTripValue; private static JLabel lblMaximumTripValue;
private static JLabel lblMinimumTripValue; private static JLabel lblMinimumTripValue;
private static JLabel lblBusesArrivedInTheLastHourValue; private static JLabel lblBusesArrivedInTheLastHourValue;
private static JLabel lblAverageTripForLastHourValue; private static JLabel lblAverageTripForLastHourValue;
private static JButton btnPause; private static JButton btnPause;
private static JLabel lblAverageTimeForTheTrip; private static JLabel lblAverageTimeForTheTrip;
private static JLabel lblArrivedToArafatTime; private static JLabel lblArrivedToArafatTime;
private static JLabel lblArrivedToHotelsTime; private static JLabel lblArrivedToHotelsTime;
public static void main(String[] args) { public static void main(String[] args) {
//TODO: fix state errors
t.start(); t.start();
//Gen Camp //Gen Camp
campPerDistrict[District.ALMANSOOR.ordinal()] = new ArrayList<>(); campPerDistrict[District.ALMANSOOR.ordinal()] = new ArrayList<>();
@ -65,11 +64,11 @@ public class MakkahCity {
generateCamps(District.ALAZIZIYA, (int)getRandom(1200, 1400)); generateCamps(District.ALAZIZIYA, (int)getRandom(1200, 1400));
generateCamps(District.ALMANSOOR, (int)getRandom(1600, 1800)); generateCamps(District.ALMANSOOR, (int)getRandom(1600, 1800));
generateCamps(District.ALHIJRA, (int)getRandom(1400, 1600)); generateCamps(District.ALHIJRA, (int)getRandom(1400, 1600));
Collections.shuffle(listOfCampaigns); Collections.shuffle(listOfCampaigns);
fillBusesToList(); fillBusesToList();
makeStreets(); makeStreets();
addCivilVehicleNoise(); addCivilVehicleNoise();
@ -79,9 +78,9 @@ public class MakkahCity {
//GUI //GUI
autoModeCheckBox = new Checkbox(); autoModeCheckBox = new Checkbox();
makkahFrame = new JFrame("Hajj Simulation"); makkahFrame = new JFrame("Hajj Simulation");
//Street data and district for GUI table //Street data and district for GUI table
//Street data //Street data
Object[][] streetData = new Object[stdStreet.length][6]; Object[][] streetData = new Object[stdStreet.length][6];
String[] streetColNames = {"Street Name", "Street Load %", "Total", "Buses", String[] streetColNames = {"Street Name", "Street Load %", "Total", "Buses",
@ -99,7 +98,7 @@ public class MakkahCity {
Object[][] districtData = new Object[campPerDistrict.length][7]; Object[][] districtData = new Object[campPerDistrict.length][7];
String[] districtColNames = {"District", "Campaigns", "Busses", "Arrival %", String[] districtColNames = {"District", "Campaigns", "Busses", "Arrival %",
"Avg. Time", "Best time to Arafat", "Best time to District"}; "Avg. Time", "Best time to Arafat", "Best time to District"};
for (int i = 0; i < campPerDistrict.length; i++) { for (int i = 0; i < campPerDistrict.length; i++) {
districtData[i][0] = campPerDistrict[i].get(0).getHotelDistrict().name(); districtData[i][0] = campPerDistrict[i].get(0).getHotelDistrict().name();
districtData[i][1] = campPerDistrict[i].size(); districtData[i][1] = campPerDistrict[i].size();
@ -109,9 +108,9 @@ public class MakkahCity {
districtData[i][5] = getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus()); districtData[i][5] = getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus());
districtData[i][6] = getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus()); districtData[i][6] = getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus());
} }
//tables //tables
//Street table //Street table
streetTable = new JTable(streetData,streetColNames); streetTable = new JTable(streetData,streetColNames);
streetTable.setEnabled(false); streetTable.setEnabled(false);
@ -136,7 +135,7 @@ public class MakkahCity {
streetTable.getColumnModel().getColumn(5).setPreferredWidth(0); streetTable.getColumnModel().getColumn(5).setPreferredWidth(0);
JScrollPane streetScroll = new JScrollPane(streetTable); JScrollPane streetScroll = new JScrollPane(streetTable);
streetScroll.setBounds(22,100,809,269); streetScroll.setBounds(22,100,809,269);
//District table //District table
districtTable = new JTable(districtData,districtColNames); districtTable = new JTable(districtData,districtColNames);
districtTable.setEnabled(false); districtTable.setEnabled(false);
@ -163,7 +162,7 @@ public class MakkahCity {
districtTable.getColumnModel().getColumn(6).setPreferredWidth(93); districtTable.getColumnModel().getColumn(6).setPreferredWidth(93);
districtTable.revalidate(); districtTable.revalidate();
districtScroll.setBounds(22,420,809,89); districtScroll.setBounds(22,420,809,89);
//Buttons //Buttons
JButton btnViewRoutes = new JButton("View Routes"); JButton btnViewRoutes = new JButton("View Routes");
btnViewRoutes.setBounds(888, 33, 166, 29); btnViewRoutes.setBounds(888, 33, 166, 29);
@ -185,7 +184,7 @@ public class MakkahCity {
pause_flag = true; pause_flag = true;
btnPause.setText("Unpause"); btnPause.setText("Unpause");
}); });
JButton btnViewReport = new JButton("View Report"); JButton btnViewReport = new JButton("View Report");
btnViewReport.setBounds(888, 153, 166, 29); btnViewReport.setBounds(888, 153, 166, 29);
btnViewReport.setFont(new Font("Rockwell", Font.PLAIN, 16)); btnViewReport.setFont(new Font("Rockwell", Font.PLAIN, 16));
@ -196,7 +195,7 @@ public class MakkahCity {
pause_flag = true; pause_flag = true;
btnPause.setText("Unpause"); btnPause.setText("Unpause");
}); });
JButton btnViewStreet = new JButton("View Street"); JButton btnViewStreet = new JButton("View Street");
btnViewStreet.setBounds(888, 113, 166, 29); btnViewStreet.setBounds(888, 113, 166, 29);
btnViewStreet.setFont(new Font("Rockwell", Font.PLAIN, 16)); btnViewStreet.setFont(new Font("Rockwell", Font.PLAIN, 16));
@ -233,7 +232,7 @@ public class MakkahCity {
btnPause.setText("Pause"); btnPause.setText("Pause");
} }
}); });
JButton btnBrowseHistory = new JButton("Browse History"); JButton btnBrowseHistory = new JButton("Browse History");
btnBrowseHistory.setBounds(888, 193, 166, 29); btnBrowseHistory.setBounds(888, 193, 166, 29);
btnBrowseHistory.setBackground(new Color(9,9,9)); btnBrowseHistory.setBackground(new Color(9,9,9));
@ -244,28 +243,28 @@ public class MakkahCity {
pause_flag = true; pause_flag = true;
btnPause.setText("Unpause"); btnPause.setText("Unpause");
}); });
//Label //Label
JLabel lblStreets = new JLabel("Streets"); JLabel lblStreets = new JLabel("Streets");
lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24)); lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24));
lblStreets.setForeground(new Color(255, 255, 255)); lblStreets.setForeground(new Color(255, 255, 255));
lblStreets.setBounds(22, 59, 208, 30); lblStreets.setBounds(22, 59, 208, 30);
JLabel lblDistrict = new JLabel("District"); JLabel lblDistrict = new JLabel("District");
lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24)); lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24));
lblDistrict.setForeground(new Color(255, 255, 255)); lblDistrict.setForeground(new Color(255, 255, 255));
lblDistrict.setBounds(22, 380, 166, 29); lblDistrict.setBounds(22, 380, 166, 29);
JLabel lblTime = new JLabel("Time:"); JLabel lblTime = new JLabel("Time:");
lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblTime.setForeground(new Color(255, 255, 255)); lblTime.setForeground(new Color(255, 255, 255));
lblTime.setBounds(22, 11, 72, 14); lblTime.setBounds(22, 11, 72, 14);
JLabel lblStatus = new JLabel("Status:"); JLabel lblStatus = new JLabel("Status:");
lblStatus.setForeground(new Color(255, 255, 255)); lblStatus.setForeground(new Color(255, 255, 255));
lblStatus.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblStatus.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblStatus.setBounds(343, 9, 72, 18); lblStatus.setBounds(343, 9, 72, 18);
lblDestination = new JLabel(); lblDestination = new JLabel();
lblDestination.setForeground(new Color(255, 255, 255)); lblDestination.setForeground(new Color(255, 255, 255));
lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblDestination.setFont(new Font("Rockwell", Font.PLAIN, 16));
@ -275,107 +274,107 @@ public class MakkahCity {
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblDate.setForeground(Color.WHITE); lblDate.setForeground(Color.WHITE);
lblDate.setBounds(69, 8, 326, 21); lblDate.setBounds(69, 8, 326, 21);
JLabel lblBuses = new JLabel("Buses: "); JLabel lblBuses = new JLabel("Buses: ");
lblBuses.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblBuses.setForeground(new Color(255, 255, 255)); lblBuses.setForeground(new Color(255, 255, 255));
lblBuses.setBackground(new Color(192, 192, 192)); lblBuses.setBackground(new Color(192, 192, 192));
lblBuses.setBounds(22, 532, 56, 14); lblBuses.setBounds(22, 532, 56, 14);
lblNumOfBuses = new JLabel(); lblNumOfBuses = new JLabel();
lblNumOfBuses.setText("0"); lblNumOfBuses.setText("0");
lblNumOfBuses.setBackground(new Color(0, 0, 0)); lblNumOfBuses.setBackground(new Color(0, 0, 0));
lblNumOfBuses.setForeground(new Color(255, 255, 255)); lblNumOfBuses.setForeground(new Color(255, 255, 255));
lblNumOfBuses.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblNumOfBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblNumOfBuses.setBounds(69, 533, 90, 12); lblNumOfBuses.setBounds(69, 533, 90, 12);
JLabel lblBusesDone = new JLabel("Buses Done:"); JLabel lblBusesDone = new JLabel("Buses Done:");
lblBusesDone.setForeground(new Color(255, 255, 255)); lblBusesDone.setForeground(new Color(255, 255, 255));
lblBusesDone.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblBusesDone.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblBusesDone.setBounds(143, 533, 101, 12); lblBusesDone.setBounds(143, 533, 101, 12);
lblNumOfDonebuses = new JLabel(); lblNumOfDonebuses = new JLabel();
lblNumOfDonebuses.setText("0"); lblNumOfDonebuses.setText("0");
lblNumOfDonebuses.setForeground(new Color(255, 255, 255)); lblNumOfDonebuses.setForeground(new Color(255, 255, 255));
lblNumOfDonebuses.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblNumOfDonebuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblNumOfDonebuses.setBounds(234, 531, 80, 16); lblNumOfDonebuses.setBounds(234, 531, 80, 16);
JLabel lblMaximumTrip = new JLabel("Maximum Trip:"); JLabel lblMaximumTrip = new JLabel("Maximum Trip:");
lblMaximumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblMaximumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblMaximumTrip.setForeground(new Color(255, 255, 255)); lblMaximumTrip.setForeground(new Color(255, 255, 255));
lblMaximumTrip.setBounds(22, 557, 112, 22); lblMaximumTrip.setBounds(22, 557, 112, 22);
lblMaximumTripValue = new JLabel(); lblMaximumTripValue = new JLabel();
lblMaximumTripValue.setText("-:--"); lblMaximumTripValue.setText("-:--");
lblMaximumTripValue.setForeground(new Color(255, 255, 255)); lblMaximumTripValue.setForeground(new Color(255, 255, 255));
lblMaximumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblMaximumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblMaximumTripValue.setBounds(142, 559, 46, 18); lblMaximumTripValue.setBounds(142, 559, 46, 18);
JLabel lblMinimumTrip = new JLabel("Minimum Trip:"); JLabel lblMinimumTrip = new JLabel("Minimum Trip:");
lblMinimumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblMinimumTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblMinimumTrip.setForeground(Color.WHITE); lblMinimumTrip.setForeground(Color.WHITE);
lblMinimumTrip.setBounds(22, 587, 112, 18); lblMinimumTrip.setBounds(22, 587, 112, 18);
lblMinimumTripValue = new JLabel("-:--"); lblMinimumTripValue = new JLabel("-:--");
lblMinimumTripValue.setForeground(Color.WHITE); lblMinimumTripValue.setForeground(Color.WHITE);
lblMinimumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblMinimumTripValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblMinimumTripValue.setBounds(143, 589, 90, 14); lblMinimumTripValue.setBounds(143, 589, 90, 14);
JLabel lblBusesArrivedInTheLastHour = new JLabel("Buses Arrived In The Last Hour:"); JLabel lblBusesArrivedInTheLastHour = new JLabel("Buses Arrived In The Last Hour:");
lblBusesArrivedInTheLastHour.setForeground(Color.WHITE); lblBusesArrivedInTheLastHour.setForeground(Color.WHITE);
lblBusesArrivedInTheLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblBusesArrivedInTheLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblBusesArrivedInTheLastHour.setBounds(333, 532, 237, 14); lblBusesArrivedInTheLastHour.setBounds(333, 532, 237, 14);
lblBusesArrivedInTheLastHourValue = new JLabel(); lblBusesArrivedInTheLastHourValue = new JLabel();
lblBusesArrivedInTheLastHourValue.setText("0"); lblBusesArrivedInTheLastHourValue.setText("0");
lblBusesArrivedInTheLastHourValue.setForeground(Color.WHITE); lblBusesArrivedInTheLastHourValue.setForeground(Color.WHITE);
lblBusesArrivedInTheLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblBusesArrivedInTheLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblBusesArrivedInTheLastHourValue.setBounds(566, 532, 90, 14); lblBusesArrivedInTheLastHourValue.setBounds(566, 532, 90, 14);
JLabel lblAverageTripForLastHour = new JLabel("Average Trip For Last Hour:"); JLabel lblAverageTripForLastHour = new JLabel("Average Trip For Last Hour:");
lblAverageTripForLastHour.setForeground(Color.WHITE); lblAverageTripForLastHour.setForeground(Color.WHITE);
lblAverageTripForLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblAverageTripForLastHour.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblAverageTripForLastHour.setBackground(Color.BLACK); lblAverageTripForLastHour.setBackground(Color.BLACK);
lblAverageTripForLastHour.setBounds(198, 559, 208, 18); lblAverageTripForLastHour.setBounds(198, 559, 208, 18);
lblAverageTripForLastHourValue = new JLabel("(No Arrivals) In Last Hour"); lblAverageTripForLastHourValue = new JLabel("(No Arrivals) In Last Hour");
lblAverageTripForLastHourValue.setForeground(Color.WHITE); lblAverageTripForLastHourValue.setForeground(Color.WHITE);
lblAverageTripForLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblAverageTripForLastHourValue.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblAverageTripForLastHourValue.setBounds(408, 557, 216, 18); lblAverageTripForLastHourValue.setBounds(408, 557, 216, 18);
JLabel lblAvgTime = new JLabel("Average Time For The Trip:"); JLabel lblAvgTime = new JLabel("Average Time For The Trip:");
lblAvgTime.setForeground(Color.WHITE); lblAvgTime.setForeground(Color.WHITE);
lblAvgTime.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblAvgTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblAvgTime.setBounds(198, 582, 208, 29); lblAvgTime.setBounds(198, 582, 208, 29);
lblAverageTimeForTheTrip = new JLabel("-:--"); lblAverageTimeForTheTrip = new JLabel("-:--");
lblAverageTimeForTheTrip.setForeground(Color.WHITE); lblAverageTimeForTheTrip.setForeground(Color.WHITE);
lblAverageTimeForTheTrip.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblAverageTimeForTheTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblAverageTimeForTheTrip.setBounds(408, 589, 101, 14); lblAverageTimeForTheTrip.setBounds(408, 589, 101, 14);
JLabel lblArrivedToArafat = new JLabel("All Arrived To Arafat At:"); JLabel lblArrivedToArafat = new JLabel("All Arrived To Arafat At:");
lblArrivedToArafat.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblArrivedToArafat.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblArrivedToArafat.setForeground(Color.WHITE); lblArrivedToArafat.setForeground(Color.WHITE);
lblArrivedToArafat.setBounds(18, 613, 216, 14); lblArrivedToArafat.setBounds(18, 613, 216, 14);
makkahFrame.getContentPane().add(lblArrivedToArafat); makkahFrame.getContentPane().add(lblArrivedToArafat);
JLabel lblArrivedToHotels = new JLabel("All Arrived To Hotels At:"); JLabel lblArrivedToHotels = new JLabel("All Arrived To Hotels At:");
lblArrivedToHotels.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblArrivedToHotels.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblArrivedToHotels.setForeground(Color.WHITE); lblArrivedToHotels.setForeground(Color.WHITE);
lblArrivedToHotels.setBounds(18, 638, 184, 14); lblArrivedToHotels.setBounds(18, 638, 184, 14);
makkahFrame.getContentPane().add(lblArrivedToHotels); makkahFrame.getContentPane().add(lblArrivedToHotels);
lblArrivedToArafatTime = new JLabel("N/A"); lblArrivedToArafatTime = new JLabel("N/A");
lblArrivedToArafatTime.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblArrivedToArafatTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblArrivedToArafatTime.setForeground(Color.WHITE); lblArrivedToArafatTime.setForeground(Color.WHITE);
lblArrivedToArafatTime.setBounds(208, 613, 358, 14); lblArrivedToArafatTime.setBounds(208, 613, 358, 14);
makkahFrame.getContentPane().add(lblArrivedToArafatTime); makkahFrame.getContentPane().add(lblArrivedToArafatTime);
lblArrivedToHotelsTime = new JLabel("N/A"); lblArrivedToHotelsTime = new JLabel("N/A");
lblArrivedToHotelsTime.setFont(new Font("Rockwell", Font.PLAIN, 16)); lblArrivedToHotelsTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblArrivedToHotelsTime.setForeground(Color.WHITE); lblArrivedToHotelsTime.setForeground(Color.WHITE);
lblArrivedToHotelsTime.setBounds(208, 638, 358, 14); lblArrivedToHotelsTime.setBounds(208, 638, 358, 14);
//Add Elements //Add Elements
makkahFrame.getContentPane().add(streetScroll); makkahFrame.getContentPane().add(streetScroll);
makkahFrame.getContentPane().add(lblAverageTimeForTheTrip); makkahFrame.getContentPane().add(lblAverageTimeForTheTrip);
@ -406,7 +405,7 @@ public class MakkahCity {
makkahFrame.getContentPane().add(lblMinimumTrip); makkahFrame.getContentPane().add(lblMinimumTrip);
makkahFrame.getContentPane().add(btnBrowseHistory); makkahFrame.getContentPane().add(btnBrowseHistory);
makkahFrame.getContentPane().add(btnPause); makkahFrame.getContentPane().add(btnPause);
//Frame Settings //Frame Settings
makkahFrame.getContentPane().setBackground(new Color(50,50,50)); makkahFrame.getContentPane().setBackground(new Color(50,50,50));
makkahFrame.getContentPane().setForeground(new Color(0, 0, 0)); makkahFrame.getContentPane().setForeground(new Color(0, 0, 0));
@ -419,11 +418,11 @@ public class MakkahCity {
makkahFrame.setLocation(200,150); makkahFrame.setLocation(200,150);
makkahFrame.setAutoRequestFocus(false); makkahFrame.setAutoRequestFocus(false);
makkahFrame.setVisible(true); makkahFrame.setVisible(true);
//Set Routes for Campaigns //Set Routes for Campaigns
while(!firstDayTimeMan.isEnded()) { while(!firstDayTimeMan.isEnded()) {
checkInput(); checkInput();
if (!isAllRoutSet) { if (!isAllRoutSet) {
isAllRoutSet = true; isAllRoutSet = true;
setRoutesForCampaigns(Mashier.ARAFAT); setRoutesForCampaigns(Mashier.ARAFAT);
@ -439,16 +438,16 @@ public class MakkahCity {
clearDoneCivilVehicles(); clearDoneCivilVehicles();
addCivilVehicleNoise(); addCivilVehicleNoise();
for (Vehicle vehicle : listOfVehicles) { for (Vehicle vehicle : listOfVehicles) {
if (vehicle.getRoute() == null) if (vehicle.getRoute() == null || vehicle.isArrivedToDest())
continue; continue;
Route route = vehicle.getRoute(); Route route = vehicle.getRoute();
double currentLocation = vehicle.getCurrentLocation(); double currentLocation = vehicle.getCurrentLocation();
if (vehicle.getCurrentStreet() == null && if (vehicle.getCurrentStreet() == null &&
firstDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) % 2 == 0 && firstDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) % 2 == 0 &&
route.getStreets()[0].capcityPoint(0,1000) < 1) { route.getStreets()[0].capcityPoint(0,1000) < 1) {
vehicle.setCurrentStreet(route.getStreets()[0]); vehicle.setCurrentStreet(route.getStreets()[0]);
} }
if (vehicle.getCurrentStreet() != null && vehicle.getCurrentStreet().capcityPoint(currentLocation, if (vehicle.getCurrentStreet() != null && vehicle.getCurrentStreet().capcityPoint(currentLocation,
currentLocation+1000) < 1 ) { currentLocation+1000) < 1 ) {
if (currentLocation >= vehicle.getCurrentStreet().getLength()) { if (currentLocation >= vehicle.getCurrentStreet().getLength()) {
@ -457,11 +456,8 @@ public class MakkahCity {
} }
if (!vehicle.isArrivedToDest()) { if (!vehicle.isArrivedToDest()) {
double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(), double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(),
vehicle.getCurrentLocation()+1000,vehicle)) ; vehicle.getCurrentLocation()+1000,vehicle)) ;
if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * factor ); vehicle.move(vehicle.getMaxSpeed()*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 );
} }
} }
} }
@ -470,7 +466,7 @@ public class MakkahCity {
lblDate.setText(currenttimeManager.getCurrentTime().toString()); lblDate.setText(currenttimeManager.getCurrentTime().toString());
//lblArrivedToArafatTime.setText(getDistTimeForLbl()); //lblArrivedToArafatTime.setText(getDistTimeForLbl());
} }
currenttimeManager = lastDayTimeMan; currenttimeManager = lastDayTimeMan;
System.out.println("\n***************FINSHIED ARAFAT DAY***************"); System.out.println("\n***************FINSHIED ARAFAT DAY***************");
//Collections.shuffle(listOfVehicles); //Collections.shuffle(listOfVehicles);
@ -503,7 +499,7 @@ public class MakkahCity {
clearDoneCivilVehicles(); clearDoneCivilVehicles();
addCivilVehicleNoise(); addCivilVehicleNoise();
for (Vehicle vehicle : listOfVehicles) { for (Vehicle vehicle : listOfVehicles) {
if (vehicle.getRoute() == null) if (vehicle.getRoute() == null || vehicle.isArrivedToDest())
continue; continue;
Route route = vehicle.getRoute(); Route route = vehicle.getRoute();
double currentLocation = vehicle.getCurrentLocation(); double currentLocation = vehicle.getCurrentLocation();
@ -521,10 +517,7 @@ public class MakkahCity {
if (!vehicle.isArrivedToDest()) { if (!vehicle.isArrivedToDest()) {
double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(), double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(),
vehicle.getCurrentLocation()+1000,vehicle)) ; vehicle.getCurrentLocation()+1000,vehicle)) ;
if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * factor ); vehicle.move(vehicle.getMaxSpeed()* 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 );
} }
} }
} }
@ -565,15 +558,15 @@ public class MakkahCity {
private static void startMenu() { private static void startMenu() {
Scanner in = new Scanner(System.in); Scanner in = new Scanner(System.in);
System.out.println("\n"+currenttimeManager.getCurrentTime()+"\n"+ System.out.println("\n"+currenttimeManager.getCurrentTime()+"\n"+
"---------------------------\n" + "---------------------------\n" +
"[1] View Buses\n" + "[1] View Buses\n" +
"[2] View Streets\n" + "[2] View Streets\n" +
"[3] View Campaigns\n" + "[3] View Campaigns\n" +
"[4] View Routes\n" + "[4] View Routes\n" +
"[5] Print report\n" + "[5] Print report\n" +
"[6] Browse History\n" + "[6] Browse History\n" +
"[7] Continue\n" + "[7] Continue\n" +
"[8] Exit"); "[8] Exit");
String choice = in.next(); String choice = in.next();
//Split into methods? //Split into methods?
if (choice.equals("1")){ if (choice.equals("1")){
@ -592,7 +585,7 @@ public class MakkahCity {
stdStreet[i].getPercentRemainingCapacity()); stdStreet[i].getPercentRemainingCapacity());
} }
String input = in.next(); String input = in.next();
int index = Integer.parseInt(input);//TODO: unhandled ex int index = Integer.parseInt(input);
showStreet(stdStreet[index]); showStreet(stdStreet[index]);
} }
if (choice.equals("4")){ if (choice.equals("4")){
@ -695,9 +688,9 @@ public class MakkahCity {
while (!selected){ while (!selected){
System.out.println(new HijriDate(dummyCal.getTimeInMillis())); System.out.println(new HijriDate(dummyCal.getTimeInMillis()));
System.out.print("[1] Forward\n" + System.out.print("[1] Forward\n" +
"[2] Backward\n" + "[2] Backward\n" +
"[3] Select\n" + "[3] Select\n" +
"[4] Return\n"); "[4] Return\n");
String choice = in.next(); String choice = in.next();
if (choice.equals("1")) dummyCal.roll(Calendar.HOUR, 1); if (choice.equals("1")) dummyCal.roll(Calendar.HOUR, 1);
if (choice.equals("2")) dummyCal.roll(Calendar.HOUR, -1); if (choice.equals("2")) dummyCal.roll(Calendar.HOUR, -1);
@ -784,9 +777,9 @@ public class MakkahCity {
District.ALHIJRA, Mashier.ARAFAT); District.ALHIJRA, Mashier.ARAFAT);
stdRoutes[RouteName.AlHijraToArafat2.ordinal()] = new Route(new Street[]{ stdRoutes[RouteName.AlHijraToArafat2.ordinal()] = new Route(new Street[]{
stdStreet[StreetNames.JABAL_THAWR_STREET.ordinal()], stdStreet[StreetNames.JABAL_THAWR_STREET.ordinal()],
stdStreet[StreetNames.FOURTH_HIGHWAY2.ordinal()], stdStreet[StreetNames.FOURTH_HIGHWAY2.ordinal()],
stdStreet[StreetNames.STREET1.ordinal()] stdStreet[StreetNames.STREET1.ordinal()]
},District.ALHIJRA, Mashier.ARAFAT); },District.ALHIJRA, Mashier.ARAFAT);
stdRoutes[RouteName.AlMansoorToArafat1.ordinal()] = new Route( stdRoutes[RouteName.AlMansoorToArafat1.ordinal()] = new Route(
@ -820,7 +813,7 @@ public class MakkahCity {
stdStreet[StreetNames.KA_STREET.ordinal()], stdStreet[StreetNames.KA_STREET.ordinal()],
stdStreet[StreetNames.STREET2.ordinal()], stdStreet[StreetNames.STREET2.ordinal()],
stdStreet[StreetNames.STREET1.ordinal()] stdStreet[StreetNames.STREET1.ordinal()]
},District.ALAZIZIYA, Mashier.ARAFAT); },District.ALAZIZIYA, Mashier.ARAFAT);
//******Arafat day end //******Arafat day end
@ -894,9 +887,9 @@ public class MakkahCity {
private static void addCivilVehicleNoise() { private static void addCivilVehicleNoise() {
for (Street street: stdStreet) { for (Street street: stdStreet) {
if (street.getPercentRemainingCapacity() >= 80) if (street.getPercentRemainingCapacity() >= 80)
continue; continue;
int numOfSedan = (int)getRandom(10,15); int numOfSedan = (int)getRandom(10,15);
int numOfSUV = (int)getRandom(5,9); int numOfSUV = (int)getRandom(5,9);
int numOfTruck = (int)getRandom(3,6); int numOfTruck = (int)getRandom(3,6);
@ -911,7 +904,7 @@ public class MakkahCity {
if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfSedan = (int) (numOfSedan * 1.2); if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfSedan = (int) (numOfSedan * 1.2);
for (int x = 0; x < numOfSedan; x++) { for (int x = 0; x < numOfSedan; x++) {
Sedan car = new Sedan(getRandom(4, 5)); Sedan car = new Sedan(getRandom(4, 5));
double pointOfEntry = getRandom(0, street.getLength());//TODO: consider getLength - x double pointOfEntry = getRandom(0, street.getLength());
if (street.capcityPoint(pointOfEntry, pointOfEntry+1500) < 1){ if (street.capcityPoint(pointOfEntry, pointOfEntry+1500) < 1){
listOfVehicles.add(car); listOfVehicles.add(car);
car.setCurrentLocation(pointOfEntry); car.setCurrentLocation(pointOfEntry);
@ -924,7 +917,7 @@ public class MakkahCity {
if (street.getName() == StreetNames.FOURTH_HIGHWAY1) numOfTruck = (int) (numOfTruck * 0.5); if (street.getName() == StreetNames.FOURTH_HIGHWAY1) numOfTruck = (int) (numOfTruck * 0.5);
if (street.getName() == StreetNames.FOURTH_HIGHWAY2) numOfTruck = (int) (numOfTruck * 0.5); if (street.getName() == StreetNames.FOURTH_HIGHWAY2) numOfTruck = (int) (numOfTruck * 0.5);
if (street.getName() == StreetNames.STREET3) numOfTruck = (int) (numOfTruck * 1.5); if (street.getName() == StreetNames.STREET3) numOfTruck = (int) (numOfTruck * 1.5);
if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfSedan = (int) (numOfSedan * 1.2); if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfTruck = (int) (numOfTruck * 1.2);
for (int x = 0; x < numOfTruck; x++) { for (int x = 0; x < numOfTruck; x++) {
Truck car = new Truck(getRandom(4, 5)); Truck car = new Truck(getRandom(4, 5));
double pointOfEntry = getRandom(0, street.getLength()); double pointOfEntry = getRandom(0, street.getLength());
@ -939,7 +932,7 @@ public class MakkahCity {
if (street.getName() == StreetNames.FOURTH_HIGHWAY1) numOfSUV = (int) (numOfSUV * 0.5); if (street.getName() == StreetNames.FOURTH_HIGHWAY1) numOfSUV = (int) (numOfSUV * 0.5);
if (street.getName() == StreetNames.FOURTH_HIGHWAY2) numOfSUV = (int) (numOfSUV * 0.5); if (street.getName() == StreetNames.FOURTH_HIGHWAY2) numOfSUV = (int) (numOfSUV * 0.5);
if (street.getName() == StreetNames.STREET3) numOfSUV = (int) (numOfSUV * 1.5); if (street.getName() == StreetNames.STREET3) numOfSUV = (int) (numOfSUV * 1.5);
if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfSUV = (int) (numOfSedan * 1.2); if (street.getName() == StreetNames.IBRAHIM_ALKHALIL2) numOfSUV = (int) (numOfSUV * 1.2);
for (int x = 0; x < numOfSUV; x++) { for (int x = 0; x < numOfSUV; x++) {
SUV car = new SUV(getRandom(4, 5)); SUV car = new SUV(getRandom(4, 5));
double pointOfEntry = getRandom(0, street.getLength()); double pointOfEntry = getRandom(0, street.getLength());
@ -950,7 +943,6 @@ public class MakkahCity {
car.setCurrentStreet(street); car.setCurrentStreet(street);
} }
} }
} }
} }
@ -958,12 +950,6 @@ public class MakkahCity {
return currenttimeManager; return currenttimeManager;
} }
/**
* Find shortest path without respect to traffic
* @param campaign
* @return
*/
private static Route getBestRoute(Campaign campaign , Mashier mashier) { private static Route getBestRoute(Campaign campaign , Mashier mashier) {
//ArrayList<Route> routes = (ArrayList<Route>) Arrays.asList(getRoutesToDistrict(campaign.getHotelDistrict())); //ArrayList<Route> routes = (ArrayList<Route>) Arrays.asList(getRoutesToDistrict(campaign.getHotelDistrict()));
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict()); Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
@ -982,14 +968,14 @@ public class MakkahCity {
} }
return null; return null;
} }
private static Route[] sortRoutes(Route[] routes) { private static Route[] sortRoutes(Route[] routes) {
Route[] sortingRoute = new Route[routes.length]; Route[] sortingRoute = new Route[routes.length];
double[] lengthes = new double[routes.length]; double[] lengthes = new double[routes.length];
for (int i = 0; i < lengthes.length ; i++) for (int i = 0; i < lengthes.length ; i++)
lengthes[i] = routes[i].getTotalLength(); lengthes[i] = routes[i].getTotalLength();
Arrays.sort(lengthes); Arrays.sort(lengthes);
for (int i = 0; i < lengthes.length ; i++) { for (int i = 0; i < lengthes.length ; i++) {
for (Route r : routes) for (Route r : routes)
@ -998,7 +984,12 @@ public class MakkahCity {
} }
return sortingRoute; return sortingRoute;
} }
/**
* Find shortest path without respect to traffic
* @param campaign
* @return
*/
public static Route getShortestRoute(Campaign campaign, Mashier mashier) { public static Route getShortestRoute(Campaign campaign, Mashier mashier) {
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict()); Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
Route route = null; Route route = null;
@ -1029,14 +1020,14 @@ public class MakkahCity {
Route[] routesArray = new Route[routes.size()]; Route[] routesArray = new Route[routes.size()];
return routes.toArray(routesArray); return routes.toArray(routesArray);
} }
private static String getStreetsReport() { private static String getStreetsReport() {
String status = ""; String status = "";
if (currenttimeManager == firstDayTimeMan) status = " Status: Heading to Arafat"; if (currenttimeManager == firstDayTimeMan) status = " Status: Heading to Arafat";
else status = " Status: Heading to hotels"; else status = " Status: Heading to hotels";
String headerFormat = "******Streets report*****\n" + String headerFormat = "******Streets report*****\n" +
"Time: %s%s\n" + "Time: %s%s\n" +
" Street name |Street Load| Total | Buses | Local Vehicles | Avg. Time |\n"; " Street name |Street Load| Total | Buses | Local Vehicles | Avg. Time |\n";
StringBuilder report = new StringBuilder(); StringBuilder report = new StringBuilder();
report.append(String.format(headerFormat, currenttimeManager.getCurrentTime(), status)); report.append(String.format(headerFormat, currenttimeManager.getCurrentTime(), status));
@ -1057,7 +1048,7 @@ public class MakkahCity {
report.append(preSimulationReport()).append("Type m+Enter to view menu"); report.append(preSimulationReport()).append("Type m+Enter to view menu");
return report.toString(); return report.toString();
} }
private static String getFinalRep() { private static String getFinalRep() {
StringBuilder s = new StringBuilder(); StringBuilder s = new StringBuilder();
int numberOfBusses = 0; int numberOfBusses = 0;
@ -1065,7 +1056,7 @@ public class MakkahCity {
//Redundant loops slow down execution. find better sol. //Redundant loops slow down execution. find better sol.
for (Campaign campaign : listOfCampaigns) { for (Campaign campaign : listOfCampaigns) {
numberOfBusses += campaign.getNumberOfBusses(); numberOfBusses += campaign.getNumberOfBusses();
} }
String fFormat = "All arrived to %s at: %s"; String fFormat = "All arrived to %s at: %s";
boolean arr = isAllArrived();//since it has looping. use once. boolean arr = isAllArrived();//since it has looping. use once.
if (arr && allArrivedToArafatTime != null) if (arr && allArrivedToArafatTime != null)
@ -1076,13 +1067,13 @@ public class MakkahCity {
numberOfBusses, numberOfArrivedBuses, minMaxRep() , getNumberOfArrivedBussesPerHour(), avgTimeOfTrip())); numberOfBusses, numberOfArrivedBuses, minMaxRep() , getNumberOfArrivedBussesPerHour(), avgTimeOfTrip()));
return s.toString(); return s.toString();
} }
private static String minMaxRep() { private static String minMaxRep() {
StringBuilder report = new StringBuilder(); StringBuilder report = new StringBuilder();
if (Vehicle.getMaxArrived() != null && Vehicle.getMinArrived() != null) { if (Vehicle.getMaxArrived() != null && Vehicle.getMinArrived() != null) {
report.append(String.format(" Maximum trip %s,", Vehicle.getMaxArrived().timeToString())); report.append(String.format(" Maximum trip %s,", Vehicle.getMaxArrived().timeToString()));
report.append(String.format(" Minimum trip %s", Vehicle.getMinArrived().timeToString())); report.append(String.format(" Minimum trip %s", Vehicle.getMinArrived().timeToString()));
} }
return report.toString(); return report.toString();
} }
@ -1100,7 +1091,7 @@ public class MakkahCity {
for (Campaign campaign : listOfCampaigns){ for (Campaign campaign : listOfCampaigns){
for (Vehicle bus : campaign.getVehicles()){ for (Vehicle bus : campaign.getVehicles()){
if (bus.isArrivedToDest() && bus.getTimeOfArrival().before(now.getTime()) if (bus.isArrivedToDest() && bus.getTimeOfArrival().before(now.getTime())
&& bus.getTimeOfArrival().after(from.getTime())) { && bus.getTimeOfArrival().after(from.getTime())) {
long minutes = (bus.getTimeOfArrival().getTime() - bus.getTimeStartedMoving().getTime())/60000; long minutes = (bus.getTimeOfArrival().getTime() - bus.getTimeStartedMoving().getTime())/60000;
sum+= minutes; sum+= minutes;
counter++; counter++;
@ -1146,7 +1137,7 @@ public class MakkahCity {
for (Campaign campaign : listOfCampaigns) { for (Campaign campaign : listOfCampaigns) {
for (Vehicle vehicle : campaign.getVehicles()){ for (Vehicle vehicle : campaign.getVehicles()){
if (vehicle instanceof Bus && if (vehicle instanceof Bus &&
vehicle.isArrivedToDest()) num++; vehicle.isArrivedToDest()) num++;
} }
} }
return num; return num;
@ -1160,19 +1151,19 @@ public class MakkahCity {
for (Campaign campaign : listOfCampaigns){ for (Campaign campaign : listOfCampaigns){
for (Vehicle bus : campaign.getVehicles()){ for (Vehicle bus : campaign.getVehicles()){
if (bus.isArrivedToDest() && bus.getTimeOfArrival().before(now.getTime()) if (bus.isArrivedToDest() && bus.getTimeOfArrival().before(now.getTime())
&& bus.getTimeOfArrival().after(from.getTime())) { && bus.getTimeOfArrival().after(from.getTime())) {
num++; num++;
} }
} }
} }
return num; return num;
} }
private static boolean isAllArrived() { private static boolean isAllArrived() {
for (Campaign campaign : listOfCampaigns) for (Campaign campaign : listOfCampaigns)
if (!campaign.isDone()) if (!campaign.isDone())
return false; return false;
return true; return true;
} }
@ -1237,7 +1228,7 @@ public class MakkahCity {
if (!result) System.out.println("Could not save state "+currenttimeManager.getCurrentTime().getTime()); if (!result) System.out.println("Could not save state "+currenttimeManager.getCurrentTime().getTime());
} }
private static void updateStreetFrame() { private static void updateStreetFrame() {
Object[][] streetData = new Object[stdStreet.length][6]; Object[][] streetData = new Object[stdStreet.length][6];
for (int i = 0; i < stdStreet.length; i++) { for (int i = 0; i < stdStreet.length; i++) {
streetData[i][0] = stdStreet[i].getName().name(); streetData[i][0] = stdStreet[i].getName().name();
@ -1271,82 +1262,82 @@ public class MakkahCity {
if (lblArrivedToArafatTime.getText().equalsIgnoreCase("N/A")) if (lblArrivedToArafatTime.getText().equalsIgnoreCase("N/A"))
if (allArrivedToArafatTime != null) { if (allArrivedToArafatTime != null) {
lblArrivedToArafatTime.setText(allArrivedToArafatTime.toString()); lblArrivedToArafatTime.setText(allArrivedToArafatTime.toString());
} }
if (lblArrivedToHotelsTime.getText().equalsIgnoreCase("N/A")) if (lblArrivedToHotelsTime.getText().equalsIgnoreCase("N/A"))
if (allArrivedToHotelsTime != null) { if (allArrivedToHotelsTime != null) {
lblArrivedToHotelsTime.setText(allArrivedToHotelsTime.toString()); lblArrivedToHotelsTime.setText(allArrivedToHotelsTime.toString());
}
String status = "";
if (currenttimeManager == firstDayTimeMan) {
status = "Heading to Arafat";
}
else{
status = "Heading to Hotels";
} }
lblDestination.setText(status);
String status = "";
int numberOfBusses = 0; if (currenttimeManager == firstDayTimeMan) {
for (Campaign campaign : listOfCampaigns) { status = "Heading to Arafat";
numberOfBusses += campaign.getNumberOfBusses(); }
} else{
String bus = String.format("%d", numberOfBusses); status = "Heading to Hotels";
lblNumOfBuses.setText(bus); }
lblDestination.setText(status);
int numberOfBusses = 0;
for (Campaign campaign : listOfCampaigns) {
numberOfBusses += campaign.getNumberOfBusses();
}
String bus = String.format("%d", numberOfBusses);
lblNumOfBuses.setText(bus);
String numOfdoneBuses = String.format("%d",getNumberOfArrivedBusses()); String numOfdoneBuses = String.format("%d",getNumberOfArrivedBusses());
lblNumOfDonebuses.setText(numOfdoneBuses); lblNumOfDonebuses.setText(numOfdoneBuses);
if (Vehicle.getMaxArrived() != null && Vehicle.getMinArrived() != null) { if (Vehicle.getMaxArrived() != null && Vehicle.getMinArrived() != null) {
lblMaximumTripValue.setText(Vehicle.getMaxArrived().getTripTime().toString()); lblMaximumTripValue.setText(Vehicle.getMaxArrived().getTripTime().toString());
lblMinimumTripValue.setText(Vehicle.getMinArrived().getTripTime().toString()); lblMinimumTripValue.setText(Vehicle.getMinArrived().getTripTime().toString());
} }
String NumberOfBussPerHour = String.format("%d", getNumberOfArrivedBussesPerHour()); String NumberOfBussPerHour = String.format("%d", getNumberOfArrivedBussesPerHour());
lblBusesArrivedInTheLastHourValue.setText(NumberOfBussPerHour); lblBusesArrivedInTheLastHourValue.setText(NumberOfBussPerHour);
lblAverageTripForLastHourValue.setText(avgTimeOfTrip()); lblAverageTripForLastHourValue.setText(avgTimeOfTrip());
lblAverageTimeForTheTrip.setText(getAvgTripForAllDis()); lblAverageTimeForTheTrip.setText(getAvgTripForAllDis());
}
public static String getAvgTripForAllDis() {
int sum = 0;
int counter = 1;
for (Campaign campaign : listOfCampaigns) {
for (Vehicle vehicle : campaign.getVehicles()) {
if (vehicle.isArrivedToDest()) {
long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000;
sum+= minutes;
counter++;
}
}
}//Make the following a method since it is the same other method
sum = sum /counter;
int hours = sum / 60;
int minutes = sum % 60;
if (hours == 0 && minutes == 0) return "-:--";
return String.format("%2d:%02d", hours,minutes);
}
private static String getDistTimeForLbl() { }
int numberOfBusses = 0;
int numberOfArrivedBuses = getNumberOfArrivedBusses(); public static String getAvgTripForAllDis() {
int sum = 0;
for (Campaign campaign : listOfCampaigns) { int counter = 1;
numberOfBusses += campaign.getNumberOfBusses(); for (Campaign campaign : listOfCampaigns) {
} for (Vehicle vehicle : campaign.getVehicles()) {
if (vehicle.isArrivedToDest()) {
boolean Done = isAllArrived(); long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000;
if (Done && allArrivedToArafatTime != null) { sum+= minutes;
return String.format("%s", allArrivedToArafatTime); counter++;
}
} }
if (Done && allArrivedToHotelsTime != null) { }//Make the following a method since it is the same other method
return String.format("%s",allArrivedToHotelsTime); sum = sum /counter;
} int hours = sum / 60;
return "N/A"; int minutes = sum % 60;
} if (hours == 0 && minutes == 0) return "-:--";
return String.format("%2d:%02d", hours,minutes);
}
private static String getDistTimeForLbl() {
int numberOfBusses = 0;
int numberOfArrivedBuses = getNumberOfArrivedBusses();
for (Campaign campaign : listOfCampaigns) {
numberOfBusses += campaign.getNumberOfBusses();
}
boolean Done = isAllArrived();
if (Done && allArrivedToArafatTime != null) {
return String.format("%s", allArrivedToArafatTime);
}
if (Done && allArrivedToHotelsTime != null) {
return String.format("%s",allArrivedToHotelsTime);
}
return "N/A";
}
} }

View File

@ -1,9 +1,9 @@
public class SUV extends CivilVehicle { public class SUV extends CivilVehicle {
private String UID; private short UID;
private static int numeberOfSUV; private static short numeberOfSUV;
private final int TIME_TO_FIX = 15; //in minutes private final short TIME_TO_FIX = 15; //in minutes
public static final int MAX_FORWARD = 1300; public static final short MAX_FORWARD = 1300;
public SUV(double vehicleSize){ public SUV(double vehicleSize){
super(vehicleSize); super(vehicleSize);
@ -21,12 +21,11 @@ public class SUV extends CivilVehicle {
private void generateUID() { private void generateUID() {
numeberOfSUV++; numeberOfSUV++;
this.UID = String.format("SUV%04d", numeberOfSUV); this.UID = numeberOfSUV;
} }
public String getUID(){ public String getUID(){
return this.UID; return String.format("SUV%04d", UID);
} }

View File

@ -1,10 +1,10 @@
public class Sedan extends CivilVehicle { public class Sedan extends CivilVehicle {
private String UID; private short UID;
private static int numeberOfSedan; private static short numeberOfSedan;
private final int TIME_TO_FIX = 15; //in minutes private final short TIME_TO_FIX = 15; //in minutes
public static final int MAX_FORWARD = 1500; // Meter/Min public static final short MAX_FORWARD = 1500; // Meter/Min
public Sedan(double vehicleSize){ public Sedan(double vehicleSize){
super(vehicleSize); super(vehicleSize);
@ -16,12 +16,11 @@ public class Sedan extends CivilVehicle {
private void generateUID() { private void generateUID() {
numeberOfSedan++; numeberOfSedan++;
this.UID = String.format("Sedan%04d", numeberOfSedan); this.UID = numeberOfSedan;
} }
public String getUID(){ public String getUID(){
return this.UID; return String.format("Sedan%04d", UID);
} }
@Override @Override

View File

@ -1,8 +1,8 @@
public class Truck extends CivilVehicle { public class Truck extends CivilVehicle {
private String UID; private short UID;
private static int numeberOfTruck; private static short numeberOfTruck;
private final int TIME_TO_FIX = 20; //in minutes private final short TIME_TO_FIX = 20; //in minutes
@Override @Override
public int getMaxSpeed() { public int getMaxSpeed() {
@ -19,12 +19,13 @@ public class Truck extends CivilVehicle {
} }
private void generateUID() { private void generateUID() {
numeberOfTruck++; numeberOfTruck++;
this.UID = String.format("Truck%04d", numeberOfTruck); this.UID = numeberOfTruck;
} }
public String getUID(){ public String getUID(){
return this.UID; return String.format("Truck%04d", UID);
} }
}
}