Merge branch 'master' into history-bin
This commit is contained in:
commit
89f7946f98
@ -1,7 +1,11 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class MakkahCity {
|
public class MakkahCity {
|
||||||
|
|
||||||
private static final ArrayList<Campaign> listOfCampaigns = new ArrayList<>();
|
private static final ArrayList<Campaign> listOfCampaigns = new ArrayList<>();
|
||||||
@ -26,6 +30,15 @@ public class MakkahCity {
|
|||||||
|
|
||||||
private static final InputListener inputListener = new InputListener();
|
private static final InputListener inputListener = new InputListener();
|
||||||
private static final Thread t = new Thread(inputListener,"InputThread-Makkah");
|
private static final Thread t = new Thread(inputListener,"InputThread-Makkah");
|
||||||
|
private static boolean isAllRoutSet;
|
||||||
|
|
||||||
|
private static boolean exit_flag;
|
||||||
|
private static Checkbox autoModeCheckBox;
|
||||||
|
private static JFrame makkahFrame;
|
||||||
|
private static JTable streetTable;
|
||||||
|
private static JTable districtTable;
|
||||||
|
private static JLabel lblDate;
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
@ -37,17 +50,172 @@ 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);
|
||||||
|
|
||||||
fillBusesToList();
|
fillBusesToList();
|
||||||
|
|
||||||
makeStreets();
|
makeStreets();
|
||||||
|
|
||||||
addCivilVehicleNoise();
|
addCivilVehicleNoise();
|
||||||
|
|
||||||
makeRoutes();
|
makeRoutes();
|
||||||
|
|
||||||
|
// Vehicle car = traceCar();
|
||||||
|
|
||||||
|
|
||||||
|
//GUI
|
||||||
|
autoModeCheckBox = new Checkbox();
|
||||||
|
makkahFrame = new JFrame("Streets");
|
||||||
|
|
||||||
|
//Street data and district for GUI table
|
||||||
|
|
||||||
|
//Street data
|
||||||
|
Object[][] streetData = new Object[stdStreet.length][6];
|
||||||
|
String[] streetColNames = {"Street Name", "Street Load", "Total", "Buses",
|
||||||
|
"Local Vehicles",
|
||||||
|
"Avg. Time"};
|
||||||
|
|
||||||
|
for (int i = 0; i < stdStreet.length; i++) {
|
||||||
|
streetData[i][0] = stdStreet[i].getName().name();
|
||||||
|
streetData[i][1] = stdStreet[i].getPercentRemainingCapacity();
|
||||||
|
streetData[i][2] = stdStreet[i].getVehicles().size();
|
||||||
|
streetData[i][3] = stdStreet[i].getNumberOfBuses();
|
||||||
|
streetData[i][4] = stdStreet[i].getNumberOfLocalCars();
|
||||||
|
streetData[i][5] = avgTimeOnStreet(stdStreet[i]);
|
||||||
|
}
|
||||||
|
//District data
|
||||||
|
Object[][] districtData = new Object[campPerDistrict.length][7];
|
||||||
|
String[] districtColNames = {"District", "Campaigns", "Busses", "Arrival",
|
||||||
|
"Avg. Time", "Best time to Arafat", "Best time to District"};
|
||||||
|
|
||||||
|
for (int i = 0; i < campPerDistrict.length; i++) {
|
||||||
|
districtData[i][0] = campPerDistrict[i].get(0).getHotelDistrict().name();
|
||||||
|
districtData[i][1] = campPerDistrict[i].size();
|
||||||
|
districtData[i][2] = busesInDistrict(District.values()[i]);
|
||||||
|
districtData[i][3] = getPercentArrival(District.values()[i]);
|
||||||
|
districtData[i][4] = getAvgTimeOfTrip(District.values()[i]);
|
||||||
|
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());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//tables
|
||||||
|
|
||||||
|
//Street table
|
||||||
|
streetTable = new JTable(streetData,streetColNames);
|
||||||
|
DefaultTableModel model = new DefaultTableModel();
|
||||||
|
model.setColumnIdentifiers(streetColNames);
|
||||||
|
streetTable.getTableHeader().setBackground(new Color(17,17,17));
|
||||||
|
streetTable.getTableHeader().setForeground(Color.WHITE);
|
||||||
|
streetTable.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||||
|
streetTable.setBackground(new Color(17,17,17));
|
||||||
|
streetTable.setForeground(Color.white);
|
||||||
|
streetTable.setSelectionBackground(Color.RED);
|
||||||
|
streetTable.setGridColor(new Color(102, 102, 102));
|
||||||
|
streetTable.setSelectionForeground(Color.white);
|
||||||
|
streetTable.setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||||
|
streetTable.setRowHeight(30);
|
||||||
|
streetTable.setAutoCreateRowSorter(true);
|
||||||
|
makkahFrame.setLocation(700, 200);
|
||||||
|
makkahFrame.revalidate();
|
||||||
|
JScrollPane streetScroll = new JScrollPane(streetTable);
|
||||||
|
streetScroll.setBounds(50,145,1271,391);
|
||||||
|
|
||||||
|
//District table
|
||||||
|
districtTable = new JTable(districtData,districtColNames);
|
||||||
|
districtTable.setForeground(new Color(255, 255, 255));
|
||||||
|
districtTable.getTableHeader().setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||||
|
districtTable.getTableHeader().setBackground(new Color(17,17,17));
|
||||||
|
districtTable.getTableHeader().setForeground(Color.WHITE);
|
||||||
|
districtTable.setBackground(new Color(17,17,17));
|
||||||
|
districtTable.setSelectionBackground(Color.RED);
|
||||||
|
model.setColumnIdentifiers(districtColNames);
|
||||||
|
districtTable.setSelectionForeground(Color.white);
|
||||||
|
districtTable.setFont(new Font("Rockwell", Font.PLAIN, 18));
|
||||||
|
districtTable.setGridColor(new Color(102, 102, 102));
|
||||||
|
JScrollPane districtScroll = new JScrollPane(districtTable);
|
||||||
|
districtTable.setAutoCreateRowSorter(true);
|
||||||
|
districtTable.setRowHeight(30);
|
||||||
|
districtTable.revalidate();
|
||||||
|
districtScroll.setBounds(61,791,1271,121);
|
||||||
|
|
||||||
|
//Buttons
|
||||||
|
JButton btnViewRoutes = new JButton("View Routes");
|
||||||
|
btnViewRoutes.setBounds(1384, 35, 184, 29);
|
||||||
|
makkahFrame.getContentPane().add(btnViewRoutes);
|
||||||
|
btnViewRoutes.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
btnViewRoutes.setBackground(new Color(9,9,9));
|
||||||
|
btnViewRoutes.setForeground(Color.white);
|
||||||
|
|
||||||
|
JButton btnViewBuses = new JButton("View Buses");
|
||||||
|
btnViewBuses.setBounds(1384, 75, 184, 29);
|
||||||
|
makkahFrame.getContentPane().add(btnViewBuses);
|
||||||
|
btnViewBuses.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
btnViewBuses.setBackground(new Color(9,9,9));
|
||||||
|
btnViewBuses.setForeground(Color.white);
|
||||||
|
|
||||||
|
JButton btnViewCampaigns = new JButton("View Campaigns");
|
||||||
|
btnViewCampaigns.setBounds(1384, 115, 184, 29);
|
||||||
|
makkahFrame.getContentPane().add(btnViewCampaigns);
|
||||||
|
btnViewCampaigns.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
btnViewCampaigns.setBackground(new Color(9,9,9));
|
||||||
|
btnViewCampaigns.setForeground(Color.white);
|
||||||
|
|
||||||
|
JButton btnViewStreet = new JButton("View Street");
|
||||||
|
btnViewStreet.setBounds(1384, 156, 184, 29);
|
||||||
|
makkahFrame.getContentPane().add(btnViewStreet);
|
||||||
|
btnViewStreet.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
btnViewStreet.setBackground(new Color(9,9,9));
|
||||||
|
btnViewStreet.setForeground(Color.white);
|
||||||
|
|
||||||
|
JButton btnExit = new JButton("Exit");
|
||||||
|
btnExit.setBackground(new Color(9,9,9));
|
||||||
|
btnExit.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
btnExit.setForeground(Color.white);
|
||||||
|
btnExit.setBounds(1427, 908, 184, 23);
|
||||||
|
makkahFrame.getContentPane().add(btnExit);
|
||||||
|
btnExit.addActionListener(actionEvent -> exit_flag = true);
|
||||||
|
|
||||||
|
//Label
|
||||||
|
JLabel lblStreets = new JLabel("Streets History");
|
||||||
|
lblStreets.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
||||||
|
lblStreets.setForeground(new Color(255, 255, 255));
|
||||||
|
lblStreets.setBounds(50, 104, 208, 30);
|
||||||
|
|
||||||
|
JLabel lblDistrict = new JLabel("District History");
|
||||||
|
lblDistrict.setFont(new Font("Rockwell", Font.PLAIN, 24));
|
||||||
|
lblDistrict.setForeground(new Color(255, 255, 255));
|
||||||
|
lblDistrict.setBounds(61, 757, 166, 23);
|
||||||
|
|
||||||
|
JLabel lblTime = new JLabel("Time: ");
|
||||||
|
lblTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
lblTime.setForeground(new Color(255, 255, 255));
|
||||||
|
lblTime.setBounds(50, 11, 72, 14);
|
||||||
|
|
||||||
|
|
||||||
|
//window
|
||||||
|
makkahFrame.getContentPane().setBackground(new Color(70, 70, 70));
|
||||||
|
makkahFrame.getContentPane().setForeground(SystemColor.inactiveCaptionBorder);
|
||||||
|
makkahFrame.setBounds(100,100,1637,1019);
|
||||||
|
makkahFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
makkahFrame.getContentPane().setLayout(null);
|
||||||
|
makkahFrame.setLocationRelativeTo(null);
|
||||||
|
makkahFrame.getContentPane().add(streetScroll);
|
||||||
|
makkahFrame.getContentPane().add(districtScroll);
|
||||||
|
makkahFrame.getContentPane().add(lblDistrict);
|
||||||
|
makkahFrame.getContentPane().add(lblStreets);
|
||||||
|
makkahFrame.setVisible(true);
|
||||||
|
makkahFrame.getContentPane().add(lblTime);
|
||||||
|
|
||||||
|
lblDate = new JLabel(currenttimeManager.getCurrentTime().toString());
|
||||||
|
lblDate.setFont(new Font("Rockwell", Font.PLAIN, 16));
|
||||||
|
lblDate.setForeground(Color.WHITE);
|
||||||
|
lblDate.setBounds(107, 4, 326, 29);
|
||||||
|
makkahFrame.getContentPane().add(lblDate);
|
||||||
|
makkahFrame.revalidate();
|
||||||
|
|
||||||
//Set Routes for Campaigns
|
//Set Routes for Campaigns
|
||||||
setRoutesForCampaigns(Mashier.ARAFAT);
|
|
||||||
while(!firstDayTimeMan.isEnded()) {
|
while(!firstDayTimeMan.isEnded()) {
|
||||||
checkInput();
|
checkInput();
|
||||||
//Start of Every hour
|
//Start of Every hour
|
||||||
@ -56,13 +224,20 @@ public class MakkahCity {
|
|||||||
saveState();
|
saveState();
|
||||||
}
|
}
|
||||||
else System.out.print(".");
|
else System.out.print(".");
|
||||||
|
|
||||||
|
if (!isAllRoutSet) {
|
||||||
|
isAllRoutSet = true;
|
||||||
|
setRoutesForCampaigns(Mashier.ARAFAT);
|
||||||
|
}
|
||||||
clearDoneCivilVehicles();
|
clearDoneCivilVehicles();
|
||||||
addCivilVehicleNoise();
|
addCivilVehicleNoise();
|
||||||
for (Vehicle vehicle : listOfVehicles) {
|
for (Vehicle vehicle : listOfVehicles) {
|
||||||
|
if (vehicle.getRoute() == null)
|
||||||
|
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 &&
|
||||||
route.getStreets()[0].capcityPoint(0,1000) < 1) {
|
route.getStreets()[0].capcityPoint(0,1000) < 1) {
|
||||||
vehicle.setCurrentStreet(route.getStreets()[0]);
|
vehicle.setCurrentStreet(route.getStreets()[0]);
|
||||||
}
|
}
|
||||||
@ -83,13 +258,16 @@ public class MakkahCity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isAllArrived()) allArrivedToArafatTime = (Date)currenttimeManager.getCurrentTime().clone();
|
if (isAllArrived() && allArrivedToArafatTime == null) allArrivedToArafatTime = (Date)currenttimeManager.getCurrentTime().clone();
|
||||||
|
updateStreetFrame();
|
||||||
firstDayTimeMan.step(Calendar.MINUTE, 1);
|
firstDayTimeMan.step(Calendar.MINUTE, 1);
|
||||||
|
// System.out.println(car);
|
||||||
}
|
}
|
||||||
//TODO make report
|
|
||||||
currenttimeManager = lastDayTimeMan;
|
currenttimeManager = lastDayTimeMan;
|
||||||
System.out.println("\n***************FINSHIED ARAFAT DAY***************");
|
System.out.println("\n***************FINSHIED ARAFAT DAY***************");
|
||||||
setRoutesForCampaigns(Mashier.MINA);
|
//Collections.shuffle(listOfVehicles);
|
||||||
|
isAllRoutSet = false;
|
||||||
for (Vehicle vehicle : listOfVehicles) {
|
for (Vehicle vehicle : listOfVehicles) {
|
||||||
vehicle.setCurrentStreet(null);
|
vehicle.setCurrentStreet(null);
|
||||||
}
|
}
|
||||||
@ -98,6 +276,7 @@ public class MakkahCity {
|
|||||||
addCivilVehicleNoise();
|
addCivilVehicleNoise();
|
||||||
|
|
||||||
System.out.println("***************STARTING LAST DAY***************");
|
System.out.println("***************STARTING LAST DAY***************");
|
||||||
|
setRoutesForCampaigns(Mashier.MINA);
|
||||||
while(!lastDayTimeMan.isEnded()) {
|
while(!lastDayTimeMan.isEnded()) {
|
||||||
checkInput();
|
checkInput();
|
||||||
//Start of Every hour
|
//Start of Every hour
|
||||||
@ -105,10 +284,17 @@ public class MakkahCity {
|
|||||||
System.out.println("\n\n" + getStreetsReport());
|
System.out.println("\n\n" + getStreetsReport());
|
||||||
}
|
}
|
||||||
else System.out.print(".");
|
else System.out.print(".");
|
||||||
|
|
||||||
|
|
||||||
|
if (!isAllRoutSet) {
|
||||||
|
isAllRoutSet = true;
|
||||||
|
setRoutesForCampaigns(Mashier.MINA);
|
||||||
|
}
|
||||||
clearDoneCivilVehicles();
|
clearDoneCivilVehicles();
|
||||||
addCivilVehicleNoise();
|
addCivilVehicleNoise();
|
||||||
for (Vehicle vehicle : listOfVehicles) {
|
for (Vehicle vehicle : listOfVehicles) {
|
||||||
|
if (vehicle.getRoute() == null)
|
||||||
|
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 &&
|
||||||
@ -132,16 +318,28 @@ public class MakkahCity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isAllArrived()) allArrivedToHotelsTime = (Date)currenttimeManager.getCurrentTime().clone();
|
if (isAllArrived() && allArrivedToHotelsTime == null) allArrivedToHotelsTime = (Date)currenttimeManager.getCurrentTime().clone();
|
||||||
lastDayTimeMan.step(Calendar.MINUTE, 1);
|
lastDayTimeMan.step(Calendar.MINUTE, 1);
|
||||||
}
|
}
|
||||||
//When done show menu to analyze. Exit from menu too.
|
//When done show menu to analyze. Exit from menu too.
|
||||||
inputListener.pause();
|
inputListener.pause();
|
||||||
startMenu();
|
startMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Vehicle traceCar() {
|
||||||
|
|
||||||
|
for(int x = 20000; x < listOfVehicles.size(); x++) {
|
||||||
|
if(listOfVehicles.get(x) instanceof Bus)
|
||||||
|
if(((Bus)listOfVehicles.get(x)).getCampaign().getHotelDistrict() == District.ALAZIZIYA) {
|
||||||
|
return listOfVehicles.get(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static void checkInput() {
|
private static void checkInput() {
|
||||||
String input = "";
|
String input = "";
|
||||||
|
if (exit_flag) System.exit(0);
|
||||||
if (inputListener.hasNew()){
|
if (inputListener.hasNew()){
|
||||||
input = inputListener.getInput();
|
input = inputListener.getInput();
|
||||||
if (input.equals("m")){
|
if (input.equals("m")){
|
||||||
@ -154,8 +352,6 @@ public class MakkahCity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void startMenu() {
|
private static void startMenu() {
|
||||||
//TODO: add used by (District) in street menu as option
|
|
||||||
//TODO: add capacity to street list output avg time too?
|
|
||||||
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" +
|
||||||
@ -331,7 +527,10 @@ public class MakkahCity {
|
|||||||
|
|
||||||
private static void setRoutesForCampaigns(Mashier mashier) {
|
private static void setRoutesForCampaigns(Mashier mashier) {
|
||||||
for (Campaign camp : listOfCampaigns){
|
for (Campaign camp : listOfCampaigns){
|
||||||
camp.setRoute(getShortestRoute(camp, mashier));
|
if(camp.getVehicles().get(0).getCurrentStreet() == null) {
|
||||||
|
isAllRoutSet = false;
|
||||||
|
camp.setRoute(getBestRoute(camp, mashier));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,7 +552,7 @@ public class MakkahCity {
|
|||||||
stdStreet[StreetNames.FOURTH_HIGHWAY2.ordinal()] = new Street(4850,4, StreetNames.FOURTH_HIGHWAY2);
|
stdStreet[StreetNames.FOURTH_HIGHWAY2.ordinal()] = new Street(4850,4, StreetNames.FOURTH_HIGHWAY2);
|
||||||
stdStreet[StreetNames.FOURTH_HIGHWAY3.ordinal()] = new Street(4500,4, StreetNames.FOURTH_HIGHWAY3);
|
stdStreet[StreetNames.FOURTH_HIGHWAY3.ordinal()] = new Street(4500,4, StreetNames.FOURTH_HIGHWAY3);
|
||||||
stdStreet[StreetNames.THIRD_HIGHWAY.ordinal()] = new Street(8200,3, StreetNames.THIRD_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.STREET1.ordinal()] = new Street(7800,4, StreetNames.STREET1);
|
||||||
stdStreet[StreetNames.STREET2.ordinal()] = new Street(2400,3,StreetNames.STREET2);
|
stdStreet[StreetNames.STREET2.ordinal()] = new Street(2400,3,StreetNames.STREET2);
|
||||||
stdStreet[StreetNames.STREET3.ordinal()] = new Street(4800,2, StreetNames.STREET3);
|
stdStreet[StreetNames.STREET3.ordinal()] = new Street(4800,2, StreetNames.STREET3);
|
||||||
stdStreet[StreetNames.JABAL_THAWR_STREET.ordinal()] = new Street(3800,3,StreetNames.JABAL_THAWR_STREET);
|
stdStreet[StreetNames.JABAL_THAWR_STREET.ordinal()] = new Street(3800,3,StreetNames.JABAL_THAWR_STREET);
|
||||||
@ -484,7 +683,7 @@ public class MakkahCity {
|
|||||||
private static void addCivilVehicleNoise() {
|
private static void addCivilVehicleNoise() {
|
||||||
|
|
||||||
for (Street street: stdStreet) {
|
for (Street street: stdStreet) {
|
||||||
if (street.getPercentRemainingCapacity() >= 100)
|
if (street.getPercentRemainingCapacity() >= 80)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int numOfSedan = (int)getRandom(10,15);
|
int numOfSedan = (int)getRandom(10,15);
|
||||||
@ -553,6 +752,42 @@ public class MakkahCity {
|
|||||||
* @param campaign
|
* @param campaign
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
private static Route getBestRoute(Campaign campaign , Mashier mashier) {
|
||||||
|
//ArrayList<Route> routes = (ArrayList<Route>) Arrays.asList(getRoutesToDistrict(campaign.getHotelDistrict()));
|
||||||
|
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
|
||||||
|
routes = sortRoutes(routes);
|
||||||
|
for (Route r : routes) {
|
||||||
|
if(r.getMashier() == Mashier.ARAFAT && r.getHotelArea() == District.ALHIJRA) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
if (r.getMashier() == mashier){
|
||||||
|
if (r.capcity() < 70) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
else if (r.getHotelArea() == District.ALAZIZIYA)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Route[] sortRoutes(Route[] routes) {
|
||||||
|
Route[] sortingRoute = new Route[routes.length];
|
||||||
|
double[] lengthes = new double[routes.length];
|
||||||
|
|
||||||
|
for (int i = 0; i < lengthes.length ; i++)
|
||||||
|
lengthes[i] = routes[i].getTotalLength();
|
||||||
|
|
||||||
|
Arrays.sort(lengthes);
|
||||||
|
for (int i = 0; i < lengthes.length ; i++) {
|
||||||
|
for (Route r : routes)
|
||||||
|
if (lengthes[i] == r.getTotalLength())
|
||||||
|
sortingRoute[i] = r;
|
||||||
|
}
|
||||||
|
return sortingRoute;
|
||||||
|
}
|
||||||
|
|
||||||
private static Route getShortestRoute(Campaign campaign, Mashier mashier) {
|
private static Route getShortestRoute(Campaign campaign, Mashier mashier) {
|
||||||
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
|
Route[] routes = getRoutesToDistrict(campaign.getHotelDistrict());
|
||||||
Route route = null;
|
Route route = null;
|
||||||
@ -619,7 +854,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();
|
||||||
} //TODO Add max min time.
|
}
|
||||||
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)
|
||||||
@ -745,7 +980,7 @@ public class MakkahCity {
|
|||||||
report.append(String.format(" %-20s|", getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus())));
|
report.append(String.format(" %-20s|", getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus())));
|
||||||
report.append(String.format(" %-22s|", getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus())));
|
report.append(String.format(" %-22s|", getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus())));
|
||||||
//Calc values per dist here.
|
//Calc values per dist here.
|
||||||
|
//TODO: add arrived buses colum (NO NEED)
|
||||||
report.append("\n");
|
report.append("\n");
|
||||||
}
|
}
|
||||||
return report.toString();
|
return report.toString();
|
||||||
@ -794,4 +1029,22 @@ public class MakkahCity {
|
|||||||
DataManeger dataManeger = new DataManeger();
|
DataManeger dataManeger = new DataManeger();
|
||||||
return dataManeger.loadState(time);
|
return dataManeger.loadState(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void updateStreetFrame() {
|
||||||
|
Object[][] streetData = new Object[stdStreet.length][6];
|
||||||
|
for (int i = 0; i < stdStreet.length; i++) {
|
||||||
|
streetData[i][0] = stdStreet[i].getName().name();
|
||||||
|
streetData[i][1] = stdStreet[i].getPercentRemainingCapacity();
|
||||||
|
streetData[i][2] = stdStreet[i].getVehicles().size();
|
||||||
|
streetData[i][3] = stdStreet[i].getNumberOfBuses();
|
||||||
|
streetData[i][4] = stdStreet[i].getNumberOfLocalCars();
|
||||||
|
streetData[i][5] = avgTimeOnStreet(stdStreet[i]);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < streetData.length; i++) {
|
||||||
|
for (int j = 0; j < streetData[i].length; j++) {
|
||||||
|
streetTable.setValueAt(streetData[i][j], i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lblDate.setText(currenttimeManager.getCurrentTime().toString());
|
||||||
}
|
}
|
||||||
|
}
|
@ -52,6 +52,8 @@ public class Route implements Travelable, Serializable {
|
|||||||
.append("\n")
|
.append("\n")
|
||||||
.append("Length: ").append(getTotalLength())
|
.append("Length: ").append(getTotalLength())
|
||||||
.append("\n")
|
.append("\n")
|
||||||
|
.append("Capacity: ").append(String.format("%.2f", capcity()))
|
||||||
|
.append("\n")
|
||||||
.append("Streets: ");
|
.append("Streets: ");
|
||||||
for (Street street : this.getStreets())
|
for (Street street : this.getStreets())
|
||||||
s.append(street.getName().name()).append(" ");
|
s.append(street.getName().name()).append(" ");
|
||||||
@ -66,6 +68,15 @@ public class Route implements Travelable, Serializable {
|
|||||||
public Mashier getMashier() {
|
public Mashier getMashier() {
|
||||||
return mashier;
|
return mashier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double capcity() {
|
||||||
|
double capcity = 0;
|
||||||
|
for (Street str : getStreets()) {
|
||||||
|
capcity += str.getPercentRemainingCapacity();
|
||||||
|
}
|
||||||
|
double c = capcity/(getStreets().length);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
private void setStreets(Street[] streets) {
|
private void setStreets(Street[] streets) {
|
||||||
if (streets != null) this.streets = streets;
|
if (streets != null) this.streets = streets;
|
||||||
|
104
src/testfx.java
Normal file
104
src/testfx.java
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Group;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TableColumn;
|
||||||
|
import javafx.scene.control.TableView;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
public class testfx extends Application {
|
||||||
|
|
||||||
|
private TableView table = new TableView();
|
||||||
|
Stage window;
|
||||||
|
private Button btVeiwBuses = new Button("View Buses");
|
||||||
|
private Button btViewStreets = new Button("View Streets");
|
||||||
|
private Button btViewCampaigns = new Button("View Campaigns");
|
||||||
|
private Button btViewRoutes= new Button("View Routes");
|
||||||
|
private Button btPrintReport = new Button("Print Report");
|
||||||
|
private Button btExit = new Button("Exit");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage primarystage) {
|
||||||
|
window = primarystage;
|
||||||
|
|
||||||
|
//table title
|
||||||
|
Label Text = new Label("Streets Report");
|
||||||
|
Text.setFont(new Font("Arial", 16));
|
||||||
|
Text.setTextFill(Color.WHITE);
|
||||||
|
|
||||||
|
//table
|
||||||
|
table.setEditable(true);
|
||||||
|
TableColumn streetName = new TableColumn("Street Name");
|
||||||
|
streetName.setPrefWidth(150);
|
||||||
|
streetName.setStyle("-fx-base: SILVER");
|
||||||
|
TableColumn StreetLoad = new TableColumn("Street Load");
|
||||||
|
StreetLoad.setPrefWidth(150);
|
||||||
|
StreetLoad.setStyle("-fx-base: SILVER");
|
||||||
|
TableColumn Total = new TableColumn("Total");
|
||||||
|
Total.setPrefWidth(100);
|
||||||
|
Total.setStyle("-fx-base: SILVER");
|
||||||
|
TableColumn Buses = new TableColumn("Buses");
|
||||||
|
Buses.setStyle("-fx-base: SILVER");
|
||||||
|
TableColumn localVehicles = new TableColumn("Local Vehicles");
|
||||||
|
localVehicles.setStyle("-fx-base: SILVER");
|
||||||
|
localVehicles.setPrefWidth(150);
|
||||||
|
TableColumn avgTime = new TableColumn("Avg. Time");
|
||||||
|
avgTime.setStyle("-fx-base: SILVER");
|
||||||
|
avgTime.setPrefWidth(150);
|
||||||
|
table.getColumns().addAll(streetName, StreetLoad, Total,Buses,localVehicles,avgTime);
|
||||||
|
|
||||||
|
//table root
|
||||||
|
VBox root1 = new VBox();
|
||||||
|
root1.setSpacing(5);
|
||||||
|
root1.setPadding(new Insets(13, 14, 15, 17));
|
||||||
|
root1.getChildren().addAll(Text, table);
|
||||||
|
root1.setAlignment(Pos.CENTER);
|
||||||
|
root1.setStyle("-fx-base: SILVER");
|
||||||
|
|
||||||
|
//buttons
|
||||||
|
HBox root2 = new HBox();
|
||||||
|
root2.getChildren().addAll(btVeiwBuses, btViewStreets, btViewCampaigns,
|
||||||
|
btViewRoutes, btPrintReport, btExit);
|
||||||
|
root2.setSpacing(5);
|
||||||
|
root2.setPadding(new Insets(13, 14, 15, 17));
|
||||||
|
root2.setAlignment(Pos.CENTER);
|
||||||
|
root2.setStyle("-fx-base: SILVER");
|
||||||
|
|
||||||
|
//All Elements
|
||||||
|
VBox root3 = new VBox();
|
||||||
|
root3.setSpacing(5);
|
||||||
|
root3.setPadding(new Insets(13, 14, 15, 17));
|
||||||
|
root3.getChildren().addAll(root1, root2);
|
||||||
|
root3.setAlignment(Pos.CENTER);
|
||||||
|
//widnow
|
||||||
|
StackPane pane = new StackPane(root3);
|
||||||
|
|
||||||
|
pane.setStyle("-fx-background-color: BLACK; "
|
||||||
|
+ "-fx-padding: 5; -fx-font-size: 14;");
|
||||||
|
|
||||||
|
Scene scene = new Scene(pane,850,550);
|
||||||
|
window.setTitle("Hajj Simulation");
|
||||||
|
window.setScene(scene);
|
||||||
|
window.show();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch(args);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user