Commit 87065bf1 authored by Sebastian Hörl's avatar Sebastian Hörl
Browse files

Add Amodeus

parent 48512726
......@@ -34,6 +34,14 @@
<id>matsim-eth-packagecloud</id>
<url>https://packagecloud.io/eth-ivt/matsim/maven2</url>
</repository>
<repository>
<id>amodeus-mvn-repo</id>
<url>https://raw.github.com/idsc-frazzoli/amodeus/mvn-repo/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<build>
......@@ -70,7 +78,7 @@
<dependency>
<groupId>ch.ethz.matsim</groupId>
<artifactId>av</artifactId>
<version>0.2.6</version>
<version>0.2.7</version>
</dependency>
<dependency>
......@@ -85,6 +93,12 @@
<version>0.10.1</version>
</dependency>
<dependency>
<groupId>ch.ethz.idsc</groupId>
<artifactId>amodeus</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>ch.sbb</groupId>
<artifactId>matsim-sbb-extensions</artifactId>
......
package ch.ethz.matsim.projects.astra_2018_002;
import java.io.IOException;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.dynagent.run.DynActivityEnginePlugin;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.core.mobsim.qsim.AbstractQSimPlugin;
import org.matsim.core.mobsim.qsim.PopulationPlugin;
import org.matsim.core.mobsim.qsim.TeleportationPlugin;
import org.matsim.core.mobsim.qsim.changeeventsengine.NetworkChangeEventsPlugin;
import org.matsim.core.mobsim.qsim.messagequeueengine.MessageQueuePlugin;
import org.matsim.core.mobsim.qsim.qnetsimengine.QNetsimEnginePlugin;
import org.matsim.core.scenario.ScenarioUtils;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import ch.ethz.idsc.amodeus.matsim.mod.AmodeusDispatcherModule;
import ch.ethz.idsc.amodeus.matsim.mod.AmodeusModule;
import ch.ethz.idsc.amodeus.matsim.mod.AmodeusQSimPlugin;
import ch.ethz.idsc.amodeus.matsim.mod.AmodeusVehicleGeneratorModule;
import ch.ethz.idsc.amodeus.matsim.mod.AmodeusVehicleToVSGeneratorModule;
import ch.ethz.idsc.amodeus.net.DatabaseModule;
import ch.ethz.idsc.amodeus.net.MatsimAmodeusDatabase;
import ch.ethz.idsc.amodeus.options.ScenarioOptions;
import ch.ethz.idsc.amodeus.options.ScenarioOptionsBase;
import ch.ethz.idsc.amodeus.prep.VirtualNetworkCreators;
import ch.ethz.idsc.amodeus.traveldata.StaticTravelDataCreator;
import ch.ethz.idsc.amodeus.traveldata.TravelData;
import ch.ethz.idsc.amodeus.util.io.MultiFileTools;
import ch.ethz.idsc.amodeus.virtualnetwork.core.VirtualNetwork;
import ch.ethz.matsim.av.routing.AVRoute;
import ch.ethz.matsim.av.routing.AVRouteFactory;
import ch.ethz.matsim.baseline_scenario.config.CommandLine;
import ch.ethz.matsim.baseline_scenario.config.CommandLine.ConfigurationException;
import ch.ethz.matsim.baseline_scenario.traffic.BaselineTrafficModule;
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.baseline_scenario.transit.simulation.BaselineTransitPlugin;
import ch.ethz.matsim.discrete_mode_choice.modules.DiscreteModeChoiceModule;
import ch.ethz.matsim.projects.astra_2018_002.amodeus.ZurichReferenceFrame;
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;
import ch.ethz.matsim.projects.astra_2018_002.mode_choice.SwissUtilityParameters;
import ch.ethz.matsim.projects.astra_2018_002.mode_choice.SwissUtilityParameters.UtilitySet;
import ch.ethz.matsim.projects.astra_2018_002.private_av.PrivateAVConfigGroup;
import ch.ethz.matsim.projects.astra_2018_002.private_av.PrivateAVConfigurator;
......@@ -34,14 +61,15 @@ import ch.sbb.matsim.routing.pt.raptor.SwissRailRaptorModule;
public class RunASTRA2018002 {
private final static Logger logger = Logger.getLogger(RunASTRA2018002.class);
static public void main(String[] args) throws ConfigurationException, JsonParseException, JsonMappingException, IOException {
static public void main(String[] args) throws Exception {
CommandLine cmd = new CommandLine.Builder(args) //
.requireOptions("config-path", "year", "ASTRA_Scenario") //
.allowOptions("use-route-choice", "use-only-significant", "crossing-penalty",
"model", "use-pt-cost-reduction", "flow-efficiency-path") //
.allowOptions("use-route-choice", "use-only-significant", "crossing-penalty", "model",
"use-pt-cost-reduction", "flow-efficiency-path") //
.allowPrefixes(SwissDiscreteModeChoiceModule.COMMAND_LINE_PREFIX, "utility-parameters") //
.build();
logger.info(String.format("config-path = %s", cmd.getOptionStrict("config-path")));
logger.info(String.format("year = %s", cmd.getOptionStrict("year")));
logger.info(String.format("ASTRA_Scenario = %s", cmd.getOptionStrict("ASTRA_Scenario")));
......@@ -52,7 +80,7 @@ public class RunASTRA2018002 {
logger.info(String.format("use-pt-cost-reduction = %s", cmd.getOption("use-pt-cost-reduction")));
logger.info(String.format("flow-efficiency-path = %s", cmd.getOption("flow-efficiency-path")));
logger.info(String.format("utility-parameters = %s", SwissDiscreteModeChoiceModule.COMMAND_LINE_PREFIX));
int year = Integer.parseInt(cmd.getOptionStrict("year"));
String ASTRA_Scenario = cmd.getOptionStrict("ASTRA_Scenario");
// To do: make it throw an error if it isn't "A" or "B"
......@@ -90,6 +118,77 @@ public class RunASTRA2018002 {
new BaselineTrafficModule(cmd.getOption("crossing-penalty").map(Double::parseDouble).orElse(3.0)));
SharedAVConfigurator.configureController(controller);
// Start set up Amodeus
File workingDirectory = MultiFileTools.getDefaultWorkingDirectory();
ScenarioOptions scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault());
scenarioOptions.setProperty("shapeFile", "/home/shoerl/astra18/gis/sa_virtual_network.shp");
controller.addOverridingModule(new AmodeusModule());
controller.addOverridingModule(new AmodeusDispatcherModule());
controller.addOverridingModule(new AmodeusVehicleGeneratorModule());
controller.addOverridingModule(new AmodeusVehicleToVSGeneratorModule());
controller.addOverridingModule(new DatabaseModule());
controller.addOverridingModule(new AbstractModule() {
@Override
public void install() {
}
@Provides
@Singleton
public VirtualNetwork<Link> provideVirtualNetwork(SharedAVConfigGroup config,
@Named("av") Network network) {
int numberOfVehicles = config.getTaxiFleetSize() + config.getPooledFleetSize();
return VirtualNetworkCreators.SHAPEFILENETWORK.create(network, scenario.getPopulation(),
scenarioOptions, numberOfVehicles, 30 * 3600);
}
@Provides
@Singleton
public TravelData provideTravelData(SharedAVConfigGroup config, VirtualNetwork<Link> virtualNetwork,
@Named("av") Network avNetwork) throws Exception {
int numberOfVehicles = config.getTaxiFleetSize() + config.getPooledFleetSize();
return StaticTravelDataCreator.create(workingDirectory, virtualNetwork, avNetwork,
scenario.getPopulation(), 30 * 3600, numberOfVehicles, 30 * 3600);
}
@Provides
@Singleton
public MatsimAmodeusDatabase provideDatabase(@Named("av") Network network) {
return MatsimAmodeusDatabase.initialize(network, new ZurichReferenceFrame());
}
@Provides
@Singleton
public Collection<AbstractQSimPlugin> provideQSimPlugins(Config config) {
final Collection<AbstractQSimPlugin> plugins = new ArrayList<>();
plugins.add(new MessageQueuePlugin(config));
plugins.add(new DynActivityEnginePlugin(config));
plugins.add(new QNetsimEnginePlugin(config));
if (config.network().isTimeVariantNetwork()) {
plugins.add(new NetworkChangeEventsPlugin(config));
}
if (config.transit().isUseTransit()) {
plugins.add(new BaselineTransitPlugin(config));
}
plugins.add(new TeleportationPlugin(config));
plugins.add(new PopulationPlugin(config));
plugins.add(new AmodeusQSimPlugin(config));
return plugins;
}
});
// End set up Amodeus
UtilitySet utilitySet = Enum.valueOf(UtilitySet.class, cmd.getOption("model").orElse("ASTRA_2018_002"));
boolean useRouteChoice = cmd.getOption("use-route-choice").map(Boolean::parseBoolean).orElse(true);
boolean useOnlySignificant = cmd.getOption("use-only-significant").map(Boolean::parseBoolean).orElse(false);
......
package ch.ethz.matsim.projects.astra_2018_002.amodeus;
import org.matsim.core.utils.geometry.CoordinateTransformation;
import org.matsim.core.utils.geometry.transformations.GeotoolsTransformation;
import ch.ethz.idsc.amodeus.data.ReferenceFrame;
public class ZurichReferenceFrame implements ReferenceFrame {
@Override
public CoordinateTransformation coords_toWGS84() {
return new GeotoolsTransformation("EPSG:2056", "EPSG:4326");
}
@Override
public CoordinateTransformation coords_fromWGS84() {
return new GeotoolsTransformation("EPSG:4326", "EPSG:2056");
}
}
\ No newline at end of file
......@@ -36,6 +36,8 @@ public class SharedAVConfigGroup extends ReflectiveConfigGroup {
private final static String FIXED_POOLING_PRICE_PER_KM = "fixedPoolingPricePerKm";
private final static String FIXED_TAXI_PRICE_PER_KM = "fixedTaxiPricePerKm";
private final static String POOLING_DISPATCHER = "poolingDispatcher";
private boolean useSharedAVs = false;
private boolean useCostCalculator = false;
......@@ -67,6 +69,8 @@ public class SharedAVConfigGroup extends ReflectiveConfigGroup {
private double fixedPoolingPricePerKm = Double.NaN;
private double fixedTaxiPricePerKm = Double.NaN;
private String poolingDispatcher = "ASTRASharingDispatcher";
public SharedAVConfigGroup() {
super(GROUP_NAME);
}
......@@ -300,4 +304,14 @@ public class SharedAVConfigGroup extends ReflectiveConfigGroup {
public void setFixedTaxiPricePerKm(double fixedTaxiPricePerKm) {
this.fixedTaxiPricePerKm = fixedTaxiPricePerKm;
}
@StringGetter(POOLING_DISPATCHER)
public String getPoolingDispatcher() {
return poolingDispatcher;
}
@StringSetter(POOLING_DISPATCHER)
public void setPoolingDispatcher(String poolingDispatcher) {
this.poolingDispatcher = poolingDispatcher;
}
}
......@@ -161,7 +161,7 @@ public class SharedAVModule extends AbstractDiscreteModeChoiceExtension {
AVGeneratorConfig poolGeneratorConfig = poolConfig.createGeneratorConfig(SharedAVModule.GENERATOR_NAME);
poolGeneratorConfig.setNumberOfVehicles(astraConfig.getPooledFleetSize());
AVDispatcherConfig poolDispatcherConfig = poolConfig.createDispatcherConfig("ASTRADispatcher");
AVDispatcherConfig poolDispatcherConfig = poolConfig.createDispatcherConfig(astraConfig.getPoolingDispatcher());
poolConfig.createPriceStructureConfig();
// double poolingThreshold_min = astraConfig.getPoolingThreshold_min();
......
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