-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented pseudo random error as trip scoring, instead of leg
- Loading branch information
Showing
6 changed files
with
96 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/org/matsim/run/scoring/PseudoRandomTripScoring.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.matsim.run.scoring; | ||
|
||
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; | ||
import it.unimi.dsi.fastutil.doubles.DoubleList; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.population.Leg; | ||
import org.matsim.api.core.v01.population.Person; | ||
import org.matsim.core.router.TripStructureUtils; | ||
import org.matsim.core.scoring.ScoringFunction; | ||
import org.matsim.core.scoring.SumScoringFunction; | ||
|
||
import java.util.List; | ||
|
||
public class PseudoRandomTripScoring implements SumScoringFunction.TripScoring { | ||
|
||
private static final Logger log = LogManager.getLogger(PseudoRandomTripScoring.class); | ||
|
||
private final Id<Person> id; | ||
private final PseudoRandomScorer rng; | ||
|
||
private final DoubleList scores = new DoubleArrayList(); | ||
private double score; | ||
|
||
public PseudoRandomTripScoring(Id<Person> id, PseudoRandomScorer rng) { | ||
this.id = id; | ||
this.rng = rng; | ||
} | ||
|
||
@Override | ||
public void finish() { | ||
} | ||
|
||
@Override | ||
public double getScore() { | ||
return score; | ||
} | ||
|
||
@Override | ||
public void handleTrip(TripStructureUtils.Trip trip) { | ||
|
||
List<Leg> legs = trip.getLegsOnly(); | ||
if (legs.isEmpty()) { | ||
log.warn("Trip {} for person {} has not legs and can not be scored", trip, id); | ||
return; | ||
} | ||
|
||
double tripScore = rng.scoreTrip(id, legs.getFirst().getRoutingMode(), trip); | ||
scores.add(tripScore); | ||
score += tripScore; | ||
} | ||
|
||
@Override | ||
public void explainScore(StringBuilder out) { | ||
out.append("trips_util=").append(score); | ||
for (int i = 0; i < scores.size(); i++) { | ||
double s = scores.getDouble(i); | ||
out.append(ScoringFunction.SCORE_DELIMITER).append("trip_").append(i).append("=").append(s); | ||
} | ||
} | ||
} |