Keep track of time used on every street on route

This commit is contained in:
HeshamTB 2020-11-26 22:41:24 +03:00
parent ff5c7753ff
commit 51534a5d2b
Signed by: Hesham
GPG Key ID: 74876157D199B09E
2 changed files with 20 additions and 2 deletions

View File

@ -12,6 +12,7 @@ public class Campaign {
private Route route; private Route route;
private ArrayList<Vehicle> vehicles = new ArrayList<>(); private ArrayList<Vehicle> vehicles = new ArrayList<>();
private ArrayList<Vehicle> arrivedVehicles = new ArrayList<>();
private Date timeToLeaveToDest; private Date timeToLeaveToDest;
private Date timeToLeaveToHousing; private Date timeToLeaveToHousing;
@ -32,8 +33,8 @@ public class Campaign {
public void busArived(Bus bus) { public void busArived(Bus bus) {
if(numberOfAriivedBuses < vehicles.size()) if(numberOfAriivedBuses < vehicles.size())
arrivedVehicles.add(bus);
numberOfAriivedBuses++; numberOfAriivedBuses++;
//Check if it is in list before increment?
} }
public boolean isDone() { public boolean isDone() {
@ -49,7 +50,8 @@ public class Campaign {
for (Vehicle vehicle : vehicles) { for (Vehicle vehicle : vehicles) {
vehicle.setRoute(route); vehicle.setRoute(route);
} }
//since a route is set, reset buses. //since a route is set, reset buses and clear arrivedBussesList
this.arrivedVehicles.clear();
this.numberOfAriivedBuses = 0; this.numberOfAriivedBuses = 0;
} }
@ -83,6 +85,15 @@ public class Campaign {
return busses; return busses;
} }
public int getNumberOfArrivedBuses() {
return getArrivedVehicles().size();
}
//Use this in Makkah to optimize later
public ArrayList<Vehicle> getArrivedVehicles() {
return arrivedVehicles;
}
public ArrayList<Vehicle> getVehicles() { public ArrayList<Vehicle> getVehicles() {
return vehicles; return vehicles;
} }

View File

@ -1,4 +1,5 @@
import java.util.Date; import java.util.Date;
import java.util.HashMap;
public abstract class Vehicle { public abstract class Vehicle {
@ -11,6 +12,10 @@ public abstract class Vehicle {
private boolean moving; private boolean moving;
private Date timeStartedMoving; private Date timeStartedMoving;
private Date timeOfArrival; private Date timeOfArrival;
private Date timeStartedOnCurrentStreet;
//Map Street to Minutes
private HashMap<Street, Long> routeTimeHistory = new HashMap<>();
public abstract int getMaxSpeed(); public abstract int getMaxSpeed();
@ -84,6 +89,7 @@ public abstract class Vehicle {
this.currentStreet = currentStreet; this.currentStreet = currentStreet;
if (this.currentStreet != null) if (this.currentStreet != null)
this.currentStreet.addVehicle(this); this.currentStreet.addVehicle(this);
this.timeStartedOnCurrentStreet = MakkahCity.getTimeMan().getCurrentTime();
} }
public void setCurrentLocation(double currentLocation) { public void setCurrentLocation(double currentLocation) {
@ -131,6 +137,7 @@ public abstract class Vehicle {
} }
public void moveToNextStreet() { public void moveToNextStreet() {
this.routeTimeHistory.put(this.currentStreet, MakkahCity.getTimeMan().getCurrentTime().getTime() - timeStartedOnCurrentStreet.getTime());
int nxtIndex = route.indexOf(this.getCurrentStreet()) + 1; int nxtIndex = route.indexOf(this.getCurrentStreet()) + 1;
if (nxtIndex <= route.getStreets().length - 1) { if (nxtIndex <= route.getStreets().length - 1) {
if (this.getRoute().getStreets()[nxtIndex].capcityPoint(0, 1000) < 1) { if (this.getRoute().getStreets()[nxtIndex].capcityPoint(0, 1000) < 1) {