Commit 1ddc6c3d authored by clivings's avatar clivings
Browse files

a method to assign AVs and change initial plans to use AVs if available

to the agent
parent 45c0076c
......@@ -18,6 +18,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.av.AVConfigurator;
import ch.ethz.matsim.projects.astra_2018_002.av.AssignPrivatAVs;
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;
......@@ -28,14 +29,16 @@ 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) //
CommandLine cmd = new CommandLine.Builder(args) //
.requireOptions("config-path", "model") //
.allowOptions("use-route-choice", "use-only-significant", "operator-path") //
.build();
// Load config
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"), new DvrpConfigGroup(),
new AVConfigGroup());
Config config = ConfigUtils.loadConfig(cmd.getOptionStrict("config-path"), new DvrpConfigGroup(),
new AVConfigGroup());
// Adjust config
SwissModeChoiceConfigurator.configure(config);
......@@ -52,6 +55,7 @@ public class RunASTRA2018002 {
// Adjust scenario
SwissModeChoiceConfigurator.copyHousholdAttributes(scenario);
//AssignPrivatAVs.main(scenario);
FlowEfficiencyConfigurator.defineVehicleTypes(scenario);
// Set up controller
......
package ch.ethz.matsim.projects.astra_2018_002.av;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.Plan;
import org.matsim.api.core.v01.population.PlanElement;
import org.matsim.api.core.v01.population.Population;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.population.PopulationUtils;
import org.matsim.core.scenario.ScenarioUtils;
public class AssignPrivatAVs {
static public void main(String args[]) {
Config config = ConfigUtils.loadConfig(args[0]);
Scenario scenario = ScenarioUtils.loadScenario(config);
Random random = new Random(1);
for (Person person : scenario.getPopulation().getPersons().values()) {
String carAvailability = (String) person.getAttributes().getAttribute("carAvail");
//System.out.println(carAvailability);//to check that the program is actually retrieving the value of carAvail
String string1 = "always";
String string2 = "sometimes";
// if carAvail == always OR sometimes, then randomly assign an AV 6 out of 10 times, to produce
// a share of 60% AV ownership, as per the values in column P of the Excel-Table "Simulationsinput TP5"
// use. The twist is that we will not be modeling the "Living cars" nor "Kraftrad" or "One-Pod" or whatever
// it is called. We are grouping the "Pods" and "Living Cars" with Level 5 AVs and the "Kraftrad" with conventional cars.
// We will assume that only Level 5 AVs offer a significantly different VOT from convetional vehicles, because all other
// levels of automation require the driver to still be able to instantly take over (up to Level 3) or the driver can only
// allow the car to drive alone in certain situations, and we do not have time to come up with a way to consider a vehicle whose
// VOT changes depending on the links it is driving on.
if(carAvailability.equals(string1)|| carAvailability.equals(string2)){
double r = random.nextDouble();
if (r <= 0.4200) {//produces "true" 42.05% of the time
person.getAttributes().putAttribute("prAvAvail","car");
person.getAttributes().putAttribute("carAvail", "true");
} else if (r <= 0.66) {//produces "true" 65.91% of the time: because the first step took 42.05% of the agents already,
// then this step will only consider the next 23.86% of agents
person.getAttributes().putAttribute("prAvAvail","prav3");
person.getAttributes().putAttribute("carAvail", "false");
} else if (r <= 0.82){
person.getAttributes().putAttribute("prAvAvail","prav4");
person.getAttributes().putAttribute("carAvail", "false");
} else {
person.getAttributes().putAttribute("prAvAvail","prav5");
person.getAttributes().putAttribute("carAvail", "false");
}
} else { // make sure that those agents who "never" have a car available also do not have an private av available,and to
// prevent "null" exceptions from Java, which occur when a variable, such as the attribute "pAvail
person.getAttributes().putAttribute("prAvAvail","noPrav");
person.getAttributes().putAttribute("carAvail", "false");
}
// should also set selected plan to choose AV in order to start the
// scenario with the percentages give by TP5 as a starting point....
/*for (Plan plan : person.getPlans()) {
for (PlanElement element : plan.getPlanElements()) {
if (element instanceof Leg) {
Leg leg = (Leg) element;
if (leg.getMode().equals("car")) {
//need to make sure Mode is not zero, otherwise java will throw an error
leg.setMode((String) person.getAttributes().getAttribute("pAvAvail"));
}
}
}
}*/
}
for (Person person : scenario.getPopulation().getPersons().values()) {
  • Java throws a "java.lang.NullPointerException" that points to line 202 and 90 of PopulationWriterHandlerImpIV6.class . There seems to be some problem with assinging modes (but there isn't, i checked, all agents have a value in "pAvAvail" after the assignment loop) or with out one of the local variables is defined within the plan-adjustment loop.

  • Solution: it was a spelling mistake. Sometimes "prAvAvail" was used, sometimes "pAvAvail"

Please register or sign in to reply
for (Plan plan : person.getPlans()){
for (PlanElement element : plan.getPlanElements()) {
if (element instanceof Leg) {
Leg leg = (Leg) element;
if (leg.getMode().equals("car")) {
//need to make sure Mode is not zero, otherwise java will throw an error
leg.setMode((String) person.getAttributes().getAttribute("pAvAvail"));
}
}
}
}
}
//##code that assigns all persons with carAvail == "always" or "sometimes" an AV##
/*if( carAvailability.equals(string1))
person.getAttributes().putAttribute("pAvAvail", "true");
else if( carAvailability.equals(string2))
person.getAttributes().putAttribute("pAvAvail", "true");
else
person.getAttributes().putAttribute("pAvAvail", "false");
*/
Population population = scenario.getPopulation();
PopulationUtils.writePopulation(population, args[1]);
}
}
\ No newline at end of file
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