CEN-3024-Code-Implementation/Route.java

67 lines
3.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<Float> tollsAmount; //stores toll amount if toll roads are used
public Destination currentDestination; //uses user-created class Destination
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
updateCurrentLocation();
HelperFunctions apiCallToRouting = new HelperFunctions();
//route option 1
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag));
timeEstimate[0] = estimateTime(routeSequences.get(0));
estimateTolls(routeSequences.get(0));
//route option 2
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag));
timeEstimate[1] = estimateTime(routeSequences.get(1));
estimateTolls(routeSequences.get(1));
//route option 3
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag));
timeEstimate[2] = estimateTime(routeSequences.get(2));
estimateTolls(routeSequences.get(2));
}
public int enumRoutes() {
return routeSequences.length;
}
public void selectRoute(int userSelection) {
routeSelected = userSelection;
}
public int getRouteSelected() {return routeSelected;}
public float estimateTolls(double[][] route) {
float runningTolls = 0;
for (int i = 0; i <= route.length; i++) {
runningTolls += route[i][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 subsequence route points 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;
}
}