96 lines
4.1 KiB
Java
96 lines
4.1 KiB
Java
import java.util.Vector;
|
|
|
|
public class Route {
|
|
private double[] currentLocation; //Lat-Long coordinates for current location
|
|
private Vector<Vector<String[]>> routeSequences; //3D array for routes. 1st dim selects route, 2nd dim selects route point, 3rd dim selects lat/long/speed/tolls (indices 0-2)
|
|
private int routeSelected;
|
|
private boolean tollsFlag; //stores user setting for whether to avoid tolls
|
|
private boolean hwyFlag; //stores user preference for whether to avoid major highways
|
|
public Vector<Double> timeEstimate; //time estimate in seconds
|
|
public Vector<Double> tollsAmount; //stores toll amount if toll roads are used
|
|
private Destination currentDestination = new Destination();
|
|
|
|
public Route() {
|
|
this.routeSequences = new Vector<Vector<String[]>>();
|
|
this.timeEstimate = new Vector<Double>();
|
|
this.tollsAmount = new Vector<Double>();
|
|
}
|
|
|
|
public Route(String destination) {
|
|
setRouteDestination(destination);
|
|
this.timeEstimate = new Vector<Double>();
|
|
this.tollsAmount = new Vector<Double>();
|
|
tollsFlag = false;
|
|
hwyFlag = false;
|
|
}
|
|
|
|
private void updateCurrentLocation() {
|
|
//execute api call out to GPS service to obtain current location
|
|
//current location will be hardcoded for testing
|
|
double[] tmpLoc = {28.1700863880887, -80.67088403224037};
|
|
currentLocation = tmpLoc;
|
|
}
|
|
|
|
private void calculateRoutes() {
|
|
//execute api call out to routing service to get route info
|
|
//ideally a query would go out using multiple pathfiding algorithms to get route options
|
|
//here the same call is made for demo purposes
|
|
this.routeSequences = new Vector<Vector<String[]>>();
|
|
updateCurrentLocation();
|
|
HelperFunctions apiCallToRouting = new HelperFunctions();
|
|
//route option 1
|
|
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationAddress(), tollsFlag, hwyFlag));
|
|
timeEstimate.add(estimateTime(routeSequences.get(0)));
|
|
tollsAmount.add(estimateTolls(routeSequences.get(0)));
|
|
//route option 2
|
|
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationAddress(), tollsFlag, hwyFlag));
|
|
timeEstimate.add(estimateTime(routeSequences.get(1)));
|
|
tollsAmount.add(estimateTolls(routeSequences.get(1)));
|
|
//route option 3
|
|
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationAddress(), tollsFlag, hwyFlag));
|
|
timeEstimate.add(estimateTime(routeSequences.get(2)));
|
|
tollsAmount.add(estimateTolls(routeSequences.get(2)));
|
|
}
|
|
|
|
public int enumRoutes() {
|
|
return routeSequences.size();
|
|
}
|
|
|
|
public void selectRoute(int userSelection) {
|
|
routeSelected = userSelection;
|
|
}
|
|
|
|
public Vector<String[]> getSelectedRouteSteps() {
|
|
return routeSequences.get(routeSelected);
|
|
}
|
|
|
|
public double estimateTolls(Vector<String[]> route) {
|
|
double runningTolls = 0;
|
|
for (String[] el : route) {
|
|
runningTolls += Double.parseDouble(el[3]);
|
|
}
|
|
return runningTolls;
|
|
}
|
|
|
|
public double estimateTime(Vector<String[]> route) {
|
|
//calculates distances between route segments, divided by speed in MPH
|
|
//the API would return expected speed due to traffic conditions as part of the speed (index 2) in the route array
|
|
double runningTime = 0;
|
|
//steps through to get distances, calculates time based on speed estimate, and accumulates on runningTime
|
|
for (String[] el : route) {
|
|
runningTime += Double.parseDouble(el[1])/Double.parseDouble(el[2]);
|
|
}
|
|
return runningTime;
|
|
}
|
|
|
|
public void setRouteDestination(String destination) {
|
|
currentDestination.setDestinationAddress(destination);
|
|
calculateRoutes();
|
|
}
|
|
|
|
public void setHwyFlag(boolean flag) {hwyFlag = flag;}
|
|
public void setTollsFlag(boolean flag) {tollsFlag = flag;}
|
|
public boolean getHwyFlag() {return hwyFlag;}
|
|
public boolean getTollsFlag() {return tollsFlag;}
|
|
public int getRouteSelected() {return routeSelected;}
|
|
}
|