To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

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

add scoring parameters

parent f4c31b72
......@@ -21,29 +21,30 @@ public class RunASTRA2018002 {
static public void main(String[] args) throws ConfigurationException {
CommandLine cmd = new CommandLine.Builder(args) //
.requireOptions("config-path", "pt-pricing-path") //
.allowPrefixes(ModeChoiceModule.SCORING_PREFIX) //
.build();
// Load config
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"));
config.strategy().clearStrategySettings();
StrategySettings strategy = new StrategySettings();
strategy.setStrategyName("custom");
strategy.setWeight(0.2);
config.strategy().addStrategySettings(strategy);
strategy = new StrategySettings();
strategy.setStrategyName("SubtourModeChoice");
strategy.setWeight(0.0);
strategy.setDisableAfter(1);
config.strategy().addStrategySettings(strategy);
strategy = new StrategySettings();
strategy.setStrategyName("KeepLastSelected");
strategy.setWeight(0.8);
config.strategy().addStrategySettings(strategy);
cmd.applyConfiguration(config);
// Load scenario
......@@ -58,7 +59,7 @@ public class RunASTRA2018002 {
controler.addOverridingModule(new BaselineTransitModule());
File ptPricingPath = new File(cmd.getOptionStrict("pt-pricing-path"));
controler.addOverridingModule(new ModeChoiceModule(ptPricingPath));
controler.addOverridingModule(new ModeChoiceModule(ptPricingPath, cmd));
// Run
controler.run();
......
......@@ -2,8 +2,10 @@ package ch.ethz.matsim.projects.astra_2018_002.mode_choice;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.matsim.api.core.v01.network.Network;
import org.matsim.core.config.groups.PlansCalcRouteConfigGroup;
......@@ -23,6 +25,7 @@ import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import ch.ethz.matsim.baseline_scenario.config.CommandLine;
import ch.ethz.matsim.baseline_scenario.config.CommandLine.ConfigurationException;
import ch.ethz.matsim.ch_pt_utils.costs.CostCalculator;
import ch.ethz.matsim.ch_pt_utils.costs.t603.SpatialT603;
......@@ -67,16 +70,39 @@ public class ModeChoiceModule extends AbstractModule {
private static final List<String> CACHED_MODES = Arrays.asList("car", "pt", "bike", "walk");
private final File ptPricingPath;
private final CommandLine cmd;
public ModeChoiceModule(File ptPricingPath) {
public ModeChoiceModule(File ptPricingPath, CommandLine cmd) {
this.ptPricingPath = ptPricingPath;
this.cmd = cmd;
}
@Override
public void install() {
addPlanStrategyBinding("custom").toProvider(ModeChoiceModelStrategy.class);
bindPlanSelectorForRemoval().to(NonSelectedPlanSelector.class);
bind(ModeChoiceParameters.class).asEagerSingleton();
}
public final static String SCORING_PREFIX = "scoring";
@Provides
@Singleton
public ModeChoiceParameters provideModeChoiceParameters() throws ConfigurationException, NoSuchFieldException,
SecurityException, NumberFormatException, IllegalArgumentException, IllegalAccessException {
List<String> scoringOptions = cmd.getAvailableOptions().stream().filter(o -> o.startsWith(SCORING_PREFIX + ":"))
.collect(Collectors.toList());
ModeChoiceParameters parameters = new ModeChoiceParameters();
for (String option : scoringOptions) {
String parameter = option.substring(SCORING_PREFIX.length() + 1);
String value = cmd.getOptionStrict(option);
Field field = ModeChoiceParameters.class.getField(parameter);
field.set(parameters, Double.valueOf(value));
}
return parameters;
}
@Provides
......
Markdown is supported
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