Commit 3f09f346 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

add migration incident to delete an element inside an array, improve the code...

add migration incident to delete an element inside an array, improve the code of the Graph/Tree-class
parent a1bb230c
......@@ -54,7 +54,7 @@
"clazz" : "PedestrianEvacuationTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -54,7 +54,7 @@
"clazz" : "PedestrianEvacuationTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -54,7 +54,7 @@
"clazz" : "PedestrianEvacuationTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -74,7 +74,7 @@
"clazz" : "PedestrianDensityProcessor"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -54,7 +54,7 @@
"clazz" : "PedestrianEvacuationTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -54,7 +54,7 @@
"clazz" : "PedestrianEvacuationTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -54,7 +54,7 @@
"clazz" : "PedestrianEvacuationTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -54,7 +54,7 @@
"clazz" : "PedestrianEvacuationTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -24,7 +24,7 @@
"clazz" : "PedestrianEvacuationTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......@@ -127,7 +127,7 @@
},
"spawnDelay" : 30.0,
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"distributionParameters" : [ 30.0 ],
"spawnNumber" : 1,
"startTime" : 0.0,
"endTime" : 1200.0,
......
......@@ -24,7 +24,7 @@
"clazz" : "PedestrianEvacuationTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......@@ -127,7 +127,7 @@
},
"spawnDelay" : 30.0,
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"distributionParameters" : [ 30.0 ],
"spawnNumber" : 1,
"startTime" : 0.0,
"endTime" : 1200.0,
......
......@@ -5,7 +5,7 @@
"topographyhash" : "fb9fd241012e5f74dfda3c5a6d2111de0b32c820",
"attributeshash" : "2f8bd261d0d5d20fcb2da3a6c142c3074aeeef89",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......@@ -210,7 +210,7 @@
},
"spawnDelay" : 10.0,
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"distributionParameters" : [ 10.0 ],
"spawnNumber" : 1,
"startTime" : 0.0,
"endTime" : 200.0,
......
......@@ -5,7 +5,7 @@
"topographyhash" : "b6ea738480b46cdbb26b3577a1db90876966ff5a",
"attributeshash" : "2f8bd261d0d5d20fcb2da3a6c142c3074aeeef89",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......@@ -210,7 +210,7 @@
},
"spawnDelay" : 10.0,
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"distributionParameters" : [ 10.0 ],
"spawnNumber" : 1,
"startTime" : 0.0,
"endTime" : 200.0,
......
......@@ -5,7 +5,7 @@
"topographyhash" : "2402d27f7a7b96b42ad35cac9b4f80a145e21e0c",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "84b67fe358a612607b1ede7c939c99bd99eb0400",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "4a9809f90720e63e4b0d8f999533eee9356fee59",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "37529a86b42cd73ca531388bdc0963836afe76a9",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "48c9e6576c3f61468d79d9fd3726942f0ba63fe2",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "3bbeaedc57a072d8c68ef54329dd4a35749f6824",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "f2d7f73e8409ac97aa6b3ab539d529284cecda7f",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "97e82c32e10351e4f71c4a5070ca5d018ab21b21",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "ea68469e931a0aa2d0e51891d0db0ac9d45e6148",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "5d8f3904564d818d63e6606a6d9e63a94b003c2c",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "a187a4ba4f61d0b493a8604088170df24e623443",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "996ac68510f1e23fc548f149ee022f2ed87b8da0",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "6f687cc2f3735ec605dfbb367a667342d0f60088",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "c774f23a010f14d5fa37a5bb5e87f43e0cefcf4a",
"attributeshash" : "b906982adb598e93b86c6a26153f04ed0c8e4753",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "bcf2c6fd48ac2381bd9b5a24f65b99c7a90dcf3f",
"attributeshash" : "2a80e801318ee7a6bcaab6f940f91597d1030037",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "e68fbf252e8faa33f68560e6477136ac16d7ef64",
"attributeshash" : "2a80e801318ee7a6bcaab6f940f91597d1030037",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "eeba5fbe296b72d9dca240ba9cc04bc924bacce8",
"attributeshash" : "b7dda81628372d30f2bfb15d15bfcdd22d2b0bad",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -54,7 +54,7 @@
"clazz" : "PedestrianWaitingTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -54,7 +54,7 @@
"clazz" : "PedestrianWaitingTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -24,7 +24,7 @@
"clazz" : "PedestrianEvacuationTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......@@ -127,7 +127,7 @@
},
"spawnDelay" : 20.0,
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"distributionParameters" : [ 20.0 ],
"spawnNumber" : 10,
"startTime" : 0.0,
"endTime" : 100.0,
......
......@@ -5,7 +5,7 @@
"topographyhash" : "f453b225d913e3eea79894cca2df23ceefbc4225",
"attributeshash" : "7c5d3dedf5a0d0a8d1d6291b952850b11d5f5f3c",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "3b00f24d1aecc13094fb4631ad6822983783c7e2",
"attributeshash" : "2f8bd261d0d5d20fcb2da3a6c142c3074aeeef89",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "08966b2db7102aef1cd3d85fe56e9f99a9e14b8e",
"attributeshash" : "2f8bd261d0d5d20fcb2da3a6c142c3074aeeef89",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -16,7 +16,7 @@
"clazz" : "PedestrianLastPositionProcessor"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "388a836ae85a814e6f84d34f6d2509d6d319a1aa",
"attributeshash" : "2a80e801318ee7a6bcaab6f940f91597d1030037",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -106,7 +106,7 @@
"clazz" : "PedestrianEvacuationTimeTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -128,7 +128,7 @@
"clazz" : "PedestrianDensityTest"
}
} ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
......@@ -5,7 +5,7 @@
"topographyhash" : "73a4ebc0c8f6e4a3ed99e51aff7868939c441e4c",
"attributeshash" : "94ceb2a6cec8ec64afacacaf9bf2cb89fa382423",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......@@ -140,7 +140,7 @@
},
"spawnDelay" : 4.0,
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"distributionParameters" : [ 4.0 ],
"spawnNumber" : 15,
"startTime" : 0.0,
"endTime" : 36.0,
......
......@@ -5,7 +5,7 @@
"topographyhash" : "d4f8babf2f7826c11f933468513f6ebb9588c335",
"attributeshash" : "94ceb2a6cec8ec64afacacaf9bf2cb89fa382423",
"processWriters" : [ ],
"vadere" : {
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesPotentialCompact" : {
......
0.1
\ No newline at end of file
0.2
\ No newline at end of file
package org.vadere.simulator.projects.migration;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.*;
import org.vadere.simulator.projects.migration.incidents.Incident;
public class Graph {
private final Node root;
private Node candidate;
public Graph(JsonNode rootValue) {
root = new Node(null, "ROOT", rootValue);
recursiveBuild(root);
}
public void recursiveBuild(Node parent) {
Iterator<Map.Entry<String, JsonNode>> it = parent.jsonNode.fields();
while (it.hasNext()) {
Map.Entry<String, JsonNode> entry = it.next();
Node child = new Node(parent, entry.getKey(), entry.getValue());
parent.addChild(child);
recursiveBuild(child);
}
}
public String pathToString(List<String> path) {
if (path.size() > 0) {
StringBuilder sb = new StringBuilder();
path.forEach(node -> sb.append(" > " + node));
return "[" + sb.toString().substring(3) + "]";
}
return "[]";
}
private List<String> getPathToNode(Node node) {
List<String> path = new ArrayList<>();
while (node != root) {
path.add(node.key);
node = node.parent;
}
Collections.reverse(path);
return path;
}
public boolean pathExists(List<String> path) {
return getNodeByPath(path) != null;
}
public void deleteUnrecognizedField(String parentKey, String childKey, StringBuilder log, Incident caller)
throws MigrationException {
recursiveScan(root, parentKey, childKey, caller);
log.append("\t- delete unrecognized node [" + childKey + "] under node "
+ pathToString(getPathToNode(candidate.parent)) + "\n");
candidate.delete();
candidate = null;
}
public void enforceIntegerValue(String parentKey, String childKey, StringBuilder log, Incident caller)
throws MigrationException {
recursiveScan(root, parentKey, childKey, caller);
log.append("\t- enforce integer-value (" + candidate.jsonNode.asInt() + " instead of " + candidate.jsonNode
+ ") of node [" + childKey + "] under node " + pathToString(getPathToNode(candidate.parent)) + "\n");
candidate.enforceIntegerValue();
candidate = null;
}
public void recursiveScan(Node parent, String parentKey, String childKey, Incident caller)
throws MigrationException { // the alternative would be to collect all leaves and check their parents
if (parent.key.equals(parentKey) && parent.children.keySet().contains(childKey)) { // = a path was found that ends on [childKey] and has [parentKey] as parent
if (candidate == null) {
candidate = parent.children.get(childKey);
} else {
throw new MigrationException(caller, "can't automatically delete the unrecognized field [" + childKey
+ "] because more than one graph-path ends with [" + parentKey + " > " + childKey + "]");
}
}
for (String child : parent.children.keySet())
recursiveScan(parent.children.get(child), parentKey, childKey, caller);
}
public boolean keyExistsInArray(List<String> pathToArray, String oldName) {
Node arrayNode = getNodeByPath(pathToArray);
if (arrayNode == null)
return false;
for (JsonNode entry : arrayNode.jsonNode)
if (entry.has(oldName))
return true;
return false;
}
public Node getNodeByPath(List<String> path) {
if (path.isEmpty()) {
return root;
}
Node descend = root;
int index = 0;
while (descend != null && index < path.size())
descend = descend.children.get(path.get(index++));
return descend;
}
public void relocateNode(List<String> fullOldPath, List<String> newPath) {
Node node = getNodeByPath(fullOldPath);
Node newParent = getNodeByPath(newPath);
node.relocateTo(newParent);
}
public void deleteNode(List<String> path) {
getNodeByPath(path).delete();
}
public void renameNode(List<String> path, String newName) {
getNodeByPath(path).renameTo(newName);
}
public void renameKeyOccurrencesInArray(List<String> pathToArray, String oldName, String newName) {
for (JsonNode entry : getNodeByPath(pathToArray).jsonNode) {
if (entry.has(oldName)) {
JsonNode value = entry.get(oldName);
((ObjectNode) entry).remove(oldName);
((ObjectNode) entry).set(newName, value); // will be added as last element, not same index as oldName was unfortunately
}
}
}
public Set<String> getKeysOfChildren(List<String> path) {
return getNodeByPath(path).children.keySet();
}
public void createTextNode(List<String> path, String key, String value) {
((ObjectNode) getNodeByPath(path).jsonNode).put(key, value);
}
public class Node { // wrapper for JsonNode that adds key, parent and children for traversing the graph
Node parent;
Map<String, Node> children = new HashMap<>(); // no duplicate keys allowed in one json node
String key;
JsonNode jsonNode;
public JsonNode getJsonNode() {
return jsonNode;
}
public Node(Node parent, String key, JsonNode jsonNode) {
this.parent = parent;