for (int i = 0; i < spot.getNumberOfVehicles(); i++) {
// Get the vehicle's type based on the user selection
VehicleType vehicleType = spot.getVehicleSelection().getRandomType();
// Get a random edge in the hotspot
Edge randomHotspotEdge = hotspotEdges.get(r.nextInt(totalHotspotEdges));
// Get a random edge in the network
Edge randomNetworkEdge = allEdges.get(r.nextInt(totalNetworkEdges));
// If the hotspot is incoming (vehicles from anywhere to the
// hotspot)
if (spot.isDirectionIn()) {
int timeOfDepartureFromSource = 0;
// If the time is specified as the time of departure from the
// source
if (spot.getDirectionInType() == HotSpot.DirectionInTimeType.TimeOfDepartureFromSource) {
// Get a random time between the incoming begin time and end
// time
timeOfDepartureFromSource = spot.getDirectionInBeginTime() + r.nextInt(spot.getDirectionInEndTime() + 1 - spot.getDirectionInBeginTime());
}
// If the time is specified as the time of arrival to the
// hotspot
else if (spot.getDirectionInType() == HotSpot.DirectionInTimeType.TimeOfArrivalToDestination) {
// Try to estimate the distance that the vehicle will need
// to travel
float distanceToTravel = randomHotspotEdge.DistanceFrom(randomNetworkEdge);
// Estimate the time needed to cover this distance
int estimatedTravelTime = (int) Math.round(distanceToTravel / Constants.averageSpeed);
// Get a random time between the incoming begin time and end
// time minus the time needed to travel
timeOfDepartureFromSource = spot.getDirectionInBeginTime() + r.nextInt(spot.getDirectionInEndTime() + 1 - spot.getDirectionInBeginTime()) - estimatedTravelTime;
// A vehicle can't start with a negative departure time
timeOfDepartureFromSource = Math.min(timeOfDepartureFromSource, 0);
}
// Add the incoming vehicle trip to the output
trips.add(new Trip(timeOfDepartureFromSource, "<trip id=\"" + spot.getName() + "-In-" + String.valueOf(i) + "\" depart=\"" + String.valueOf(timeOfDepartureFromSource) + "\" from=\"" + randomNetworkEdge.getId() + "\" to=\"" + randomHotspotEdge.getId() + "\" color=\"" + color + "\" type=\"" + vehicleType.getName() + "\" />\n"));
}
// If the hotspot is outgoing (vehicles from the hotspot to
// anywhere)
if (spot.isDirectionOut()) {
// Get a random time between the outgoing begin time and end
// time
int timeToLeaveSpot = spot.getDirectionOutBeginTime() + r.nextInt(spot.getDirectionOutEndTime() + 1 - spot.getDirectionOutBeginTime());
// Add the outgoing vehicle trip to the output
trips.add(new Trip(timeToLeaveSpot, "<trip id=\"" + spot.getName() + "-Out-" + String.valueOf(i) + "\" depart=\"" + String.valueOf(timeToLeaveSpot) + "\" from=\"" + randomHotspotEdge.getId() + "\" to=\"" + randomNetworkEdge.getId() + "\" color=\"" + color + "\" type=\"" + vehicleType.getName() + "\" />\n"));
}
}
return trips;