Major update
Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
cc64faf912
commit
62c8fb22fa
@ -4,6 +4,7 @@ public class Bus extends CivilVehicle {
|
|||||||
private String UID;
|
private String UID;
|
||||||
private static int numeberOfBuses;
|
private static int numeberOfBuses;
|
||||||
private final int TIME_TO_FIX = 20; //in minutes
|
private final int TIME_TO_FIX = 20; //in minutes
|
||||||
|
public final int MAX_FORWARD = 900; //Meter/Min
|
||||||
|
|
||||||
public static final double STD_BUS_SIZE = 10;
|
public static final double STD_BUS_SIZE = 10;
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ public class MakkahCity {
|
|||||||
private static final Street[] stdStreet = new Street[8];
|
private static final Street[] stdStreet = new Street[8];
|
||||||
|
|
||||||
private static final PDate timeManager = new PDate(
|
private static final PDate timeManager = new PDate(
|
||||||
new GregorianCalendar(2020, Calendar.JANUARY, 1, 8, 0, 0),
|
new GregorianCalendar(2020, Calendar.JANUARY, 1, 4, 0, 0),
|
||||||
new GregorianCalendar(2020, Calendar.JANUARY, 2, 8, 0, 0)
|
new GregorianCalendar(2020, Calendar.JANUARY, 1, 20, 0, 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -31,7 +31,7 @@ public class MakkahCity {
|
|||||||
//Set Routes for Campaigns
|
//Set Routes for Campaigns
|
||||||
setRoutesForCampaigns();
|
setRoutesForCampaigns();
|
||||||
|
|
||||||
//TODO: [1]Set Schedule for Campaigns
|
|
||||||
|
|
||||||
while(!timeManager.isEnded()) {
|
while(!timeManager.isEnded()) {
|
||||||
timeManager.step(Calendar.MINUTE, 1);
|
timeManager.step(Calendar.MINUTE, 1);
|
||||||
@ -44,6 +44,12 @@ public class MakkahCity {
|
|||||||
|
|
||||||
//TODO: [5]Streets move forward.
|
//TODO: [5]Streets move forward.
|
||||||
|
|
||||||
|
for (Campaign campaign : listOfCampaigns){
|
||||||
|
for (Vehicle vehicle : campaign.getVehicles()){
|
||||||
|
vehicle.moveForward(((Bus)vehicle).MAX_FORWARD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: [6]update vehicles on street.
|
//TODO: [6]update vehicles on street.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,14 +85,14 @@ public class MakkahCity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void makeStreets(){
|
private static void makeStreets(){
|
||||||
stdStreet[StreetNames.KA_STREET.ordinal()] = new Street(22700,3);
|
stdStreet[StreetNames.KA_STREET.ordinal()] = new Street(22700,3, StreetNames.KA_STREET);
|
||||||
stdStreet[StreetNames.FOURTH_HIGHWAY.ordinal()] = new Street(24600,4);
|
stdStreet[StreetNames.FOURTH_HIGHWAY.ordinal()] = new Street(24600,4, StreetNames.FOURTH_HIGHWAY);
|
||||||
stdStreet[StreetNames.KUDAY.ordinal()] = new Street(22000,3);
|
stdStreet[StreetNames.KUDAY.ordinal()] = new Street(22000,3, StreetNames.KUDAY);
|
||||||
stdStreet[StreetNames.STREET1.ordinal()] = new Street(4000,2);
|
stdStreet[StreetNames.STREET1.ordinal()] = new Street(4000,2, StreetNames.STREET1);
|
||||||
stdStreet[StreetNames.STREET2.ordinal()] = new Street(7000,2);
|
stdStreet[StreetNames.STREET2.ordinal()] = new Street(7000,2,StreetNames.STREET2);
|
||||||
stdStreet[StreetNames.STREET3.ordinal()] = new Street(400,2);
|
stdStreet[StreetNames.STREET3.ordinal()] = new Street(400,2, StreetNames.STREET3);
|
||||||
stdStreet[StreetNames.STREET4.ordinal()] = new Street(8200,2);
|
stdStreet[StreetNames.STREET4.ordinal()] = new Street(8200,2,StreetNames.STREET4);
|
||||||
stdStreet[StreetNames.IBRAHIM_ALKHALIL.ordinal()] = new Street(100,2); //TODO: [7]Change numbers
|
stdStreet[StreetNames.IBRAHIM_ALKHALIL.ordinal()] = new Street(100,2, StreetNames.IBRAHIM_ALKHALIL); //TODO: [7]Change numbers
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void makeRoutes() {
|
private static void makeRoutes() {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
public class SUV extends CivilVehicle {
|
public class SUV extends CivilVehicle {
|
||||||
|
|
||||||
private final int TIME_TO_FIX = 15; //in minutes
|
private final int TIME_TO_FIX = 15; //in minutes
|
||||||
|
public final int MAX_FORWARD = 1300;
|
||||||
|
|
||||||
public SUV(double vehicleSize){
|
public SUV(double vehicleSize){
|
||||||
super(vehicleSize);
|
super(vehicleSize);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
public class Sedan extends CivilVehicle {
|
public class Sedan extends CivilVehicle {
|
||||||
|
|
||||||
private final int TIME_TO_FIX = 15; //in minutes
|
private final int TIME_TO_FIX = 15; //in minutes
|
||||||
|
public final int MAX_FORWARD = 1500; // Meter/Min
|
||||||
|
|
||||||
public Sedan(double vehicleSize){
|
public Sedan(double vehicleSize){
|
||||||
super(vehicleSize);
|
super(vehicleSize);
|
||||||
|
@ -5,12 +5,14 @@ public class Street {
|
|||||||
private double length;
|
private double length;
|
||||||
private int numberOfLanes;
|
private int numberOfLanes;
|
||||||
private ArrayList<Vehicle> vehicles;
|
private ArrayList<Vehicle> vehicles;
|
||||||
|
private StreetNames name;
|
||||||
|
|
||||||
|
|
||||||
public Street(double length, int numberOfLanes) {
|
public Street(double length, int numberOfLanes, StreetNames name) {
|
||||||
vehicles = new ArrayList<>();
|
vehicles = new ArrayList<>();
|
||||||
setLength(length);
|
setLength(length);
|
||||||
setNumberOfLanes(numberOfLanes);
|
setNumberOfLanes(numberOfLanes);
|
||||||
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLength(double length) {
|
private void setLength(double length) {
|
||||||
@ -44,6 +46,10 @@ public class Street {
|
|||||||
return vehicles;
|
return vehicles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StreetNames getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public double capcity() {
|
public double capcity() {
|
||||||
double totalLength = length * numberOfLanes;
|
double totalLength = length * numberOfLanes;
|
||||||
double totalLenthofCar=0;
|
double totalLenthofCar=0;
|
||||||
@ -70,5 +76,4 @@ public class Street {
|
|||||||
vehicles.add(vehicle);
|
vehicles.add(vehicle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ public abstract class Vehicle {
|
|||||||
public void setRoute(Route route) {
|
public void setRoute(Route route) {
|
||||||
this.route = route;
|
this.route = route;
|
||||||
this.currentStreetIndex = 0;
|
this.currentStreetIndex = 0;
|
||||||
|
this.currentStreet = route.getStreets()[0];
|
||||||
this.route.getStreets()[0].addVehicle(this);//TODO: [9]street might not add if capacity is low
|
this.route.getStreets()[0].addVehicle(this);//TODO: [9]street might not add if capacity is low
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,12 +43,22 @@ public abstract class Vehicle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void moveForward(double distance) {
|
public void moveForward(double distance) {
|
||||||
if (moving && !arrivedToDest){
|
if (!moving && !arrivedToDest) moving = true;
|
||||||
|
if (!arrivedToDest){
|
||||||
if (isAtEndOfCurrentStreet()) {
|
if (isAtEndOfCurrentStreet()) {
|
||||||
moveToNextStreet();
|
moveToNextStreet();
|
||||||
//this.currentLocation += distance;
|
//this.currentLocation += distance;
|
||||||
}
|
}
|
||||||
else this.currentLocation += distance;
|
else {
|
||||||
|
double dToNext = getDistanceToNextVehicle();
|
||||||
|
double trafficFactor = getCurrentStreet().getPercentRemainingCapacity() / 100.0;
|
||||||
|
if (dToNext == -1 ) {
|
||||||
|
this.currentLocation += distance * trafficFactor;
|
||||||
|
} else if (dToNext < distance){//TODO after I wake up
|
||||||
|
this.currentLocation += distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +71,7 @@ public abstract class Vehicle {
|
|||||||
this.currentStreetIndex++;
|
this.currentStreetIndex++;
|
||||||
Street nextStreet;
|
Street nextStreet;
|
||||||
try { nextStreet = this.getRoute().getStreets()[currentStreetIndex]; }
|
try { nextStreet = this.getRoute().getStreets()[currentStreetIndex]; }
|
||||||
catch (IndexOutOfBoundsException e) { this.arrivedToDest = true; return;}
|
catch (IndexOutOfBoundsException e) { this.arrivedToDest = true; this.moving = false; return;}
|
||||||
if (nextStreet.canTakeVehicles(this)){
|
if (nextStreet.canTakeVehicles(this)){
|
||||||
this.currentStreet = nextStreet;
|
this.currentStreet = nextStreet;
|
||||||
this.currentLocation = 0;
|
this.currentLocation = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user