Commit 16fe3e4f authored by clivings's avatar clivings
Browse files

created a static variable to make spelling mistakes harder to make when

assigning values to the "prAvAvail" attribute. 
parent 1ddc6c3d
......@@ -20,6 +20,7 @@ public class AssignPrivatAVs {
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");
......@@ -41,27 +42,27 @@ public class AssignPrivatAVs {
if (r <= 0.4200) {//produces "true" 42.05% of the time
person.getAttributes().putAttribute("prAvAvail","car");
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("prAvAvail","prav3");
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"prav3");
person.getAttributes().putAttribute("carAvail", "false");
} else if (r <= 0.82){
person.getAttributes().putAttribute("prAvAvail","prav4");
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"prav4");
person.getAttributes().putAttribute("carAvail", "false");
} else {
person.getAttributes().putAttribute("prAvAvail","prav5");
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("prAvAvail","noPrav");
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE,"noPrav");
person.getAttributes().putAttribute("carAvail", "false");
}
......@@ -77,7 +78,7 @@ public class AssignPrivatAVs {
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"));
leg.setMode((String) person.getAttributes().getAttribute(AV_AVAILABILITY_ATTRIBUTE));
}
}
}
......@@ -92,7 +93,7 @@ public class AssignPrivatAVs {
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"));
leg.setMode((String) person.getAttributes().getAttribute(AV_AVAILABILITY_ATTRIBUTE));
}
}
}
......@@ -101,13 +102,13 @@ public class AssignPrivatAVs {
//##code that assigns all persons with carAvail == "always" or "sometimes" an AV##
/*if( carAvailability.equals(string1))
person.getAttributes().putAttribute("pAvAvail", "true");
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE, "true");
else if( carAvailability.equals(string2))
person.getAttributes().putAttribute("pAvAvail", "true");
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE, "true");
else
person.getAttributes().putAttribute("pAvAvail", "false");
person.getAttributes().putAttribute(AV_AVAILABILITY_ATTRIBUTE, "false");
*/
......
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