Commit 1608701a authored by clivings's avatar clivings
Browse files

Merge branch 'clarissa' into 'master'

Clarissa - AV Assingment should be ready

See merge request !2
parents e419fb26 8a08f92f
......@@ -21,7 +21,7 @@ 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", "utility-parameters", "crossing-penalty") //
.allowPrefixes(SwissDiscreteModeChoiceModule.COMMAND_LINE_PREFIX) //
......@@ -54,6 +54,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);
final String AV_AVAILABILITY_ATTRIBUTE = "prAvAvail";
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(AV_AVAILABILITY_ATTRIBUTE,"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(AV_AVAILABILITY_ATTRIBUTE,"prav3");
person.getAttributes().putAttribute("carAvail", "false");
} else if (r <= 0.82){
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"prav4");
person.getAttributes().putAttribute("carAvail", "false");
} else {
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"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(AV_AVAILABILITY_ATTRIBUTE,"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(AV_AVAILABILITY_ATTRIBUTE));
}
}
}
}*/
}
for (Person person : scenario.getPopulation().getPersons().values()) {
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(AV_AVAILABILITY_ATTRIBUTE));
}
}
}
}
}
//##code that assigns all persons with carAvail == "always" or "sometimes" an AV##
/*if( carAvailability.equals(string1))
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE, "true");
else if( carAvailability.equals(string2))
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE, "true");
else
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE, "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