Package roadnetwork

Examples of roadnetwork.Edge


    for (int i = 0; i < totalVehiclesToEmit; i++) {
      // Get the vehicle's type based on the user selection
      VehicleType vehicleType = layer.getVehicleSelection().getRandomType();

      // Get a random edge in the network
      Edge randomNetworkEdge1 = allEdges.get(r.nextInt(totalNetworkEdges));

      // Get a random edge in the network
      Edge randomNetworkEdge2 = allEdges.get(r.nextInt(totalNetworkEdges));

      // Get a random time between the emission starting and ending time
      int timeToLeave = layer.getStartingTime() + r.nextInt(layer.getEndingTime() + 1 - layer.getStartingTime());

      // Add the incoming vehicle trip to the output
      tripsList.add(new Trip(timeToLeave,"<trip id=\"" + layer.getName() + "-In-" + String.valueOf(i) + "\" depart=\"" + String.valueOf(timeToLeave) + "\" from=\"" + randomNetworkEdge1.getId() + "\" to=\"" + randomNetworkEdge2.getId() + "\" color=\"" + color + "\" type=\"" + vehicleType.getName() + "\" />\n"));
    }
  }
View Full Code Here


    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;
View Full Code Here

        // Create a route for a vehicle starting at the edge that the
        // accident happens and ending at an edge connected to the lane
        String route = accident.getEdge().getId();

        if (affectedLane.getFirst().getConnectedEdges().size() > 0) {
          Edge connectedEdge = roadNetwork.findEdge(affectedLane.getFirst().getConnectedEdges().get(0));

          if (connectedEdge != null) {
            route += " " + connectedEdge.getId();
          }
        }

        routes.add(new Route(accident.getStartingTime(), "<vehicle id=\"Accident-" + accident.getName() + "-" + affectedLane.getFirst().getId() + "\" type=\"Default\" depart=\"" + String.valueOf(accident.getStartingTime()) + "\" color=\"1,0,0\">\n" + "     <route color=\"1,0,0\">" + route + "</route>\n" + "     <stop lane=\"" + affectedLane.getFirst().getId() + "\" pos=\"" + accident.getEdgeRelativeLocation() + "\" duration=\"" + String.valueOf(accident.getEndingTime() - accident.getStartingTime()) + "\"/>\n" + "</vehicle>\n"));
      }
View Full Code Here

    }

    // For each vehicle
    for (int i = 0; i < areaFlow.getNumberOfVehicles(); i++) {
      // Get a random source and destination edge
      Edge randomFromEdge = fromAreaEdges.get(r.nextInt(totalFromAreaEdges));
      Edge randomToEdge = toAreaEdges.get(r.nextInt(totalToAreaEdges));

      // Get a random time between the begin time and end time
      int departureTime = areaFlow.getBeginTime() + r.nextInt(areaFlow.getEndTime() + 1 - areaFlow.getBeginTime());

      String color = new Float(areaFlow.getColor().getRed() / 255f).toString() + "," + new Float(areaFlow.getColor().getGreen() / 255f).toString() + "," + new Float(areaFlow.getColor().getBlue() / 255f).toString();

      // Create the trip
      trips.add(new Trip(departureTime, "<trip id=\"" + areaFlow.getName() + "-" + String.valueOf(i) + "\" depart=\"" + String.valueOf(departureTime) + "\" from=\"" + randomFromEdge.getId() + "\" to=\"" + randomToEdge.getId() + "\" color=\"" + color + "\" type=\"" + areaFlow.getVehicleSelection().getRandomType().getName() + "\" />\n"));
    }

    return trips;
  }
View Full Code Here

TOP

Related Classes of roadnetwork.Edge

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.