Skip to content

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
luchengqi7 committed May 22, 2024
1 parent a410d7d commit 3f58fbb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public EuclideanDistanceBasedDrtEstimator(Network network, double networkDistanc
this.networkDistanceFactor = networkDistanceFactor;
this.tripEstimator = new ConstantTripEstimator(slope, intercept);
this.waitingTimeEstimator = new ConstantWaitingTimeEstimator(estimatedMeanWaitTime);
this.rideDurationDistributionGenerator = new LogNormalDistributionGenerator(new Random(4711), mu, sigma);
this.waitingTimeDistributionGenerator = new NormalDistributionGenerator(4711, waitTimeStd);
this.rideDurationDistributionGenerator = new LogNormalDistributionGenerator(1, mu, sigma);
this.waitingTimeDistributionGenerator = new NormalDistributionGenerator(2, waitTimeStd);
}

public EuclideanDistanceBasedDrtEstimator(Network network, double networkDistanceFactor, TripEstimator tripEstimator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.drt.estimator.DrtEstimator;
import org.matsim.contrib.drt.estimator.impl.distribution.DistributionGenerator;
import org.matsim.contrib.drt.estimator.impl.distribution.LogNormalDistributionGenerator;
import org.matsim.contrib.drt.estimator.impl.distribution.NormalDistributionGenerator;
import org.matsim.contrib.drt.estimator.impl.trip_estimation.ConstantTripEstimator;
import org.matsim.contrib.drt.estimator.impl.trip_estimation.TripEstimator;
Expand All @@ -13,6 +14,8 @@
import org.matsim.core.utils.collections.Tuple;
import org.matsim.core.utils.misc.OptionalTime;

import java.util.Random;

/**
* DRT estimator that uses available data (e.g., real-world operational data, simulation-based data) to provide estimated data for DRT trips.
*/
Expand Down Expand Up @@ -71,13 +74,35 @@ public NetworkBasedDrtEstimator(TripEstimator rideDurationEstimator, WaitingTime
* @param waitTimeStd standard deviation of waiting time (normalized to 1)
* @return NetworkBasedDrtEstimator
*/
public static NetworkBasedDrtEstimator normalDistributed(double estRideTimeAlpha, double estRideTimeBeta, double rideTimeStd, double estMeanWaitTime,
double waitTimeStd) {
public static NetworkBasedDrtEstimator normalDistributedNetworkBasedDrtEstimator(double estRideTimeAlpha, double estRideTimeBeta,
double rideTimeStd, double estMeanWaitTime,
double waitTimeStd) {
return new Builder()
.setWaitingTimeEstimator(new ConstantWaitingTimeEstimator(estMeanWaitTime))
.setRideDurationEstimator(new ConstantTripEstimator(estRideTimeAlpha, estRideTimeBeta))
.setWaitingTimeDistributionGenerator(new NormalDistributionGenerator(1, waitTimeStd))
.setRideDurationDistributionGenerator(new NormalDistributionGenerator(2, rideTimeStd))
.build();
}

/**
* Example DRT estimator based on the log-normal distributed ride time and normal distributed waiting time
* @param estRideTimeAlpha typical ride duration = alpha * direct ride time + beta, alpha is specified here
* @param estRideTimeBeta typical ride duration = alpha * direct ride time + beta, beta is specified here
* @param mu log-normal distribution parameter for ride duration (normalized to typical ride duration)
* @param sigma log-normal distribution parameter for ride duration (normalized to typical ride duration)
* @param estMeanWaitTime estimated waiting time (i.e., mean wait time)
* @param waitTimeStd standard deviation of waiting time (normalized to 1)
* @return NetworkBasedDrtEstimator
*/
public static NetworkBasedDrtEstimator mixDistributedNetworkBasedDrtEstimator(double estRideTimeAlpha, double estRideTimeBeta,
double mu, double sigma, double estMeanWaitTime,
double waitTimeStd) {
return new Builder()
.setWaitingTimeEstimator(new ConstantWaitingTimeEstimator(estMeanWaitTime))
.setRideDurationEstimator(new ConstantTripEstimator(estRideTimeAlpha, estRideTimeBeta))
.setWaitingTimeDistributionGenerator(new NormalDistributionGenerator(4711, waitTimeStd))
.setRideDurationDistributionGenerator(new NormalDistributionGenerator(4711, rideTimeStd))
.setWaitingTimeDistributionGenerator(new NormalDistributionGenerator(1, waitTimeStd))
.setRideDurationDistributionGenerator(new LogNormalDistributionGenerator(2, mu, sigma))
.build();
}

Expand All @@ -91,7 +116,7 @@ public Estimate estimate(DrtRoute route, OptionalTime departureTime) {
double alpha = alphaBetaTuple.getFirst();
double beta = alphaBetaTuple.getSecond();
double typicalRideDuration = directRideTIme * alpha + beta;
double typicalRideDistance = directDistance * alpha + beta;
double typicalRideDistance = (typicalRideDuration / directRideTIme) * directDistance;
double typicalWaitingTime = waitingTimeEstimator.estimateWaitTime(fromLinkId, toLinkId, departureTime);

double estimatedWaitingTime = typicalWaitingTime * waitingTimeDistributionGenerator.generateRandomValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public interface DistributionGenerator {
/**
* @return relative value to the typical ride duration
* @return relative value to the typical ride duration (i.e., generate a distribution around 1.0)
*/
double generateRandomValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ public class LogNormalDistributionGenerator implements DistributionGenerator {

private final double maxValue;

public LogNormalDistributionGenerator(Random random, double mu, double sigma) {
this.random = new Random();
public LogNormalDistributionGenerator(long seed, double mu, double sigma) {
this.random = new Random(seed);
this.mu = mu;
this.sigma = sigma;
this.minValue = 0.5;
this.maxValue = 3;
}

public LogNormalDistributionGenerator(Random random, double mu, double sigma, double minValue, double maxValue) {
this.random = random;
public LogNormalDistributionGenerator(long seed, double mu, double sigma, double minValue, double maxValue) {
this.random = new Random(seed);
this.mu = mu;
this.sigma = sigma;
this.minValue = minValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public NormalDistributionGenerator(long seed, double std, double minValue, doubl

@Override
public double generateRandomValue() {
double randomValue = random.nextGaussian() * std;
double randomValue = 1 + random.nextGaussian() * std;
randomValue = Math.min(maxValue, randomValue);
randomValue = Math.max(minValue, randomValue);
return randomValue;
Expand Down

0 comments on commit 3f58fbb

Please sign in to comment.