Java Code Examples for org.matsim.vehicles.Vehicle

The following examples show how to use org.matsim.vehicles.Vehicle. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void handleEvent(PersonDepartureEvent event) {
    if (AmodeusIdentifiers.isValid(event.getPersonId())) {
        String mode = AmodeusIdentifiers.getMode(event.getPersonId());
        Id<Vehicle> vehicleId = Id.createVehicleId(event.getPersonId());

        VehicleMovementItem movement = new VehicleMovementItem();
        movements.add(movement);

        movement.mode = mode;
        movement.vehicleId = vehicleId;

        movement.originLink = linkFinder.getLink(event.getLinkId());
        movement.departureTime = event.getTime();

        currentMovements.put(vehicleId, movement);
    }
}
 
Example 2
@Override
public void handleEvent(PersonArrivalEvent event) {
    if (AmodeusIdentifiers.isValid(event.getPersonId())) {
        Id<Vehicle> vehicleId = Id.createVehicleId(event.getPersonId());

        VehicleMovementItem movement = currentMovements.remove(vehicleId);

        if (movement == null) {
            throw new IllegalStateException("Found arrival without departure");
        }

        movement.destinationLink = linkFinder.getLink(event.getLinkId());
        movement.arrivalTime = event.getTime();

        movement.numberOfPassengers = passengers.getNumberOfPassengers(vehicleId);
    }
}
 
Example 3
@Override
public void handleEvent(ActivityStartEvent event) {
    if (AmodeusIdentifiers.isValid(event.getPersonId())) {
        String mode = AmodeusIdentifiers.getMode(event.getPersonId());
        Id<Vehicle> vehicleId = Id.createVehicleId(event.getPersonId());

        VehicleActivityItem activity = new VehicleActivityItem();
        activities.add(activity);

        activity.mode = mode;
        activity.vehicleId = vehicleId;

        activity.link = linkFinder.getLink(event.getLinkId());
        activity.type = event.getActType();

        activity.startTime = event.getTime();

        currentActivities.put(vehicleId, activity);
    }
}
 
Example 4
@Override
public void handleEvent(ActivityEndEvent event) {
    if (AmodeusIdentifiers.isValid(event.getPersonId())) {
        String mode = AmodeusIdentifiers.getMode(event.getPersonId());
        Id<Vehicle> vehicleId = Id.createVehicleId(event.getPersonId());

        VehicleActivityItem activity = currentActivities.remove(vehicleId);
        boolean isStarted = activity != null;

        if (!isStarted) {
            activity = new VehicleActivityItem();
            activities.add(activity);
        }

        activity.mode = mode;
        activity.vehicleId = vehicleId;

        activity.link = linkFinder.getLink(event.getLinkId());
        activity.type = event.getActType();

        activity.endTime = event.getTime();
    }
}
 
Example 5
Source Project: pt2matsim   Source File: FPLANRoute.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
	 * @return A list of all departures of this route.
	 * If firstDepartureTime or usedVehicle are not set before this is called, null is returned.
	 * If vehicleType is not set, the vehicle is not in the list and entry will not be created.
	 */
	public List<Departure> getDepartures() {
		if(firstDepartureTime < 0 || getVehicleId() == null) {
			log.error("getDepartures before first departureTime and usedVehicleId set.");
			return null;
		}
		if(vehicleTypeId == null) {
			//log.warn("VehicleType not defined in vehicles list.");
			return null;
		}

		List<Departure> departures = new ArrayList<>();
		for(int i = 0; i < numberOfDepartures; i++) {
			// Departure ID
//			Id<Departure> departureId = Id.create(routeDescription + "_" + String.format("%04d", i + 1), Departure.class);
			Id<Departure> departureId = Id.create(String.format("%05d", depId++), Departure.class);
			// Departure time
			double departureTime = firstDepartureTime + (i * cycleTime) - initialDelay;
			// Departure vehicle
//			Id<Vehicle> vehicleId = Id.create(getVehicleId() + "_" + String.format("%04d", i + 1), Vehicle.class);
			Id<Vehicle> vehicleId = Id.create(getVehicleId() + "_" + departureId, Vehicle.class);
			// create and add departure
			departures.add(createDeparture(departureId, departureTime, vehicleId));
		}
		return departures;
	}
 
Example 6
Source Project: pt2matsim   Source File: ScheduleCleaner.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Removes vehicles that are not used in the schedule
 */
public static void cleanVehicles(TransitSchedule schedule, Vehicles vehicles) {
	log.info("Removing not used vehicles...");
	int removed = 0;
	final Set<Id<Vehicle>> usedVehicles = new HashSet<>();
	for(TransitLine transitLine : schedule.getTransitLines().values()) {
		for(TransitRoute transitRoute : transitLine.getRoutes().values()) {
			for(Departure departure : transitRoute.getDepartures().values()) {
				usedVehicles.add(departure.getVehicleId());
			}
		}
	}
	for(Id<Vehicle> vehicleId : new HashSet<>(vehicles.getVehicles().keySet())) {
		if(!usedVehicles.contains(vehicleId)) {
			vehicles.removeVehicle(vehicleId);
			removed++;
		}
	}
	log.info(removed + " vehicles removed");
}
 
Example 7
Source Project: amodeus   Source File: LSDataTravelTime.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
    double speed = link.getFreespeed();
    LinkSpeedTimeSeries timeSeries = lsData.get(link);
    if (Objects.nonNull(timeSeries))
        speed = timeSeries.getSpeedsFloor((int) time);
    return link.getLength() / speed;
}
 
Example 8
@Override
public Future<Path> calcLeastCostPath(Node fromNode, Node toNode, double starttime, Person person, Vehicle vehicle) {
    Future<Path> future = executor.submit(() -> {
        LeastCostPathCalculator calculator = calculators.take();
        Path path = calculator.calcLeastCostPath(fromNode, toNode, starttime, person, vehicle);
        calculators.put(calculator);
        return path;
    });

    // futures.add(future);
    return future;
}
 
Example 9
Source Project: amodeus   Source File: PassengerTracker.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void addPassenger(Id<Vehicle> vehicleId, Id<Person> passengerId) {
    ensurePassengers(vehicleId);

    if (!passengers.get(vehicleId).add(passengerId)) {
        throw new IllegalStateException(String.format("Passenger '%s' is already in vehicle '%s'", passengerId, vehicleId));
    }
}
 
Example 10
Source Project: amodeus   Source File: PassengerTracker.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void removePassenger(Id<Vehicle> vehicleId, Id<Person> passengerId) {
    ensurePassengers(vehicleId);

    if (!passengers.get(vehicleId).remove(passengerId)) {
        throw new IllegalStateException(String.format("Passenger '%s' is not in vehicle '%s'", passengerId, vehicleId));
    }
}
 
Example 11
Source Project: amodeus   Source File: DefaultAStarLMRouter.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Future<Path> calcLeastCostPath(Node fromNode, Node toNode, double starttime, //
        Person person, Vehicle vehicle) {
    return delegate.calcLeastCostPath(fromNode, toNode, starttime, person, vehicle);
}
 
Example 12
Source Project: amodeus   Source File: TaxiTravelTimeRouter.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Future<Path> calcLeastCostPath(Node fromNode, Node toNode, double starttime, Person person, Vehicle vehicle) {
    return delegate.calcLeastCostPath(fromNode, toNode, starttime, person, vehicle);
}
 
Example 13
@Override
public Future<Path> calcLeastCostPath(Node fromNode, Node toNode, double starttime, Person person, Vehicle vehicle) {
    return ConcurrentUtils.constantFuture(delegate.calcLeastCostPath(fromNode, toNode, starttime, person, vehicle));
}
 
Example 14
Source Project: amodeus   Source File: PassengerTracker.java    License: GNU General Public License v2.0 4 votes vote down vote up
private void ensurePassengers(Id<Vehicle> vehicleId) {
    if (!passengers.containsKey(vehicleId)) {
        passengers.put(vehicleId, new HashSet<>());
    }
}
 
Example 15
Source Project: amodeus   Source File: PassengerTracker.java    License: GNU General Public License v2.0 4 votes vote down vote up
public boolean hasPassenger(Id<Vehicle> vehicleId, Id<Person> passengerId) {
    ensurePassengers(vehicleId);
    return passengers.get(vehicleId).contains(passengerId);
}
 
Example 16
Source Project: amodeus   Source File: PassengerTracker.java    License: GNU General Public License v2.0 4 votes vote down vote up
public int getNumberOfPassengers(Id<Vehicle> vehicleId) {
    ensurePassengers(vehicleId);
    return passengers.get(vehicleId).size();
}
 
Example 17
Source Project: amodeus   Source File: PassengerTracker.java    License: GNU General Public License v2.0 4 votes vote down vote up
public Collection<Id<Person>> getPassengerIds(Id<Vehicle> vehicleId) {
    ensurePassengers(vehicleId);
    return passengers.get(vehicleId);
}
 
Example 18
Source Project: amodeus   Source File: DefaultAmodeusRouter.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Future<Path> calcLeastCostPath(Node fromNode, Node toNode, double starttime, Person person, Vehicle vehicle) {
    return delegate.calcLeastCostPath(fromNode, toNode, starttime, person, vehicle);
}
 
Example 19
Source Project: amod   Source File: CustomRouter.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Future<Path> calcLeastCostPath(Node fromNode, Node toNode, double starttime, Person person, Vehicle vehicle) {
    /** here a path neets to be computed and returned accordign to your custom logic */
    throw new RuntimeException("This CustomRouter is not functional.");
}
 
Example 20
Source Project: pt2matsim   Source File: LinkSequence.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Id<Vehicle> getVehicleId() {
	return null;
}
 
Example 21
@Override
public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) {
	return this.calcLinkTravelCost(link);
}
 
Example 22
@Override
public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
	return link.getLength() / link.getFreespeed();
}
 
Example 23
@Override
public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) {
	return this.getLinkMinimumTravelDisutility(link);
}
 
Example 24
@Override
public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
	return link.getLength() / link.getFreespeed();
}
 
Example 25
@Override
public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) {
    return calcLinkTravelCost(link);
}
 
Example 26
@Override
public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
    return link.getLength() / link.getFreespeed();
}
 
Example 27
Source Project: pt2matsim   Source File: FPLANRoute.java    License: GNU General Public License v2.0 4 votes vote down vote up
private Departure createDeparture(Id<Departure> departureId, double departureTime, Id<Vehicle> vehicleId) {
	Departure departure = scheduleFactory.createDeparture(departureId, departureTime);
	departure.setVehicleId(vehicleId);
	return departure;
}
 
Example 28
Source Project: pt2matsim   Source File: LinkSequence.java    License: GNU General Public License v2.0 2 votes vote down vote up
@Override
public void setVehicleId(Id<Vehicle> id) {

}
 
Example 29
Future<LeastCostPathCalculator.Path> calcLeastCostPath(Node fromNode, Node toNode, double starttime, final Person person, final Vehicle vehicle);