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

Make ready for freight

parent 6d2db22d
package ch.ethz.matsim.projects.astra_2018_002;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.core.config.Config;
import org.matsim.core.config.groups.ControlerConfigGroup.RoutingAlgorithmType;
public class ASTRAConfigurator {
static public void configure(Config config) {
config.controler().setRoutingAlgorithmType(RoutingAlgorithmType.FastAStarLandmarks);
Collection<String> mainModes = new ArrayList<>(config.qsim().getMainModes());
mainModes.addAll(Arrays.asList("truck", "truckAv"));
config.qsim().setMainModes(mainModes);
Set<String> networkModes = new HashSet<>(config.plansCalcRoute().getNetworkModes());
networkModes.addAll(Arrays.asList("truck", "truckAv"));
config.plansCalcRoute().setNetworkModes(networkModes);
}
static public void checkNetwork(Scenario scenario, int year) {
static public void updateNetwork(Scenario scenario, int year) {
for (Link link : scenario.getNetwork().getLinks().values()) {
if (link.getAllowedModes().contains("car")) {
Set<String> allowedModes = new HashSet<>(link.getAllowedModes());
allowedModes.addAll(Arrays.asList("truck", "car_passenger", "truckAv"));
link.setAllowedModes(allowedModes);
}
}
if (year >= 2030) {
for (Link link : scenario.getNetwork().getLinks().values()) {
if (link.getAllowedModes().contains("prav3")) {
......
......@@ -58,7 +58,7 @@ public class RunASTRA2018002 {
SwissModeChoiceConfigurator.copyHousholdAttributes(scenario);
FlowEfficiencyConfigurator.defineVehicleTypes(scenario, year);
PrivateAVConfigurator.assignPrivateAVs(scenario, year, ASTRA_Scenario);
ASTRAConfigurator.checkNetwork(scenario, year);
ASTRAConfigurator.updateNetwork(scenario, year);
// Set up controller
Controler controller = new Controler(scenario);
......
......@@ -22,11 +22,17 @@ public class SwissModeAvailability extends CarModeAvailability {
@Override
public Collection<String> getAvailableModes(Person person, List<DiscreteModeChoiceTrip> trips) {
Boolean isFreight = (Boolean) person.getAttributes().getAttribute("isFreight");
if (isFreight != null && isFreight) {
return Collections.singleton("truck");
Boolean freightAv = (Boolean) person.getAttributes().getAttribute("freight_av");
if (freightAv != null && freightAv) {
return Collections.singleton("truckAv");
} else {
return Collections.singleton("truck");
}
}
boolean bikeAvailability = !"FOR_NONE".equals((String) person.getAttributes().getAttribute("bikeAvailability"));
Set<String> modes = new HashSet<>();
......
......@@ -35,7 +35,7 @@ public class SwissModeChoiceConfigurator {
dmcConfig.setTripEstimator(SwissDiscreteModeChoiceModule.SWISS_ESTIMATOR_NAME);
dmcConfig.setTourEstimator(EstimatorModule.CUMULATIVE);
dmcConfig.setCachedModes(Arrays.asList("car", "bike", "pt", "walk", "car_passenger", "truck"));
dmcConfig.setCachedModes(Arrays.asList("car", "bike", "pt", "walk", "car_passenger", "truck", "truckAv"));
dmcConfig.setTourFinder(SwissDiscreteModeChoiceModule.SWISS_TOUR_FINDER_NAME);
dmcConfig.getActivityTourFinderConfigGroup().setActivityType("home");
......@@ -50,7 +50,7 @@ public class SwissModeChoiceConfigurator {
SwissDiscreteModeChoiceModule.PASSENGER_CONSTRAINT_NAME));
dmcConfig.getVehicleTourConstraintConfig().setHomeType(HomeType.USE_ACTIVITY_TYPE);
dmcConfig.getVehicleTourConstraintConfig().setRestrictedModes(Arrays.asList("car", "bike"));
dmcConfig.getVehicleTourConstraintConfig().setRestrictedModes(Arrays.asList("car", "bike", "prav3", "prav4", "prav5"));
dmcConfig.setTourFilters(Arrays.asList(SwissDiscreteModeChoiceModule.OUTSIDE_FILTER));
......@@ -70,6 +70,7 @@ public class SwissModeChoiceConfigurator {
scoringConfig.getOrCreateModeParams("car_passenger");
scoringConfig.getOrCreateModeParams("truck");
scoringConfig.getOrCreateModeParams("truckAv");
// Some additional settings
config.controler().setRoutingAlgorithmType(RoutingAlgorithmType.FastAStarLandmarks);
......
......@@ -55,6 +55,11 @@ public abstract class BaseUtilityEstimator extends AbstractTripRouterEstimator {
protected double estimateTrip(Person person, String mode, DiscreteModeChoiceTrip trip,
List<TripCandidate> previousTrips, List<? extends PlanElement> routedTrip) {
Boolean rawIsFreight = (Boolean) person.getAttributes().getAttribute("isFreight");
if (rawIsFreight != null && rawIsFreight) {
return 0.0;
}
PersonVariables personVariables = new PersonVariables();
personVariables.age_over18a = Math.max(0.0,
......
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