Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle TransitQVehicles in SituationalFlowEfficiencyImpact examples #1339

Merged
merged 1 commit into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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