Skip to content

Commit

Permalink
adjust homeCoord detection
Browse files Browse the repository at this point in the history
  • Loading branch information
rewertvsp committed Feb 8, 2024
1 parent b42d715 commit 4438381
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1353,12 +1353,11 @@ private static HashMap<Id<Person>, Person> findPossiblePersons(Population popula
*/
static void findLinksForPerson(Scenario scenario,
HashMap<Id<Person>, HashMap<Double, String>> nearestLinkPerPerson, Person person) {

Coord homePoint = getHomeCoord(person);
for (Link link : scenario.getNetwork().getLinks().values())
if (!link.getId().toString().contains("pt") && (!link.getAttributes().getAsMap().containsKey("type")
|| !link.getAttributes().getAsMap().get("type").toString().contains("motorway"))) {

Coord homePoint = getHomeCoord(person);
Coord middlePointLink = FreightDemandGenerationUtils.getCoordOfMiddlePointOfLink(link);
double distance = NetworkUtils.getEuclideanDistance(homePoint, middlePointLink);
if (!nearestLinkPerPerson.containsKey(person.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,39 @@ static void preparePopulation(Population population, double sampleSizeInputPopul
personsToRemove.add(person.getId());
continue;
}
for (Plan plan : person.getPlans())
for (PlanElement element : plan.getPlanElements())
if (element instanceof Activity)
if (((Activity) element).getType().contains("home")) {
double x = ((Activity) element).getCoord().getX();
double y = ((Activity) element).getCoord().getY();
person.getAttributes().putAttribute("homeX", x);
person.getAttributes().putAttribute("homeY", y);
break;
}
Coord homeCoord = null;
if (person.getSelectedPlan() != null) {
if (PopulationUtils.getActivities(person.getSelectedPlan(),
TripStructureUtils.StageActivityHandling.ExcludeStageActivities).stream().anyMatch(
activity -> activity.getType().contains("home"))) {
homeCoord = PopulationUtils.getActivities(person.getSelectedPlan(),
TripStructureUtils.StageActivityHandling.ExcludeStageActivities).stream().filter(
activity -> activity.getType().contains("home")).findFirst().get().getCoord();
}
} else if (!person.getPlans().isEmpty())
for (Plan plan : person.getPlans())
if (PopulationUtils.getActivities(plan,
TripStructureUtils.StageActivityHandling.ExcludeStageActivities).stream().anyMatch(
activity -> activity.getType().contains("home"))) {
homeCoord = PopulationUtils.getActivities(plan,
TripStructureUtils.StageActivityHandling.ExcludeStageActivities).stream().filter(
activity -> activity.getType().contains("home")).findFirst().get().getCoord();
}
if (homeCoord == null){
double home_x = (double) person.getAttributes().getAsMap().entrySet().stream().filter(
entry -> entry.getKey().contains("home") && entry.getKey().contains("X") || entry.getKey().contains("x")).findFirst().get().getValue();
double home_y = (double) person.getAttributes().getAsMap().entrySet().stream().filter(
entry -> entry.getKey().contains("home") && (entry.getKey().contains("Y") || entry.getKey().contains("y"))).findFirst().get().getValue();
homeCoord = new Coord(home_x, home_y);
}


if (homeCoord != null) {
person.getAttributes().putAttribute("homeX", homeCoord.getX());
person.getAttributes().putAttribute("homeY", homeCoord.getY());
} else {
log.warn("No home found for person " + person.getId());
}
person.removePlan(person.getSelectedPlan());
}
for (Id<Person> id : personsToRemove)
Expand Down

0 comments on commit 4438381

Please sign in to comment.