MATSIM
DefaultTurnAcceptanceLogic.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * DefaultTurnAcceptanceLogic.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22 package org.matsim.core.mobsim.qsim.qnetsimengine;
23 
24 import org.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
26 import org.matsim.api.core.v01.Id;
28 
35 public final class DefaultTurnAcceptanceLogic implements TurnAcceptanceLogic {
36  private static final Logger log = LogManager.getLogger( DefaultTurnAcceptanceLogic.class) ;
37 
39  @Override
40  public AcceptTurn isAcceptingTurn(Link currentLink, QLaneI currentLane, Id<Link> nextLinkId, QVehicle veh, QNetwork qNetwork, double now){
41  if (nextLinkId == null) {
42  log.error( "Agent has no or wrong route! agentId=" + veh.getDriver().getId()
43  + " currentLink=" + currentLink.getId().toString()
44  + ". The agent is removed from the simulation.");
45  return AcceptTurn.ABORT;
46  }
47  QLinkI nextQLink = qNetwork.getNetsimLinks().get(nextLinkId);
48 
49  if (nextQLink == null){
50  log.warn("The link id " + nextLinkId + " is not available in the simulation network, but vehicle " + veh.getId() +
51  " plans to travel on that link from link " + veh.getCurrentLink().getId());
52  return AcceptTurn.ABORT ;
53  }
54  if (currentLink.getToNode() != nextQLink.getLink().getFromNode()) {
55  log.warn("Cannot move vehicle " + veh.getId() + " from link " + currentLink.getId() + " to link " + nextQLink.getLink().getId());
56  return AcceptTurn.ABORT ;
57  }
58 // if ( !nextQLink.getLink().getAllowedModes().contains( veh.getDriver().getMode() ) ) {
59 // final String message = "The link with id " + nextLinkId + " does not allow the current mode, which is " + veh.getDriver().getMode();
60 // throw new RuntimeException( message ) ;
63 // // yyyy is rather nonsensical to get the mode from the driver, not from the vehicle. However, this seems to be
64 // // how it currently works: network links are defined for modes, not for vehicle types. kai, may'16
65 // }
66  // currently does not work, see MATSIM-533
67 
68  /* note: it cannot happen, that currentLane does not lead to nextLink (e.g. due to turn restrictions) because this is checked before:
69  * a vehicle only enters a lane when that lane leads to the next link. see QLinkLanesImpl.moveBufferToNextLane() and .chooseNextLane()
70  * tthunig, oct'17 */
71 
72  return AcceptTurn.GO ;
73  }
74 
75 }
Map< Id< Link >, QLinkI > getNetsimLinks()
Definition: QNetwork.java:84
AcceptTurn isAcceptingTurn(Link currentLink, QLaneI currentLane, Id< Link > nextLinkId, QVehicle veh, QNetwork qNetwork, double now)