Commit 0e6ad27e authored by Sebastian Hörl's avatar Sebastian Hörl
Browse files

add avs

parent 38ae6bc4
package ch.ethz.matsim.projects.astra_2018_002;
import java.io.File;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.dvrp.trafficmonitoring.DvrpTravelTimeModule;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.ControlerConfigGroup.RoutingAlgorithmType;
import org.matsim.core.controler.Controler;
import org.matsim.core.scenario.ScenarioUtils;
import ch.ethz.matsim.av.framework.AVConfigGroup;
import ch.ethz.matsim.av.framework.AVModule;
import ch.ethz.matsim.baseline_scenario.config.CommandLine;
import ch.ethz.matsim.baseline_scenario.config.CommandLine.ConfigurationException;
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.av.AVConfigurator;
import ch.ethz.matsim.projects.astra_2018_002.av.operating_area.OperatingAreaModule;
import ch.ethz.matsim.projects.astra_2018_002.av.operator.OperatorModule;
import ch.ethz.matsim.projects.astra_2018_002.flow_efficiency.FlowEfficiencyConfigurator;
import ch.ethz.matsim.projects.astra_2018_002.mode_choice.SwissDiscreteModeChoiceModule;
import ch.ethz.matsim.projects.astra_2018_002.mode_choice.SwissModeChoiceConfigurator;
......@@ -23,16 +29,18 @@ import ch.sbb.matsim.routing.pt.raptor.SwissRailRaptorModule;
public class RunASTRA2018002 {
static public void main(String[] args) throws ConfigurationException {
CommandLine cmd = new CommandLine.Builder(args) //
.requireOptions("config-path", "model") //
.requireOptions("config-path", "model", "operator-path") //
.allowOptions("use-route-choice", "use-only-significant") //
.build();
// Load config
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"));
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"), new DvrpConfigGroup(),
new AVConfigGroup());
// Adjust config
SwissModeChoiceConfigurator.configure(config);
//FlowEfficiencyConfigurator.configure(config);
FlowEfficiencyConfigurator.configure(config);
AVConfigurator.configure(config);
cmd.applyConfiguration(config);
......@@ -44,13 +52,17 @@ public class RunASTRA2018002 {
// Adjust scenario
SwissModeChoiceConfigurator.copyHousholdAttributes(scenario);
//FlowEfficiencyConfigurator.defineVehicleTypes(scenario);
FlowEfficiencyConfigurator.defineVehicleTypes(scenario);
// Set up controller
Controler controler = new Controler(scenario);
controler.addOverridingModule(new DvrpTravelTimeModule());
controler.addOverridingModule(new SwissRailRaptorModule());
controler.addOverridingModule(new AVModule());
controler.addOverridingModule(new OperatingAreaModule());
controler.addOverridingModule(new OperatorModule(new File(cmd.getOptionStrict("operator-path"))));
controler.addOverridingModule(new BaselineTransitModule());
//controler.addOverridingModule(new AVModule());
// TODO: Consolidate QSim plugins
UtilitySet utilitySet = Enum.valueOf(UtilitySet.class, cmd.getOptionStrict("model"));
boolean useRouteChoice = cmd.getOption("use-route-choice").map(Boolean::parseBoolean).orElse(true);
......
package ch.ethz.matsim.projects.astra_2018_002.av;
import org.matsim.core.config.Config;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup.ModeParams;
import ch.ethz.matsim.av.framework.AVModule;
public class AVConfigurator {
static public void configure(Config config) {
ModeParams avParams = new ModeParams(AVModule.AV_MODE);
config.planCalcScore().addModeParams(avParams);
}
}
package ch.ethz.matsim.projects.astra_2018_002.av.operating_area;
import java.util.Collection;
import java.util.HashSet;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import ch.ethz.matsim.av.framework.AVModule;
import ch.ethz.matsim.av.framework.AVUtils;
import ch.ethz.matsim.discrete_mode_choice.modules.AbstractDiscreteModeChoiceExtension;
import ch.ethz.matsim.projects.astra_2018_002.av.operator.Operator;
public class OperatingAreaModule extends AbstractDiscreteModeChoiceExtension {
private final static GeometryFactory geometryFactory = new GeometryFactory();
public static final String CONSTRAINT_NAME = "OperatingArea";
public static final String GENERATOR_NAME = "OperatingArea";
......@@ -24,7 +38,25 @@ public class OperatingAreaModule extends AbstractDiscreteModeChoiceExtension {
@Provides
@Singleton
public OperatingAreaRegistry provideOperatingAreaRegistry() {
return new OperatingAreaRegistry();
public OperatingAreaRegistry provideOperatingAreaRegistry(Collection<Operator> operators,
@Named(AVModule.AV_MODE) Network network) {
OperatingAreaRegistry registry = new OperatingAreaRegistry();
for (Operator operator : operators) {
Collection<Link> links = new HashSet<>();
for (Link link : network.getLinks().values()) {
Coordinate coordinate = new Coordinate(link.getCoord().getX(), link.getCoord().getY());
Point point = geometryFactory.createPoint(coordinate);
if (operator.getShape().contains(point)) {
links.add(link);
}
}
registry.addOperatingArea(operator.getName(), links);
}
return registry;
}
}
......@@ -8,10 +8,13 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
public class OperatingAreaRegistry {
private final static Logger logger = Logger.getLogger(OperatingAreaRegistry.class);
private final List<String> areaNames = new LinkedList<>();
private final List<Collection<Link>> linksForAreas = new LinkedList<>();
private final Map<Id<Link>, Set<Integer>> areasForLinks = new HashMap<>();
......@@ -29,6 +32,8 @@ public class OperatingAreaRegistry {
areasForLinks.get(linkId).add(areaNames.size() - 1);
}
logger.info(String.format("Registered %d links for operator %s", links.size(), operatingArea));
}
public boolean areLinksCoveredAndConnected(Id<Link> originId, Id<Link> destinationId) {
......
package ch.ethz.matsim.projects.astra_2018_002.av.operator;
import com.vividsolutions.jts.geom.Geometry;
public class Operator {
private final String name;
private final Geometry shape;
private final int fleetSize;
public Operator(String name, Geometry shape, int fleetSize) {
this.shape = shape;
this.fleetSize = fleetSize;
this.name = name;
}
public String getName() {
return name;
}
public Geometry getShape() {
return shape;
}
public int getFleetSize() {
return fleetSize;
}
}
package ch.ethz.matsim.projects.astra_2018_002.av.operator;
import java.io.File;
import java.net.MalformedURLException;
import java.util.Collection;
import org.matsim.api.core.v01.Id;
import org.matsim.core.controler.AbstractModule;
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.Vehicles;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import ch.ethz.matsim.av.config.AVConfig;
import ch.ethz.matsim.av.config.AVGeneratorConfig;
import ch.ethz.matsim.av.config.AVOperatorConfig;
import ch.ethz.matsim.av.framework.AVModule;
import ch.ethz.matsim.projects.astra_2018_002.av.operating_area.OperatingAreaModule;
public class OperatorModule extends AbstractModule {
private final File operatorPath;
public OperatorModule(File operatorPath) {
this.operatorPath = operatorPath;
}
@Override
public void install() {
}
@Provides
@Singleton
public Collection<Operator> provideOperators() throws MalformedURLException {
return new OperatorReader().read(operatorPath.toURI().toURL());
}
@Provides
@Singleton
public AVConfig provideAVConfig(Collection<Operator> operators) {
AVConfig avConfig = new AVConfig();
for (Operator operator : operators) {
AVOperatorConfig operatorConfig = avConfig.createOperatorConfig(operator.getName());
AVGeneratorConfig generatorConfig = operatorConfig
.createGeneratorConfig(OperatingAreaModule.GENERATOR_NAME);
generatorConfig.setNumberOfVehicles(operator.getFleetSize());
operatorConfig.createDispatcherConfig("SingleHeuristic");
operatorConfig.createPriceStructureConfig();
}
return avConfig;
}
@Provides
@Singleton
@Named(AVModule.AV_MODE)
public VehicleType provideAVVehicleType(Vehicles vehicles) {
return vehicles.getVehicleTypes().get(Id.create("shared_av", VehicleType.class));
}
}
package ch.ethz.matsim.projects.astra_2018_002.av.operator;
import java.io.IOException;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.opengis.feature.simple.SimpleFeature;
import com.vividsolutions.jts.geom.Geometry;
public class OperatorReader {
public Collection<Operator> read(URL url) {
List<Operator> operators = new LinkedList<>();
try {
DataStore dataStore = DataStoreFinder.getDataStore(Collections.singletonMap("url", url));
SimpleFeatureSource featureSource = dataStore.getFeatureSource(dataStore.getTypeNames()[0]);
SimpleFeatureCollection featureCollection = featureSource.getFeatures();
SimpleFeatureIterator featureIterator = featureCollection.features();
while (featureIterator.hasNext()) {
SimpleFeature feature = featureIterator.next();
String name = (String) feature.getAttribute("OAREA");
Integer fleetSize = (Integer) feature.getAttribute("FLEETSIZE");
Operator operator = new Operator(name, (Geometry) feature.getDefaultGeometry(), fleetSize);
operators.add(operator);
}
featureIterator.close();
dataStore.dispose();
} catch (IOException e) {
throw new RuntimeException(e);
}
return operators;
}
}
......@@ -17,16 +17,24 @@ public class FlowEfficiencyConfigurator {
// config.travelTimeCalculator().setSeparateModes(true);
// Set the calculator instance (not the best design, but works)
// TODO: Here we will be able to distinguish between HLS and other roads in
// combination with vehicle types
FlowEfficiencyCalculator calculator = new StaticFlowEfficiencyCalculator();
FlowEfficiencyCalculator.INSTANCE.set(calculator);
}
static public void defineVehicleTypes(Scenario scenario) {
VehicleType carVehicleType = VehicleUtils.getDefaultVehicleType();
VehicleType carVehicleType = VehicleUtils.getFactory() //
.createVehicleType(Id.create("car", VehicleType.class));
scenario.getVehicles().addVehicleType(carVehicleType);
VehicleType privateAvVehicleType = VehicleUtils.getFactory()
VehicleType privateAvVehicleType = VehicleUtils.getFactory() //
.createVehicleType(Id.create("private_av", VehicleType.class));
scenario.getVehicles().addVehicleType(privateAvVehicleType);
VehicleType sharedAvVehicleType = VehicleUtils.getFactory() //
.createVehicleType(Id.create("shared_av", VehicleType.class));
scenario.getVehicles().addVehicleType(sharedAvVehicleType);
}
}
......@@ -22,6 +22,7 @@ import ch.ethz.matsim.discrete_mode_choice.modules.SelectorModule;
import ch.ethz.matsim.discrete_mode_choice.modules.TourFinderModule;
import ch.ethz.matsim.discrete_mode_choice.modules.config.DiscreteModeChoiceConfigGroup;
import ch.ethz.matsim.discrete_mode_choice.modules.config.VehicleTourConstraintConfigGroup.HomeType;
import ch.ethz.matsim.projects.astra_2018_002.av.operating_area.OperatingAreaModule;
public class SwissModeChoiceConfigurator {
static public void configure(Config config) {
......@@ -47,8 +48,7 @@ public class SwissModeChoiceConfigurator {
dmcConfig.setTourConstraints(
Arrays.asList(ConstraintModule.VEHICLE_CONTINUITY, ConstraintModule.FROM_TRIP_BASED));
dmcConfig.setTripConstraints(Arrays.asList(ConstraintModule.TRANSIT_WALK)); // ,
// OperatingAreaModule.CONSTRAINT_NAME));
dmcConfig.setTripConstraints(Arrays.asList(ConstraintModule.TRANSIT_WALK, OperatingAreaModule.CONSTRAINT_NAME));
dmcConfig.getVehicleTourConstraintConfig().setHomeType(HomeType.USE_ACTIVITY_TYPE);
dmcConfig.getVehicleTourConstraintConfig().setRestrictedModes(Arrays.asList("car", "bike"));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment