1 package org.matsim.core.population.routes;
3 import org.apache.logging.log4j.LogManager;
4 import org.apache.logging.log4j.Logger;
9 import java.util.Iterator;
10 import java.util.List;
11 import java.util.Optional;
25 return compare(population1, population2, DEFAULT_DELTA);
32 Iterator<? extends Person> it1 = population1.
getPersons().values().iterator();
33 Iterator<? extends Person> it2 = population2.
getPersons().values().iterator();
35 while (it1.hasNext() || it2.hasNext()) {
39 log.warn(
" different length in populations. ");
45 log.warn(
" different length in populations. ");
49 Person person1 = it1.next();
50 Person person2 = it2.next();
52 if (!person1.getId().equals(person2.getId())) {
54 log.warn(
"persons out of sequence p1: " + person1.getId() +
" | p2: " + person2.getId());
61 log.warn(
"person attributes different p1: " + person1.getId() +
" | p2: " + person2.getId());
69 log.warn(
"selected plan attributes different p1: " + person1.getId() +
" | p2: " + person2.getId());
72 Optional<Double> score1 = Optional.ofNullable(plan1.
getScore());
73 Optional<Double> score2 = Optional.ofNullable(plan2.
getScore());
75 if (score1.isPresent() && score2.isPresent()) {
78 double maxScore = Double.NEGATIVE_INFINITY;
80 if (plan.getScore() > maxScore) {
81 maxScore = plan.getScore();
86 log.warn(
"personId=" + person1.getId() +
"; score1=" + plan1.
getScore() +
"; score2=" + plan2.
getScore() +
"; maxScore2=" + maxScore);
92 }
else if (score1.isEmpty() && score2.isEmpty()) {
95 log.warn(
" selected plan scores not consistently present: p1: " + person1.getId() +
" | p2: " + person2.getId());
101 log.warn(
" selected plan elements not equal: p1: " + person1.getId() +
" | p2: " + person2.getId());
104 log.warn(planElement);
108 log.warn(planElement);
117 private static boolean isWithinDelta(
double double1,
double double2,
double delta) {
118 return Math.abs(double1 - double2) < delta;
130 public static boolean equals(List<PlanElement> planElements,
131 List<PlanElement> planElements2) {
132 return equals(planElements, planElements2, DEFAULT_DELTA);
135 public static boolean equals(List<PlanElement> planElements,
136 List<PlanElement> planElements2,
double delta) {
137 int nElements = planElements.size();
138 if (nElements != planElements2.size()) {
141 for (
int i = 0; i < nElements; i++) {
142 if (!
equals(planElements.get(i), planElements2.get(i), delta)) {
157 if (o1 instanceof
Leg leg1) {
158 if (o2 instanceof
Leg leg2) {
162 if (!leg1.getMode().equals(leg2.getMode())) {
171 }
else if (o1 instanceof
Activity activity1) {
172 if (o2 instanceof
Activity activity2) {
Attributes getAttributes()
static boolean equals(List< PlanElement > planElements, List< PlanElement > planElements2, double delta)
static boolean isBothUndefinedOrWithinDelta(OptionalTime time1, OptionalTime time2, double delta)
Map< Id< Person >,? extends Person > getPersons()
static boolean equals(List< PlanElement > planElements, List< PlanElement > planElements2)
static boolean equals(Attributes a1, Attributes a2)
static Result compare(Population population1, Population population2)
static Result compare(Population population1, Population population2, double delta)
List< PlanElement > getPlanElements()
static final double DEFAULT_DELTA
static boolean equals(PlanElement o1, PlanElement o2, double delta)
static boolean isWithinDelta(double double1, double double2, double delta)
abstract T getSelectedPlan()
abstract List<? extends T > getPlans()