Skip to content

Commit

Permalink
Merge pull request #1339 from matsim-org/situationalImpacts
Browse files Browse the repository at this point in the history
handle TransitQVehicles in SituationalFlowEfficiencyImpact examples
  • Loading branch information
mergify[bot] authored Jan 11, 2021
2 parents 619187f + 49f5a0d commit 2c63626
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.base.Preconditions;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.core.mobsim.qsim.pt.TransitQVehicle;
import org.matsim.core.mobsim.qsim.qnetsimengine.QVehicle;
import org.matsim.lanes.Lane;
import org.matsim.vehicles.VehicleType;
Expand All @@ -46,6 +47,10 @@ public AVFlowEfficiencyImpact(Set<VehicleType> autonomousVehicleTypes) {

@Override
public double calculateFlowEfficiency(QVehicle qVehicle, @Nullable QVehicle previousQVehicle, @Nullable Double timeGapToPreviousVeh, Link link, Id<Lane> laneId) {

// currently, we can not call chooseNextLinkId for TransitQVehicles because no link Id caching is performed!
if(qVehicle instanceof TransitQVehicle) { return 1;}

Id<Link> nextLinkId = qVehicle.getDriver().chooseNextLinkId();
if(nextLinkId != null && //vehicle is not arriving
this.autonomousVehicleTypes.contains(qVehicle.getVehicle().getType())){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.base.Preconditions;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.core.mobsim.qsim.pt.TransitQVehicle;
import org.matsim.core.mobsim.qsim.qnetsimengine.QVehicle;
import org.matsim.lanes.Lane;
import org.matsim.vehicles.VehicleType;
Expand Down Expand Up @@ -56,6 +57,9 @@ public BunchingFlowEfficencyImpact(Set<VehicleType> bunchableVehicleTypes, doubl
@Override
public double calculateFlowEfficiency(QVehicle qVehicle, @Nullable QVehicle previousQVehicle, @Nullable Double timeGapToPreviousVeh, Link link, Id<Lane> laneId) {

// currently, we can not call chooseNextLinkId for TransitQVehicles because no link Id caching is performed!
if(qVehicle instanceof TransitQVehicle) { return 1;}

//querying the next link id forces the driver to take it (diversion can only take place after next link)
//this might change drt performance
Id<Link> nextLinkId = qVehicle.getDriver().chooseNextLinkId();
Expand All @@ -65,21 +69,17 @@ public double calculateFlowEfficiency(QVehicle qVehicle, @Nullable QVehicle prev
double flowCapPerSecond = link.getFlowCapacityPerSec();
double standardMinTimeGap = 1 / flowCapPerSecond;

if(timeGapToPreviousVeh < standardMinTimeGap * toleratedTimeGapDeviationFactor &&
this.bunchableVehicleTypes.contains(qVehicle.getVehicle().getType()) &&
this.bunchableVehicleTypes.contains(previousQVehicle.getVehicle().getType())){
if(timeGapToPreviousVeh < standardMinTimeGap * toleratedTimeGapDeviationFactor && //is the time gap between the two vehicles small enough?
this.bunchableVehicleTypes.contains(qVehicle.getVehicle().getType()) && //are the two vehicles able to bunch? (i.e. can they communicate or whatever..)
this.bunchableVehicleTypes.contains(previousQVehicle.getVehicle().getType()) &&
previousQVehicle.getCurrentLink().getId().equals(nextLinkId)){ // do they drive in the same direction?

if(link.getAttributes().getAttribute("turns") != null){
Map<String, String> turns = (Map<String, String>) link.getAttributes().getAttribute("turns");
String direction = turns.get(nextLinkId.toString());
Preconditions.checkNotNull(direction, "could not find toLinkId=" + nextLinkId + " in turns map of link " + link);

if(direction.equals(TurnDirection.STRAIGHT.toString())){ //bunching only in straight direction
/*careful: if you attend to allow bunching factors for turns, be aware that you only know about the direction of the currently investigated qVehicle
* and not about the direction of the previous vehicle!
* you would have to make assumptions about timeGapToPreviousVeh being small (what actually is already incorporated above) and call previousQVehicle.getCurrentLink()
* to query turns map and find out in which direction the previous vehicle drove.
*/
return impact;
}
} else {
Expand Down

0 comments on commit 2c63626

Please sign in to comment.