org.matsim.vehicles.Vehicle Java Examples

The following examples show how to use org.matsim.vehicles.Vehicle. 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
Source File: ScheduleCleaner.java    From pt2matsim with 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 #2
Source File: FPLANRoute.java    From pt2matsim with 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 #3
Source File: VehicleAnalysisListener.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
@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 #4
Source File: VehicleAnalysisListener.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
@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 #5
Source File: VehicleAnalysisListener.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
@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 #6
Source File: VehicleAnalysisListener.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
@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 #7
Source File: LSDataTravelTime.java    From amodeus with 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
Source File: PassengerTracker.java    From amodeus with 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 #9
Source File: PassengerTracker.java    From amodeus with 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 File: DefaultParallelLeastCostPathCalculator.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
@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 #11
Source File: LinkSequence.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Id<Vehicle> getVehicleId() {
	return null;
}
 
Example #12
Source File: DefaultAStarLMRouter.java    From amodeus with 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
Source File: FPLANRoute.java    From pt2matsim with 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 #14
Source File: TaxiTravelTimeRouter.java    From amodeus with 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 #15
Source File: ScheduleRoutersOsmAttributes.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
@Override
public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
    return link.getLength() / link.getFreespeed();
}
 
Example #16
Source File: ScheduleRoutersOsmAttributes.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
@Override
public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) {
    return calcLinkTravelCost(link);
}
 
Example #17
Source File: ScheduleRoutersStandard.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
@Override
public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
	return link.getLength() / link.getFreespeed();
}
 
Example #18
Source File: ScheduleRoutersStandard.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
@Override
public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) {
	return this.getLinkMinimumTravelDisutility(link);
}
 
Example #19
Source File: ScheduleRoutersGtfsShapes.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
@Override
public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
	return link.getLength() / link.getFreespeed();
}
 
Example #20
Source File: ScheduleRoutersGtfsShapes.java    From pt2matsim with GNU General Public License v2.0 4 votes vote down vote up
@Override
public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) {
	return this.calcLinkTravelCost(link);
}
 
Example #21
Source File: CustomRouter.java    From amod with 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 #22
Source File: DefaultAmodeusRouter.java    From amodeus with 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 #23
Source File: PassengerTracker.java    From amodeus with 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 #24
Source File: PassengerTracker.java    From amodeus with 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 #25
Source File: SerialLeastCostPathCalculator.java    From amodeus with 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 ConcurrentUtils.constantFuture(delegate.calcLeastCostPath(fromNode, toNode, starttime, person, vehicle));
}
 
Example #26
Source File: PassengerTracker.java    From amodeus with 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 #27
Source File: PassengerTracker.java    From amodeus with 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 #28
Source File: LinkSequence.java    From pt2matsim with GNU General Public License v2.0 2 votes vote down vote up
@Override
public void setVehicleId(Id<Vehicle> id) {

}
 
Example #29
Source File: ParallelLeastCostPathCalculator.java    From amodeus with GNU General Public License v2.0 votes vote down vote up
Future<LeastCostPathCalculator.Path> calcLeastCostPath(Node fromNode, Node toNode, double starttime, final Person person, final Vehicle vehicle);