Commit 7b8d75e8 authored by Sebastian Hörl's avatar Sebastian Hörl
Browse files

Add PCU for private av (not tested yet)

parent 35334d70
......@@ -57,6 +57,12 @@
</build>
<dependencies>
<dependency>
<groupId>ch.ethz.matsim</groupId>
<artifactId>av</artifactId>
<version>0.2.6</version>
</dependency>
<dependency>
<groupId>ch.ethz.matsim</groupId>
<artifactId>baseline_scenario</artifactId>
......
......@@ -3,6 +3,7 @@ package ch.ethz.matsim.projects.astra_2018_002;
import org.matsim.api.core.v01.Scenario;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.QSimConfigGroup.VehiclesSource;
import org.matsim.core.config.groups.StrategyConfigGroup.StrategySettings;
import org.matsim.core.controler.Controler;
import org.matsim.core.scenario.ScenarioUtils;
......@@ -13,6 +14,7 @@ import ch.ethz.matsim.baseline_scenario.transit.BaselineTransitModule;
import ch.ethz.matsim.baseline_scenario.transit.routing.DefaultEnrichedTransitRoute;
import ch.ethz.matsim.baseline_scenario.transit.routing.DefaultEnrichedTransitRouteFactory;
import ch.ethz.matsim.projects.astra_2018_002.mode_choice.ModeChoiceModule;
import ch.ethz.matsim.projects.astra_2018_002.pcu.PCUUtils;
import ch.sbb.matsim.routing.pt.raptor.SwissRailRaptorModule;
public class RunASTRA2018002 {
......@@ -42,6 +44,10 @@ public class RunASTRA2018002 {
strategy.setWeight(0.8);
config.strategy().addStrategySettings(strategy);
config.qsim().setVehiclesSource(VehiclesSource.modeVehicleTypesFromVehiclesData);
config.travelTimeCalculator().setAnalyzedModes("car,private_av");
// config.travelTimeCalculator().setSeparateModes(true);
cmd.applyConfiguration(config);
// Load scenario
......@@ -50,6 +56,9 @@ public class RunASTRA2018002 {
new DefaultEnrichedTransitRouteFactory());
ScenarioUtils.loadScenario(scenario);
// Set up scenario
PCUUtils.defineVehicleTypes(scenario);
// Set up controller
Controler controler = new Controler(scenario);
controler.addOverridingModule(new SwissRailRaptorModule());
......
package ch.ethz.matsim.projects.astra_2018_002.pcu;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.vehicles.EngineInformation;
import org.matsim.vehicles.VehicleCapacity;
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils;
public class AVVehicleType implements VehicleType {
private final VehicleType vehicleType = VehicleUtils.getDefaultVehicleType();
private final FlowEfficiencyCalculator flowEffciencyCalculator;
private final Id<VehicleType> id;
public AVVehicleType(FlowEfficiencyCalculator flowEffciencyCalculator, Id<VehicleType> id) {
this.flowEffciencyCalculator = flowEffciencyCalculator;
this.id = id;
}
public AVVehicleType(FlowEfficiencyCalculator flowEffciencyCalculator) {
this(flowEffciencyCalculator, null);
}
@Override
public Id<VehicleType> getId() {
if (id == null) {
return vehicleType.getId();
} else {
return id;
}
}
public void setDescription(String desc) {
vehicleType.setDescription(desc);
}
public void setLength(double length) {
vehicleType.setLength(length);
}
public void setWidth(double width) {
vehicleType.setWidth(width);
}
public void setMaximumVelocity(double meterPerSecond) {
vehicleType.setMaximumVelocity(meterPerSecond);
}
public void setEngineInformation(EngineInformation currentEngineInfo) {
vehicleType.setEngineInformation(currentEngineInfo);
}
public void setCapacity(VehicleCapacity capacity) {
vehicleType.setCapacity(capacity);
}
public double getWidth() {
return vehicleType.getWidth();
}
public double getMaximumVelocity() {
return vehicleType.getMaximumVelocity();
}
public double getLength() {
return vehicleType.getLength();
}
public EngineInformation getEngineInformation() {
return vehicleType.getEngineInformation();
}
public String getDescription() {
return vehicleType.getDescription();
}
public VehicleCapacity getCapacity() {
return vehicleType.getCapacity();
}
public double getAccessTime() {
return vehicleType.getAccessTime();
}
public void setAccessTime(double seconds) {
vehicleType.setAccessTime(seconds);
}
public double getEgressTime() {
return vehicleType.getEgressTime();
}
public void setEgressTime(double seconds) {
vehicleType.setEgressTime(seconds);
}
public DoorOperationMode getDoorOperationMode() {
return vehicleType.getDoorOperationMode();
}
public void setDoorOperationMode(DoorOperationMode mode) {
vehicleType.setDoorOperationMode(mode);
}
public double getPcuEquivalents() {
return vehicleType.getPcuEquivalents();
}
public void setPcuEquivalents(double pcuEquivalents) {
vehicleType.setPcuEquivalents(pcuEquivalents);
}
public double getFlowEfficiencyFactor(Link link) {
return flowEffciencyCalculator.calculateFlowEfficiency(link);
}
public void setFlowEfficiencyFactor(double flowEfficiencyFactor) {
vehicleType.setFlowEfficiencyFactor(flowEfficiencyFactor);
}
}
package ch.ethz.matsim.projects.astra_2018_002.pcu;
import org.matsim.api.core.v01.network.Link;
public class FlowEfficiencyCalculator {
public double calculateFlowEfficiency(Link link) {
return 1.0;
}
}
package ch.ethz.matsim.projects.astra_2018_002.pcu;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils;
public class PCUUtils {
static public void defineVehicleTypes(Scenario scenario) {
VehicleType carVehicleType = VehicleUtils.getDefaultVehicleType();
scenario.getVehicles().addVehicleType(carVehicleType);
VehicleType avVehicleType = new AVVehicleType(new FlowEfficiencyCalculator(),
Id.create("private_av", VehicleType.class));
scenario.getVehicles().addVehicleType(avVehicleType);
}
}
/* *********************************************************************** *
* project: org.matsim.*
* SimVehicle.java
* *
* *********************************************************************** *
* *
* copyright : (C) 2009 by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* *
* *********************************************************************** *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
* *
* *********************************************************************** */
package org.matsim.core.mobsim.qsim.qnetsimengine;
import org.apache.log4j.Logger;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.core.gbl.Gbl;
import org.matsim.core.mobsim.framework.DriverAgent;
import org.matsim.core.mobsim.framework.MobsimDriverAgent;
import org.matsim.core.mobsim.framework.PassengerAgent;
import org.matsim.core.mobsim.qsim.interfaces.MobsimVehicle;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleCapacity;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
/**
* The ``Q'' implementation of the MobsimVehicle.
* <p></p>
* Design thoughts:<ul>
* <li> This needs to be public since the ``Q'' version of the
* vehicle is used by more than one package. This interfaces should, however, not be used outside the relevant
* netsimengines. In particular, the information should not be used for visualization. kai, nov'11
* <li> Might be possible to make all methods in this hierarchy protected and just inherit to a QueueVehicle. kai, nov'11
* </ul>
*
* @author nagel
*/
public class QVehicle extends QItem implements MobsimVehicle {
private static final Logger log = Logger.getLogger(QVehicle.class);
private static int warnCount = 0;
private double linkEnterTime = 0. ;
private double earliestLinkExitTime = 0;
private DriverAgent driver = null;
private Collection<PassengerAgent> passengers = null;
private final Id<Vehicle> id;
private Link currentLink = null;
private final Vehicle vehicle;
private final int passengerCapacity;
public QVehicle(final Vehicle basicVehicle) {
this.id = basicVehicle.getId();
this.vehicle = basicVehicle;
this.passengers = new ArrayList<>();
VehicleCapacity capacity = basicVehicle.getType().getCapacity();
if (capacity == null) {
this.passengerCapacity = 4;
if (warnCount < 10) {
log.warn("No VehicleCapacity (= maximum number of passengers) set in Vehicle. "
+ "Using default value of 4. This is only a problem if you need vehicles with different "
+ "capacities, e.g. for minibuses.");
warnCount++;
if ( warnCount == 10 ) {
log.warn( Gbl.FUTURE_SUPPRESSED ) ;
}
}
} else {
// do *not* subtract one for the driver! Most pt vehicles define the capacity without the driver.
// for private cars, think about if we should subtract one from the capacity if the driver is set?
// But if we do, change the number of seats of the default vehicle from 4 to 5.
this.passengerCapacity = capacity.getSeats() +
(capacity.getStandingRoom() == null ? 0 : capacity.getStandingRoom());
}
}
public void setCurrentLink(final Link link) {
this.currentLink = link;
}
// yy not sure if this needs to be publicly exposed
/**Design thoughts:<ul>
* <li> I am fairly sure that this should not be publicly exposed. As far as I can tell, it is used in order to
* figure out of a visualizer should make a vehicle "green" or "red". But green or red should be related to
* vehicle speed, and the mobsim should figure that out, not the visualizer. So something like "getCurrentSpeed"
* seems to be a more useful option. kai, nov'11
* <li> The problem is not only the speed, but also the positioning of the vehicle in the "asQueue" plotting method.
* (Although, when thinking about it: Should be possible to obtain same result by using "getEarliestLinkExitTime()".
* But I am not sure if that would really be a conceptual improvement ... linkEnterTime is, after all, a much more
* "physical" quantity.) kai, nov'11
* <li> But maybe it should then go into MobsimVehicle? kai, nov'11
* <li> Also see comment under setLinkEnterTime(). kai, nov'11
* <li>removed this while refactoring the visualizer computations, dg jan'12</li>
* </ul>
*/
// public double getLinkEnterTime() {
// return this.linkEnterTime;
// }
/**Design thoughts:<ul>
* <li> This has to remain public as long as QVehicle/QVehicleImpl is both used by QueueSimulation and QSim. At best,
* we could say that there should also be a MobsimVehicle interface that does not expose this. kai, nov'11.
* (This is there now. kai, nov'11)
* <li>removed this while refactoring the visualizer computations, dg jan'12</li>
* </ul>
*/
// public void setLinkEnterTime(final double time) {
// this.linkEnterTime = time;
// }
@Override
public double getEarliestLinkExitTime() {
return this.earliestLinkExitTime;
}
@Override
public void setEarliestLinkExitTime(final double time) {
this.earliestLinkExitTime = time;
}
@Override
public Link getCurrentLink() {
return this.currentLink;
}
@Override
public MobsimDriverAgent getDriver() {
if ( this.driver instanceof MobsimDriverAgent ) {
return (MobsimDriverAgent) this.driver;
} else if ( this.driver==null ) {
return null ;
} else {
throw new RuntimeException( "error (downstream methods need to be made to accept DriverAgent)") ;
}
}
public void setDriver(final DriverAgent driver) {
if (driver != null) {
if (this.driver != null && !this.driver.getId().equals(driver.getId())) {
throw new RuntimeException( "A driver (" + this.driver.getId() +") " +
"is already set in vehicle " + this.getId() + ". " +
"Setting agent " + driver.getId().toString() + " is not possible!");
}
}
// TODO: To make this check possible, we would need something like removeDriver().
// else {
// throw new RuntimeException( "Driver to be set in vehicle " + this.getId() +
// " is null!");
// }
this.driver = driver;
}
@Override
public Id<Vehicle> getId() {
return this.id;
}
@Override
public double getSizeInEquivalents() {
return vehicle.getType().getPcuEquivalents();
}
public double getFlowCapacityConsumptionInEquivalents(Link link) {
return vehicle.getType().getPcuEquivalents() / vehicle.getType().getFlowEfficiencyFactor(link);
}
@Override
public Vehicle getVehicle() {
return this.vehicle;
}
@Override
public String toString() {
return "Vehicle Id " + getId() + ", driven by (personId) " + this.driver.getId()
+ ", on link " + this.currentLink.getId();
}
public double getMaximumVelocity() {
return vehicle.getType().getMaximumVelocity();
}
@Override
public Collection<? extends PassengerAgent> getPassengers() {
return Collections.unmodifiableCollection(this.passengers);
}
@Override
public boolean addPassenger(PassengerAgent passenger) {
if (this.passengers.size() < this.passengerCapacity) {
return this.passengers.add(passenger);
}
return false;
}
@Override
public boolean removePassenger(PassengerAgent passenger) {
return this.passengers.remove(passenger);
}
@Override
public int getPassengerCapacity() {
return this.passengerCapacity;
}
final double getLinkEnterTime() {
return this.linkEnterTime;
}
final void setLinkEnterTime(double linkEnterTime) {
// yyyyyy use in code!
this.linkEnterTime = linkEnterTime;
}
}
package org.matsim.core.mobsim.qsim.qnetsimengine;
public class VehicleType {
}
/* *********************************************************************** *
* project: org.matsim.*
* *
* *********************************************************************** *
* *
* copyright : (C) 2008 by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* *
* *********************************************************************** *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
* *
* *********************************************************************** */
package org.matsim.vehicles;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
/**
* @author dgrether
*/
public interface VehicleType {
public enum DoorOperationMode {serial, parallel}
public void setDescription(String desc);
public void setLength(double length);
public void setWidth(double width);
public void setMaximumVelocity(double meterPerSecond);
public void setEngineInformation(EngineInformation currentEngineInfo);
public void setCapacity(VehicleCapacity capacity);
public double getWidth();
public double getMaximumVelocity();
public double getLength();
public EngineInformation getEngineInformation();
public String getDescription();
/**
* Comments:<ul>
* <li> What happens with multi-vehicle trains? I assume they need to be defined as a single vehicle? kai, jul'11
* </ul>
*/
public VehicleCapacity getCapacity();
public Id<VehicleType> getId();
/**
* Comments:<ul>
* <li> In my understanding, ``access'' time is the time to reach the public transit system (e.g. by walking).
* See, e.g., http://en.wikipedia.org/wiki/Public_Transport_Accessibility_Level . It is thus not the same as
* the time for one person to enter the vehicle. Or is there an alternative definition somewhere? kai, jul'11
* <li> Even if this is understood as the time per person to enter the vehicle, it needs to be clear that this is, at
* best, the emtpy vehicle entering time, and there may be additional functions computing longer vehicle entering times
* when the vehicle is full. kai, jul'11
* <li> Finally, the time needs to be understood as capacitated. I.e. when there are enough doors so that 9 passengers
* can enter the vehicle per second, then this time should be 1/9=0.111. kai, jul'11
* </ul>
*/
@Deprecated
public double getAccessTime();
/**
* See comments under getter.
*/
@Deprecated
public void setAccessTime(double seconds);
/**
* Comments:<ul>
* <li> In my understanding, ``egress'' time is either the time from the vehicle to the final destination
* (e.g. http://www.worldtransitresearch.info/research/1507/ ), or
* the time that is necessary to evacuate the vehicle. Both definitions are decidedly not the same as the
* time for one person to leave the vehicle. kai, jul'11
* <li> Also see remarks under getAccessTime() .
* </ul>
*/
@Deprecated
public double getEgressTime();
/**
* See comments under getter.
*/
@Deprecated
public void setEgressTime(double seconds);
public DoorOperationMode getDoorOperationMode();
public void setDoorOperationMode(DoorOperationMode mode);
public double getPcuEquivalents();
public void setPcuEquivalents(double pcuEquivalents);
public double getFlowEfficiencyFactor(Link link);
public void setFlowEfficiencyFactor(double flowEfficiencyFactor);
}
/* *********************************************************************** *
* project: org.matsim.*
* *
* *********************************************************************** *
* *
* copyright : (C) 2008 by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* *
* *********************************************************************** *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
* *
* *********************************************************************** */
package org.matsim.vehicles;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
/**
* @author dgrether
*/
public class VehicleTypeImpl implements VehicleType {
private double width = 1.0;
private double maxVelocity = Double.POSITIVE_INFINITY; // default: constrained only by the link speed
private double length = 7.5;
private double pcuEquivalents = 1.0;
private double flowEfficiencyFactor = 1.0;
private EngineInformation engineInformation;
private String description;