Skip to content

Commit

Permalink
Merge branch 'master' into Drt-estimation-2
Browse files Browse the repository at this point in the history
  • Loading branch information
luchengqi7 authored Aug 9, 2024
2 parents f8f6a91 + 90c72f3 commit c2f0fa6
Show file tree
Hide file tree
Showing 22 changed files with 630 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ public static void runWithDefaults(Class<? extends MATSimApplication> clazz, Str

if (ApplicationUtils.isRunFromDesktop() && args.length == 0) {

System.setProperty("MATSIM_GUI_DESKTOP", "true");

if (defaultArgs.length > 0) {
String value = String.join(ARGS_DELIMITER, defaultArgs);
System.setProperty("MATSIM_GUI_ARGS", value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public Integer call() throws Exception {

Gui gui = f.get();

// Set the current working directory to be used in the gui, when run from the command line
// If the gui is run from desktop, the working directory is not overwritten

// Assumption is that starting something from command line, the user expects that the working directory remains the same
if (!System.getProperty("MATSIM_GUI_DESKTOP", "false").equals("true"))
gui.setWorkingDirectory(new File(""));

while (gui.isShowing())
Thread.sleep(250);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.matsim.application.analysis.noise;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.locationtech.jts.geom.Envelope;
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.Scenario;
Expand All @@ -8,6 +10,7 @@
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.options.InputOptions;
import org.matsim.application.options.OutputOptions;
import org.matsim.application.options.SampleOptions;
import org.matsim.application.options.ShpOptions;
import org.matsim.contrib.noise.NoiseConfigGroup;
import org.matsim.contrib.noise.NoiseOfflineCalculation;
Expand Down Expand Up @@ -38,6 +41,8 @@
)
public class NoiseAnalysis implements MATSimAppCommand {

private static final Logger log = LogManager.getLogger(NoiseAnalysis.class);

@CommandLine.Mixin
private final InputOptions input = InputOptions.ofCommand(NoiseAnalysis.class);
@CommandLine.Mixin
Expand All @@ -46,7 +51,11 @@ public class NoiseAnalysis implements MATSimAppCommand {
@CommandLine.Mixin
private final ShpOptions shp = new ShpOptions();

@CommandLine.Option(names = "--consider-activities", split = ",", description = "Considered activities for noise calculation", defaultValue = "h,w,home,work")
@CommandLine.Mixin
private final SampleOptions sampleOptions = new SampleOptions();

@CommandLine.Option(names = "--consider-activities", split = ",", description = "Considered activities for noise calculation." +
" Use asterisk ('*') for acttype prefixes, if all such acts shall be considered.", defaultValue = "h,w,home*,work*")
private Set<String> considerActivities;

@CommandLine.Option(names = "--noise-barrier", description = "Path to the noise barrier File", defaultValue = "")
Expand Down Expand Up @@ -88,6 +97,16 @@ public Integer call() throws Exception {
noiseParameters.setNoiseBarriersFilePath(noiseBarrierFile);
}

if(! sampleOptions.isSet() && noiseParameters.getScaleFactor() == 1d){
log.warn("You didn't provide the simulation sample size via command line option --sample-size! This means, noise damages are not scaled!!!");
} else if (noiseParameters.getScaleFactor() == 1d){
if (sampleOptions.getSample() == 1d){
log.warn("Be aware that the noise output is not scaled. This might be unintended. If so, assure to provide the sample size via command line option --sample-size, in the SimWrapperConfigGroup," +
"or provide the scaleFactor (the inverse of the sample size) in the NoiseConfigGroup!!!");
}
noiseParameters.setScaleFactor(sampleOptions.getUpscaleFactor());
}

Scenario scenario = ScenarioUtils.loadScenario(config);

String outputFilePath = output.getPath().getParent() == null ? "." : output.getPath().getParent().toString();
Expand Down Expand Up @@ -119,6 +138,7 @@ private Config prepareConfig() {
config.facilities().setInputFile(null);
config.eventsManager().setNumberOfThreads(null);
config.eventsManager().setEstimatedNumberOfEvents(null);
//ts, aug '24: not sure if and why we need to set 1 thread
config.global().setNumberOfThreads(1);

return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.graphhopper.jsprit.io.algorithm.AlgorithmConfigXmlReader;
import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithms;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.roadpricing.RoadPricingScheme;
import org.matsim.core.replanning.ReplanningContext;
import org.matsim.core.replanning.modules.GenericPlanStrategyModule;
import org.matsim.core.router.util.TravelTime;
Expand All @@ -58,7 +59,7 @@ class CarrierVehicleReRouter implements GenericPlanStrategyModule<CarrierPlan>{

private final VehicleRoutingActivityCosts vehicleRoutingActivityCosts;

public CarrierVehicleReRouter( Network network, CarrierVehicleTypes vehicleTypes, TravelTime travelTimes, String vrpAlgoConfigFile, VehicleTypeDependentRoadPricingCalculator roadPricing ) {
public CarrierVehicleReRouter( Network network, CarrierVehicleTypes vehicleTypes, TravelTime travelTimes, String vrpAlgoConfigFile, RoadPricingScheme roadPricing ) {
this.network = network;
vehicleRoutingTransportCosts = getNetworkBasedTransportCosts(network,vehicleTypes,travelTimes,roadPricing);
vehicleRoutingActivityCosts = new VehicleRoutingActivityCosts() {
Expand Down Expand Up @@ -146,7 +147,7 @@ public void handlePlan(CarrierPlan carrierPlan) {

}

private NetworkBasedTransportCosts getNetworkBasedTransportCosts(Network network, CarrierVehicleTypes vehicleTypes, TravelTime travelTimes, VehicleTypeDependentRoadPricingCalculator roadPricing) {
private NetworkBasedTransportCosts getNetworkBasedTransportCosts(Network network, CarrierVehicleTypes vehicleTypes, TravelTime travelTimes, RoadPricingScheme roadPricing ) {
//******
//Define transport-costs
//******
Expand All @@ -157,7 +158,7 @@ private NetworkBasedTransportCosts getNetworkBasedTransportCosts(Network network
//sets time-dependent travelTimes
tpcostsBuilder.setTravelTime(travelTimes);

if(roadPricing != null) tpcostsBuilder.setRoadPricingCalculator(roadPricing);
if(roadPricing != null) tpcostsBuilder.setRoadPricingScheme(roadPricing );

//sets time-slice to build time-dependent tpcosts and travelTime matrices
tpcostsBuilder.setTimeSliceWidth(900);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.population.Person;
import org.matsim.contrib.roadpricing.RoadPricingScheme;
import org.matsim.contrib.roadpricing.RoadPricingSchemeImpl;
import org.matsim.core.router.speedy.SpeedyALTFactory;
import org.matsim.core.router.util.LeastCostPathCalculator;
import org.matsim.core.router.util.LeastCostPathCalculator.Path;
Expand Down Expand Up @@ -83,6 +85,8 @@
*/
public class NetworkBasedTransportCosts implements VRPTransportCosts {

private final RoadPricingScheme roadPricingScheme;

public interface InternalLeastCostPathCalculatorListener {

void startCalculation(long routerId);
Expand Down Expand Up @@ -316,27 +320,34 @@ private static class VehicleTypeVarCosts {
*/
static class VehicleTransportCostsIncludingToll implements TravelDisutility {

// private static Logger logger = LogManager.getLogger(VehicleTransportCostsIncludingToll.class);

private final TravelDisutility baseTransportDisutility;

private final VehicleTypeDependentRoadPricingCalculator vehicleTypeDependentPricingCalculator;
private final RoadPricingScheme roadPricingScheme;

public VehicleTransportCostsIncludingToll(TravelDisutility baseTransportDisutility,
VehicleTypeDependentRoadPricingCalculator vehicleTypeDependentPricingCalculator) {
public VehicleTransportCostsIncludingToll( TravelDisutility baseTransportDisutility,
RoadPricingScheme roadPricingScheme ) {
super();
this.baseTransportDisutility = baseTransportDisutility;
this.vehicleTypeDependentPricingCalculator = vehicleTypeDependentPricingCalculator;
// System.out.println("huuuuuuuuuuuuuuuuuuuu - initialize transport costs with toll");
this.roadPricingScheme = roadPricingScheme;
}

@Override
public double getLinkTravelDisutility(Link link, double time, Person person,
org.matsim.vehicles.Vehicle vehicle) {
double costs = baseTransportDisutility.getLinkTravelDisutility(link, time, person, vehicle);
Id<org.matsim.vehicles.VehicleType> typeId = vehicle.getType().getId();
double toll = vehicleTypeDependentPricingCalculator.getTollAmount(typeId, link, time);
// System.out.println("huuuuuuuuuuuuuuuuuuuu - paid toll");

RoadPricingSchemeImpl.Cost costInfo;
if (person == null) {
costInfo = roadPricingScheme.getLinkCostInfo( link.getId(), time, null, vehicle.getId() );
} else {
costInfo = roadPricingScheme.getLinkCostInfo( link.getId(), time, person.getId(), vehicle.getId() );
}

double toll = 0.;
if ( costInfo != null ){
toll = costInfo.amount;
}
return costs + toll;
}

Expand Down Expand Up @@ -377,7 +388,8 @@ public static Builder newInstance(Network network) {

private LeastCostPathCalculatorFactory leastCostPathCalculatorFactory = (network, travelCosts, travelTimes) -> new SpeedyALTFactory().createPathCalculator(network, travelCosts, travelTime);

private VehicleTypeDependentRoadPricingCalculator roadPricingCalculator = new VehicleTypeDependentRoadPricingCalculator();
// private VehicleTypeDependentRoadPricingCalculator roadPricingScheme = new VehicleTypeDependentRoadPricingCalculator();
private RoadPricingScheme roadPricingScheme;

private boolean withToll = false;

Expand All @@ -393,7 +405,7 @@ public static Builder newInstance(Network network) {
* Creates the builder requiring {@link Network} and a collection of
* {@link VehicleType}.
*
* @param network
* @param network the MATSim network
* @param vehicleTypes must be all vehicleTypes and their assigned
* costInformation in the system.
*/
Expand All @@ -414,7 +426,7 @@ private void retrieveTypeSpecificCosts(Collection<VehicleType> vehicleTypes) {
* Sets the travelTime. By default, travelTime is based on
* <code>link.getFreespeed();</code>.
*
* @param travelTime
* @param travelTime the travelTime to set
* @return this builder
*/
public Builder setTravelTime(TravelTime travelTime) {
Expand Down Expand Up @@ -463,7 +475,7 @@ public Builder setFIFO(boolean isFIFO) {
* <p>
* By default, it use {@link SpeedyALTFactory}
*
* @param {@link {@link LeastCostPathCalculatorFactory}
* @param leastCostPathCalcFactory {@link LeastCostPathCalculatorFactory}
* @return this builder
*/
public Builder setThreadSafeLeastCostPathCalculatorFactory(
Expand All @@ -472,9 +484,9 @@ public Builder setThreadSafeLeastCostPathCalculatorFactory(
return this;
}

public Builder setRoadPricingCalculator(VehicleTypeDependentRoadPricingCalculator calculator) {
public Builder setRoadPricingScheme( RoadPricingScheme roadPricingScheme) {
withToll = true;
this.roadPricingCalculator = calculator;
this.roadPricingScheme = roadPricingScheme;
return this;
}

Expand All @@ -501,7 +513,7 @@ public NetworkBasedTransportCosts build() {
baseDisutility = new BaseVehicleTransportCosts(typeSpecificCosts, travelTime);
}
if (withToll) {
finalDisutility = new VehicleTransportCostsIncludingToll(baseDisutility, roadPricingCalculator);
finalDisutility = new VehicleTransportCostsIncludingToll(baseDisutility, roadPricingScheme );
} else
finalDisutility = baseDisutility;
return new NetworkBasedTransportCosts(this);
Expand All @@ -511,10 +523,10 @@ public NetworkBasedTransportCosts build() {
* Adds type-specific costs. If typeId already exists, existing entry is
* overwritten.
*
* @param typeId
* @param fix
* @param perSecond
* @param perMeter
* @param typeId the vehicleType-id as String
* @param fix fix costs for the vehicle
* @param perSecond variable costs per second
* @param perMeter variable costs per meter
*/
public void addVehicleTypeSpecificCosts(String typeId, double fix, double perSecond, double perMeter) {
typeSpecificCosts.put(typeId, new VehicleTypeVarCosts(perMeter, perSecond));
Expand Down Expand Up @@ -551,8 +563,6 @@ public void addVehicleTypeSpecificCosts(String typeId, double fix, double perSec

private final Map<String, org.matsim.vehicles.Vehicle> matsimVehicles = new HashMap<>();

private final VehicleTypeDependentRoadPricingCalculator roadPricingCalc;

/**
* by default sets the {@link SpeedyALTFactory}
*/
Expand All @@ -568,7 +578,7 @@ private NetworkBasedTransportCosts(Builder builder) {
this.travelTime = builder.travelTime;
this.network = builder.network;
this.leastCostPathCalculatorFactory = builder.leastCostPathCalculatorFactory;
this.roadPricingCalc = builder.roadPricingCalculator;
this.roadPricingScheme = builder.roadPricingScheme;
this.timeSliceWidth = builder.timeSliceWidth;
this.defaultTypeId = builder.defaultTypeId;
this.ttMemorizedCounter = new Counter("#TransportCostValues cached ");
Expand All @@ -585,7 +595,7 @@ private NetworkBasedTransportCosts(Builder builder) {
* cached travel-time. If not, it computes and caches new values with the
* leastCostPathCalc defined in here.
*
* @Throws {@link IllegalStateException} if vehicle is null
* @exception IllegalStateException if vehicle is null
*/
@Override
public double getTransportTime(Location fromId, Location toId, double departureTime, Driver driver,
Expand Down Expand Up @@ -666,7 +676,7 @@ private void informStartCalc() {
* cached travel-cost value. If not, it computes and caches new values with the
* leastCostPathCalc defined in here.
*
* @Throws {@link IllegalStateException} if vehicle is null
* @exception IllegalStateException if vehicle is null
*/
@Override
public double getTransportCost(Location fromId, Location toId, double departureTime, Driver driver,
Expand Down Expand Up @@ -734,7 +744,7 @@ public double getTransportCost(Location fromId, Location toId, double departureT
* cached distance. If not, it computes and caches new values with the
* leastCostPathCalc defined in here.
*
* @Throws {@link IllegalStateException} if vehicle is null
* @exception IllegalStateException if vehicle is null
*/
@Override
public double getDistance(Location fromId, Location toId, double departureTime, Vehicle vehicle) {
Expand Down Expand Up @@ -799,7 +809,7 @@ public Collection<InternalLeastCostPathCalculatorListener> getInternalListeners(
* This is a rather bad approximation. If you require this, you should implement
* another {@link VehicleRoutingTransportCosts}
*
* @Throws {@link IllegalStateException} if vehicle is null
* @exception IllegalStateException if vehicle is null
*/
@Override
public double getBackwardTransportCost(Location fromId, Location toId, double arrivalTime, Driver driver,
Expand All @@ -815,7 +825,7 @@ public double getBackwardTransportCost(Location fromId, Location toId, double ar
* This is a rather bad approximation. If you require this, you should implement
* another {@link VehicleRoutingTransportCosts}.
*
* @Throws {@link IllegalStateException} if vehicle is null
* @exception IllegalStateException if vehicle is null
*/
@Override
public double getBackwardTransportTime(Location fromId, Location toId, double arrivalTime, Driver driver,
Expand Down Expand Up @@ -862,7 +872,7 @@ private int getTimeSlice(double time) {
/**
* Gets the network the calculation is based on.
*
* @return
* @return the network
*/
public Network getNetwork() {
return network;
Expand All @@ -877,13 +887,4 @@ public TravelTime getTravelTime() {
return travelTime;
}

/**
* Gets the {@link VehicleTypeDependentRoadPricingCalculator}
*
* @return {@link VehicleTypeDependentRoadPricingCalculator}
*/
public VehicleTypeDependentRoadPricingCalculator getRoadPricingCalculator() {
return roadPricingCalc;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @author stefan schröder
*
*/
@Deprecated // use RoadPricingScheme
public class VehicleTypeDependentRoadPricingCalculator {

interface TollCalculator {
Expand Down
Loading

0 comments on commit c2f0fa6

Please sign in to comment.