20 package org.matsim.lanes.data.consistency;
22 import java.util.Arrays;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.Iterator;
26 import java.util.LinkedList;
27 import java.util.List;
31 import org.apache.logging.log4j.LogManager;
32 import org.apache.logging.log4j.Logger;
55 this.lanes = laneDefs;
59 log.info(
"Checking consistency of lane data...");
60 List<Id<Link>> linksWithMalformedLanes =
new LinkedList<>();
63 linksWithMalformedLanes.add(l2l.getLinkId());
67 if (this.removeMalformed){
68 for (
Id<Link> linkId : linksWithMalformedLanes) {
70 log.info(
"remove lanes on link " + linkId);
73 log.info(
"checked consistency. Lanes on " + linksWithMalformedLanes.size() +
" links have been removed.");
79 log.error(
"No link found for lanesToLinkAssignment on link Id(linkIdRef): " + l2l.
getLinkId());
86 if (link.
getLength() < l.getStartsAtMeterFromLinkEnd()) {
87 log.error(
"Link Id " + link.
getId() +
" is shorter than an assigned lane with id " + l.getId());
97 Map<Id<Link>,
Id<Link>> mergedLinks =
new HashMap();
99 if(link.toString().contains(
"-")){
100 List<String> origLinks = Arrays.asList(link.toString().split(
"-"));
101 for (String origlink : origLinks){
111 if (lane.getToLinkIds()!=null) {
112 Set<Id<Link>> links2Replace =
new HashSet<>();
113 for (
Id<Link> toLink : lane.getToLinkIds()) {
114 if (mergedLinks.keySet().contains(toLink)) {
117 links2Replace.add(merged);
120 if (!links2Replace.isEmpty()) {
121 for (
Id<Link> temp : links2Replace) {
122 lane.addToLinkId(temp);
124 if (removeMalformed) {
125 Iterator<Id<Link>> toLinkIdIterator = lane.getToLinkIds().iterator();
126 while (toLinkIdIterator.hasNext()) {
127 Id<Link> toLinkId = toLinkIdIterator.next();
128 if (mergedLinks.keySet().contains(toLinkId)) {
129 toLinkIdIterator.remove();
130 log.info(
"Replace ToLinks of Lane Id: " + lane.getId() +
" on Link Id: " + l2l.
getLinkId() +
131 " - Replace ToLink Id: " + toLinkId.toString() +
" with " + mergedLinks.
get(toLinkId).toString());
148 log.info(
"Check if all OutLinks of junction with lanes is reachable...");
149 Map<Id<Node>,Set<Id<Link>>> junctionNodes =
new HashMap<>();
155 if (lane.getToLinkIds() != null) {
157 if (!junctionNodes.containsKey(jn)){
158 junctionNodes.put(jn,
new HashSet<
Id<Link>>());
160 for (
Id<Link> toLink :lane.getToLinkIds()){
161 if (!junctionNodes.get(jn).contains(toLink)) junctionNodes.get(jn).add(toLink);
167 Set<Id<Node>> checkedJn =
new HashSet<Id<Node>>();
168 for (
Id<Node> jn : junctionNodes.keySet()){
170 if (network.
getNodes().get(jn).getOutLinks().keySet().size()== junctionNodes.get(jn).size()){
183 if (!junctionNodes.get(jn).contains(outLink) && !checkedJn.contains(jn)){
184 log.warn(
"Link "+outLink.toString()+
" is not connected to the network - remove lanes from all inLinks of the corresponding junction:");
187 log.warn(
"\t\tRemove Lanes on Link "+inLink.toString());
202 if (lane.getToLaneIds() != null) {
203 Iterator<Id<Lane>> toLaneIdIterator = lane.getToLaneIds().iterator();
204 while (toLaneIdIterator.hasNext()){
205 Id<Lane> toLaneId = toLaneIdIterator.next();
206 if (! l2l.
getLanes().containsKey(toLaneId)){
207 log.error(
"Error: toLane not existing:");
208 log.error(
" Lane Id: " + lane.getId() +
" on Link Id: " + l2l.
getLinkId() +
209 " leads to Lane Id: " + toLaneId +
" that is not existing!");
212 if (this.removeMalformed) {
213 toLaneIdIterator.remove();
219 if (lane.getToLinkIds() != null){
220 Iterator<Id<Link>> toLinkIdIterator = lane.getToLinkIds().iterator();
221 while (toLinkIdIterator.hasNext()) {
222 Id<Link> toLinkId = toLinkIdIterator.next();
223 if (! this.network.
getLinks().containsKey(toLinkId)){
224 log.error(
"No link found in network for toLinkId " + toLinkId +
" of laneId " + lane.getId() +
" of link id " + l2l.
getLinkId());
227 if (this.removeMalformed) {
228 toLinkIdIterator.remove();
233 log.error(
"The given toLink " + toLinkId +
" is not reachable from lane " + lane.getId() +
" on link " + link.
getId());
236 if (this.removeMalformed) {
237 toLinkIdIterator.remove();
244 if ((lane.getToLaneIds() == null || lane.getToLaneIds().isEmpty())
245 && (lane.getToLinkIds() == null || lane.getToLinkIds().isEmpty())) {
246 log.error(
"The lane " + lane.getId() +
" on link " + l2l.
getLinkId() +
" does not lead to any lane nor link.");
253 log.error(
"The link " + link.
getId() +
" has lanes but only one outLink.");
static< T > Id< T > get(int index, final Class< T > type)
Map< Id< Node >, ? extends Node > getNodes()
SortedMap< Id< Link >, LanesToLinkAssignment > getLanesToLinkAssignments()
boolean isRemoveMalformed()
static Id< Link > createLinkId(final long key)
LanesConsistencyChecker(Network net, Lanes laneDefs)
void setRemoveMalformed(boolean removeMalformed)
Map< Id< Link >, ? extends Link > getLinks()
SortedMap< Id< Lane >, Lane > getLanes()
boolean areLanesOnLinkConsistent(LanesToLinkAssignment l2l)
Map< Id< Link >, ? extends Link > getOutLinks()