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

Merge branch 'master' of gitlab.ethz.ch:ivt-vpl/astra_2018_002

parents 6df99ed2 05ed3a57
......@@ -17,6 +17,8 @@ import org.matsim.core.scenario.ScenarioUtils;
public class AssignPrivatAVs {
static public final String AV_AVAILABILITY_ATTRIBUTE = "prAvAvail";
static public final String FREIGHT_AV = "freight_av";
static public final Boolean freight_av = false;
static public void main(Scenario scenario, int year, String ASTRA_Scenario) {
//Config config = ConfigUtils.loadConfig(args[0]);
......@@ -24,6 +26,11 @@ public class AssignPrivatAVs {
Random random = new Random(1);
for (Person person : scenario.getPopulation().getPersons().values()) {
Boolean isFreight = (Boolean) person.getAttributes().getAttribute("isFreight");
if (isFreight != null && isFreight) {
continue;
}
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";
......@@ -140,8 +147,172 @@ public class AssignPrivatAVs {
person.getAttributes().putAttribute("carAvail", "never");
}
} else if (ASTRA_Scenario.equals("B")&& year >= 2050){
//TODO reduce amount of agents who have car available "always" and "sometimes" compared to ASTRA Scenario A,
// in accordance with what TP5 gives us! So change at which value of r the first condition will be true.
if(carAvailability.equals(string1)|| carAvailability.equals(string2)){
double r = random.nextDouble();
if (r <= 0.81500) {//produces "true" 81.50% of the time
//if they are part of this lucky percentage, they have "decided" to keep their/purchase a car, else...
person.getAttributes().putAttribute("carAvail", carAvailability);
} else { //...else they have "decided" to give up their/not purchase a car! They've converted to the sharing economy!
person.getAttributes().putAttribute("carAvail", "never");
}
}
//now, for the agents that still have cars, aka whose attribute "carAvail" still equals "always" or "sometimes"...
//let us assign which one of them has a car capable of autonomous operation...
if(carAvailability.equals(string1)|| carAvailability.equals(string2)){
double r = random.nextDouble();
//TODO change percentages to match what TP5 gives us for ASTRA Scenario B!
// these agents still have good ol' conventional cars....
if (r <= 0.61400) {//produces "true" 61.40% of the time
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"car");
person.getAttributes().putAttribute("carAvail", carAvailability);
//currently only differentiating between conventional vehicles and "highly automated, highly networked" vehicles
//thus these next to bits of code are commented out...
/*} 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", "never");
} else if (r <= 0.82){
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"prav4");
person.getAttributes().putAttribute("carAvail", "never");
*/
//now, for the other lucky few, they now will have an autonomous vehicle
//we also specify that agents never have BOTH a conventional car and an autonomous vehicle
} else {
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"prav5");
person.getAttributes().putAttribute("carAvail", "never");
}
} 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 "prAvAvail" don't have a value
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"noPrav");
person.getAttributes().putAttribute("carAvail", "never");
}
} else if (ASTRA_Scenario.equals("B")&& year >= 2040){
//TODO reduce amount of agents who have car available "always" and "sometimes" compared to ASTRA Scenario A,
// in accordance with what TP5 gives us! So change at which value of r the first condition will be true.
if(carAvailability.equals(string1)|| carAvailability.equals(string2)){
double r = random.nextDouble();
if (r <= 0.84700) {//produces "true" 84.70% of the time
//if they are part of this lucky percentage, they have "decided" to keep their/purchase a car, else...
person.getAttributes().putAttribute("carAvail", carAvailability);
} else { //...else they have "decided" to give up their/not purchase a car! They've converted to the sharing economy!
person.getAttributes().putAttribute("carAvail", "never");
}
}
//now, for the agents that still have cars, aka whose attribute "carAvail" still equals "always" or "sometimes"...
//let us assign which one of them has a car capable of autonomous operation...
if(carAvailability.equals(string1)|| carAvailability.equals(string2)){
double r = random.nextDouble();
//TODO change percentages to match what TP5 gives us for ASTRA Scenario B!
// these agents still have good ol' conventional cars....
if (r <= 0.93300) {//produces "true" 93.30% of the time
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"car");
person.getAttributes().putAttribute("carAvail", carAvailability);
//currently only differentiating between conventional vehicles and "highly automated, highly networked" vehicles
//thus these next to bits of code are commented out...
/*} 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", "never");
} else if (r <= 0.82){
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"prav4");
person.getAttributes().putAttribute("carAvail", "never");
*/
//now, for the other lucky few, they now will have an autonomous vehicle
//we also specify that agents never have BOTH a conventional car and an autonomous vehicle
} else {
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"prav5");
person.getAttributes().putAttribute("carAvail", "never");
}
} 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 "prAvAvail" don't have a value
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"noPrav");
person.getAttributes().putAttribute("carAvail", "never");
}
} else if (ASTRA_Scenario.equals("B")&& year >= 2030){
//TODO reduce amount of agents who have car available "always" and "sometimes" compared to ASTRA Scenario A,
// in accordance with what TP5 gives us! So change at which value of r the first condition will be true.
if(carAvailability.equals(string1)|| carAvailability.equals(string2)){
double r = random.nextDouble();
if (r <= 0.94700) {//produces "true" 94.70% of the time
//if they are part of this lucky percentage, they have "decided" to keep their/purchase a car, else...
person.getAttributes().putAttribute("carAvail", carAvailability);
} else { //...else they have "decided" to give up their/not purchase a car! They've converted to the sharing economy!
person.getAttributes().putAttribute("carAvail", "never");
}
}
//now, for the agents that still have cars, aka whose attribute "carAvail" still equals "always" or "sometimes"...
//let us assign which one of them has a car capable of autonomous operation...
if(carAvailability.equals(string1)|| carAvailability.equals(string2)){
double r = random.nextDouble();
//TODO change percentages to match what TP5 gives us for ASTRA Scenario B!
// these agents still have good ol' conventional cars....
if (r <= 0.99500) {//produces "true" 99.50% of the time
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"car");
person.getAttributes().putAttribute("carAvail", carAvailability);
//currently only differentiating between conventional vehicles and "highly automated, highly networked" vehicles
//thus these next to bits of code are commented out...
/*} 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", "never");
} else if (r <= 0.82){
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"prav4");
person.getAttributes().putAttribute("carAvail", "never");
*/
//now, for the other lucky few, they now will have an autonomous vehicle
//we also specify that agents never have BOTH a conventional car and an autonomous vehicle
} else {
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"prav5");
person.getAttributes().putAttribute("carAvail", "never");
}
} 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 "prAvAvail" don't have a value
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"noPrav");
person.getAttributes().putAttribute("carAvail", "never");
}
} else if (ASTRA_Scenario.equals("B")&& year <= 2030){
if(carAvailability.equals(string1)|| carAvailability.equals(string2)){
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"car");
person.getAttributes().putAttribute("carAvail", carAvailability);
} 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 "prAvAvail" don't have a value
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"noPrav");
person.getAttributes().putAttribute("carAvail", "never");
}
}
}
// should also set selected plan to choose AV in order to start the
// scenario with the percentages given by TP5 as a starting point....
......@@ -164,17 +335,51 @@ public class AssignPrivatAVs {
}
}
}
//TODO for loop to assign freight vehicles av property or not.
//Variable name will be "FREIGHT_AV"
//Attribute name will be "freight_av" and it will be of type boolean
for (Person person : scenario.getPopulation().getPersons().values()) {
Boolean isFreight = (Boolean) person.getAttributes().getAttribute("isFreight");
if (isFreight != null && isFreight) {
if( year >= 2050){
//TODO put the values that TP5 gives us as conditions for freight av market penetration 2050
double r = random.nextDouble();
if (r <= 0.6000) {
person.getAttributes().putAttribute(FREIGHT_AV,true);
} else {
person.getAttributes().putAttribute(FREIGHT_AV,false);
}
} else if(year >= 2040){
//TODO put the values that TP5 gives us as conditions for freight av market penetration 2040
double r = random.nextDouble();
if (r <= 0.7500) {
person.getAttributes().putAttribute(FREIGHT_AV,true);
} else {
person.getAttributes().putAttribute(FREIGHT_AV,false);
}
} else if( year >= 2030){
//TODO put the values that TP5 gives us as conditions for freight av market penetration 2030
double r = random.nextDouble();
if (r <= 0.9000) {
person.getAttributes().putAttribute(FREIGHT_AV,true);
} else {
person.getAttributes().putAttribute(FREIGHT_AV,false);
}
} else {
person.getAttributes().putAttribute(FREIGHT_AV,false);
}
}
}
//##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();
......
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