diff --git a/src/main/java/org/matsim/evacuationgui/scenariogenerator/EvacuationNetworkGenerator.java b/src/main/java/org/matsim/evacuationgui/scenariogenerator/EvacuationNetworkGenerator.java
index 5909498..1615248 100644
--- a/src/main/java/org/matsim/evacuationgui/scenariogenerator/EvacuationNetworkGenerator.java
+++ b/src/main/java/org/matsim/evacuationgui/scenariogenerator/EvacuationNetworkGenerator.java
@@ -19,9 +19,7 @@
* *********************************************************************** */
package org.matsim.evacuationgui.scenariogenerator;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
+import java.util.*;
import org.apache.log4j.Logger;
import org.locationtech.jts.geom.Coordinate;
@@ -36,6 +34,7 @@
import org.matsim.api.core.v01.network.Node;
import org.matsim.core.network.algorithms.NetworkCleaner;
import org.matsim.core.utils.geometry.geotools.MGC;
+import org.opengis.feature.simple.SimpleFeature;
/**
@@ -47,18 +46,26 @@ public class EvacuationNetworkGenerator {
private static final Logger log = Logger.getLogger(EvacuationNetworkGenerator.class);
- private final Geometry evacuationArea;
- private final Network network;
+ private Geometry evacuationArea;
+
+ private Network network;
private final HashSet redundantLinks = new HashSet();
private final HashSet safeNodes = new HashSet();
private final HashSet redundantNodes = new HashSet();
- private final Id safeNodeAId;
+ private Id safeNodeAId;
+
+ private Id safeNodeBId;
- private final Id safeNodeBId;
+ private final Collection> safeNodeBIds = new ArrayList<>();
+
+ public Collection> getSafeNodeAIds() {
+ return safeNodeAIds;
+ }
- private final Id safeLinkId;
+ private final Collection> safeNodeAIds = new ArrayList<>();
+ private Id safeLinkId;
public EvacuationNetworkGenerator(Scenario sc, Geometry evavcuationArea, Id safeLinkId) {
this.evacuationArea = evavcuationArea;//.buffer(4000);
@@ -67,7 +74,6 @@ public EvacuationNetworkGenerator(Scenario sc, Geometry evavcuationArea, Id, Geometry> safePoints) {
+ log.info("generating evacuation net ...");
+ log.info("pre-cleaning network");
+ preClean();
+ log.info("classifing nodes");
+ classifyNodesAndLinks();
+ log.info("creating evacuation nodes and links");
+ createEvacuationNodsAndLinks(safePoints);
+ log.info("removing links and nodes that are outside the evacuation area");
+ cleanUpNetwork();
+ log.info("done.");
+ }
+
private void preClean() {
log.info("Pre-cleanup #nodes: " + this.network.getNodes().size());
List rm = new ArrayList<>();
@@ -112,8 +131,10 @@ private void createEvacuationNodsAndLinks() {
Node safeNodeA = this.network.getFactory().createNode(this.safeNodeAId, safeCoord1);
this.network.addNode(safeNodeA);
+ this.safeNodeAIds.add(this.safeNodeAId);
Node safeNodeB = this.network.getFactory().createNode(this.safeNodeBId, safeCoord2);
this.network.addNode(safeNodeB);
+ this.safeNodeBIds.add(this.safeNodeBId);
double capacity = 1000000.;
Link l = this.network.getFactory().createLink(this.safeLinkId, safeNodeA, safeNodeB);
@@ -139,6 +160,51 @@ private void createEvacuationNodsAndLinks() {
}
}
+ private void createEvacuationNodsAndLinks(Map, Geometry> safePoints) {
+ for (Map.Entry, Geometry> safePoint: safePoints.entrySet()) {
+
+ Coordinate cc1 = safePoint.getValue().getCoordinate();
+ Coord safeCoord1 = MGC.coordinate2Coord(cc1);
+
+ Coordinate cc2 = safePoint.getValue().getCoordinate();
+ Coord safeCoord2 = MGC.coordinate2Coord(cc2);
+
+ this.safeNodeAId = Id.createNodeId("en1_" + safePoint.getValue().getCoordinate());
+ this.safeNodeBId = Id.createNodeId("en2_" + safePoint.getValue().getCoordinate());
+
+ Node safeNodeA = this.network.getFactory().createNode(this.safeNodeAId, safeCoord1);
+ this.network.addNode(safeNodeA);
+ this.safeNodeAIds.add(this.safeNodeAId);
+ Node safeNodeB = this.network.getFactory().createNode(this.safeNodeBId, safeCoord2);
+ this.network.addNode(safeNodeB);
+ this.safeNodeBIds.add(safeNodeBId);
+
+ double capacity = 1000000.;
+ this.safeLinkId = safePoint.getKey();
+ Link l = this.network.getFactory().createLink(this.safeLinkId, safeNodeA, safeNodeB);
+ l.setLength(10);
+ l.setFreespeed(100000);
+ l.setCapacity(capacity);
+ l.setNumberOfLanes(100);
+ this.network.addLink(l);
+
+ int linkId = 1;
+ for (Node node : this.network.getNodes().values()) {
+ Id nodeId = node.getId();
+ // && !nodeId.equals(this.safeNodeAId) && !nodeId.equals(this.safeNodeBId)) {
+ if (this.safeNodes.contains(node) && !nodeId.equals(this.safeNodeAId) && !nodeId.equals(this.safeNodeBId)) {
+ String sLinkID = "el_" + linkId++ + "_" + this.safeLinkId;
+ Link l2 = this.network.getFactory().createLink(Id.create(sLinkID, Link.class), node, safeNodeA);
+ l2.setLength(10);
+ l2.setFreespeed(100000);
+ l2.setCapacity(capacity);
+ l2.setNumberOfLanes(1);
+ this.network.addLink(l2);
+ }
+ }
+ }
+ }
+
private void classifyNodesAndLinks() {
for (Node node : this.network.getNodes().values()) {
@@ -230,12 +296,14 @@ protected void cleanUpNetwork() {
log.info("adding dummy links");
List dummies = new ArrayList();
int dCnt = 0;
- for (Node n : this.network.getNodes().values()) {
- if (!this.safeNodes.contains(n) && !this.redundantNodes.contains(n)) {
- NetworkFactory fac = this.network.getFactory();
- Link l = fac.createLink(Id.create("dummy" + dCnt++, Link.class), this.network.getNodes().get(this.safeNodeBId), n);
- this.network.addLink(l);
- dummies.add(l);
+ for (Id safeNodeBIdFromCollection: this.safeNodeBIds) {
+ for (Node n : this.network.getNodes().values()) {
+ if (!this.safeNodes.contains(n) && !this.redundantNodes.contains(n)) {
+ NetworkFactory fac = this.network.getFactory();
+ Link l = fac.createLink(Id.create("dummy" + dCnt++, Link.class), this.network.getNodes().get(safeNodeBIdFromCollection), n);
+ this.network.addLink(l);
+ dummies.add(l);
+ }
}
}
new NetworkCleaner().run(this.network);