Skip to content
Snippets Groups Projects
Commit e4401fa8 authored by Nikolaus Krismer's avatar Nikolaus Krismer
Browse files

fixed some problems with empty lists

changed list type of adjList variable to collection
parent b9a6cb78
No related branches found
No related tags found
No related merge requests found
......@@ -149,6 +149,10 @@ public abstract class Isochrone {
node.close();
final Collection<Link> adjacents = mapEntry.getValue();
if (adjacents == null) {
throw new NullPointerException("Unexpected null value!");
}
for (final Link link : adjacents) {
if (link.isContinuous()) {
updateQueue(expandContinuousLink(node, link));
......@@ -315,9 +319,8 @@ public abstract class Isochrone {
*/
protected Map<Integer, Collection<Link>> calcAdjLinks(final Collection<Integer> nodes) {
final Map<Integer, Collection<Link>> resultMap = new HashMap<>();
for (Integer id : nodes) {
final Collection<Link> adjLinks = getNode(id).getAdjLinks();
resultMap.put(id, adjLinks);
for (final Integer id : nodes) {
resultMap.put(id, getNode(id).getAdjLinks());
}
return resultMap;
......
......@@ -71,7 +71,7 @@ public class MineX extends Isochrone {
final Collection<Integer> c = new ArrayList<>(1);
c.add(nodeId);
return database.getAdjLinks(c, nodes).get(nodeId);
return calcAdjLinks(c).get(nodeId);
}
@Override
......
......@@ -13,7 +13,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
......@@ -23,7 +22,7 @@ import java.util.Set;
* Loads the data in circles surrounding the currently explored node.
*/
public class MrneX extends Isochrone {
private final Map<Integer, List<Link>> adjList;
private final Map<Integer, Collection<Link>> adjList;
private final Map<Integer, Node> loadedIERNodes;
private final Map<Integer, Node> nodes;
private final int maxDuration;
......@@ -43,9 +42,9 @@ public class MrneX extends Isochrone {
public MrneX(final ConfigDataset config, final Database db, final Query query, final int maxMemorySize) throws AlgorithmException {
super(config, db, query);
adjList = new HashMap<Integer, List<Link>>();
loadedIERNodes = new HashMap<Integer, Node>();
nodes = new HashMap<Integer, Node>();
adjList = new HashMap<>();
loadedIERNodes = new HashMap<>();
nodes = new HashMap<>();
maxDuration = query.getDuration().intValue();
maxMemory = maxMemorySize;
walkingSpeed = query.getWalkingSpeed();
......@@ -93,16 +92,19 @@ public class MrneX extends Isochrone {
}
}
final Map<Integer, Node> nullNodeMap = database.getNode(nullNodes);
final Set<Entry<Integer, Node>> nullNodeCheckList = nullNodeMap.entrySet();
for (Entry<Integer, Node> e : nullNodeCheckList) {
final Integer nodeId = e.getKey();
final Node node = e.getValue();
if (node == null) {
throw new RuntimeException("NodeId not present: " + nodeId);
}
if (!nullNodes.isEmpty()) {
final Map<Integer, Node> nullNodeMap = database.getNode(nullNodes);
final Set<Entry<Integer, Node>> nullNodeCheckList = nullNodeMap.entrySet();
for (Entry<Integer, Node> e : nullNodeCheckList) {
final Integer nodeId = e.getKey();
final Node node = e.getValue();
if (node == null) {
throw new RuntimeException("NodeId not present: " + nodeId);
}
result.put(nodeId, node);
nodes.put(nodeId, node);
result.put(nodeId, node);
}
}
return result;
......@@ -140,7 +142,7 @@ public class MrneX extends Isochrone {
final Collection<Integer> nonCoordinateNodeIds = new ArrayList<>(maxNodeCount);
for (Integer nodeId : nodeIds) {
final List<Link> adjNodeLinks = adjList.get(nodeId);
final Collection<Link> adjNodeLinks = adjList.get(nodeId);
if (adjNodeLinks != null) {
/*
* Check if adjacent continuous links are empty
......@@ -170,10 +172,12 @@ public class MrneX extends Isochrone {
}
// fill coordinates of remaining nodes
final Map<Integer, Point> coordinates = database.getCoordinates(nonCoordinateNodeIds);
final Set<Entry<Integer, Point>> coordinatEntrySet = coordinates.entrySet();
for (Entry<Integer, Point> e : coordinatEntrySet) {
nodeMap.get(e.getKey()).setCoordinates(e.getValue());
if (!nonCoordinateNodeIds.isEmpty()) {
final Map<Integer, Point> coordinates = database.getCoordinates(nonCoordinateNodeIds);
final Set<Entry<Integer, Point>> coordinatEntrySet = coordinates.entrySet();
for (Entry<Integer, Point> e : coordinatEntrySet) {
nodeMap.get(e.getKey()).setCoordinates(e.getValue());
}
}
// prepare radius of remaining nodes
......
......@@ -18,7 +18,6 @@ import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -157,7 +156,7 @@ public class Database {
// Public methods
public void addLink(final Link link, final short degree, final Map<Integer, Node> nodes, final Map<Integer, List<Link>> adjList) {
public void addLink(final Link link, final short degree, final Map<Integer, Node> nodes, final Map<Integer, Collection<Link>> adjList) {
int n1, n2;
if (isIncoming) {
n1 = link.getStartNode();
......@@ -518,10 +517,12 @@ public class Database {
/**
* Loads the links in a circle from the database (for better explanation see the MrneX algorithm).
*/
public void loadLinksFromIER(final Node node, final Collection<Node> intersections, final Map<Integer, Node> nodes, final Map<Integer, List<Link>> adjList) {
public void loadLinksFromIER(final Node node, final Collection<Node> intersections, final Map<Integer, Node> nodes, final Map<Integer, Collection<Link>> adjList) {
PreparedStatement stmt = null;
ResultSet rs = null;
final int serverSRID = config.getServerSRID();
final double r = node.getRadius();
final Point g = node.getCoordinates();
final String pointString = "POINT( " + g.getX() + " " + g.getY() + ")";
try {
......@@ -529,13 +530,13 @@ public class Database {
stmt = getPstmt(queryLoadLinksFromIER);
// CHECKSTYLE:OFF MagicNumber
stmt.setString(1, pointString);
stmt.setInt(2, config.getServerSRID());
stmt.setDouble(3, node.getRadius());
stmt.setInt(2, serverSRID);
stmt.setDouble(3, r);
// CHECKSTYLE:ON MagicNumber
} else {
final Node[] loadedAreas = intersections.toArray(new Node[0]);
final String disjunctAreaString = "st_difference(st_buffer(st_pointfromtext('" + pointString + "',"
+ config.getServerSRID() + ")," + node.getRadius() + ")," + subQuery(loadedAreas, loadedAreas.length - 1, config.getServerSRID()) + ")";
+ config.getServerSRID() + ")," + r + ")," + subQuery(loadedAreas, loadedAreas.length - 1, serverSRID) + ")";
stmt = getPstmt(String.format(queryGetLinksInRange, disjunctAreaString));
}
rs = stmt.executeQuery();
......
......@@ -3,6 +3,7 @@ package it.unibz.inf.isochrone.network;
import it.unibz.inf.isochrone.util.Point;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
......@@ -101,7 +102,7 @@ public class Node implements Comparable<Node> {
return true;
}
public List<Link> getAdjLinks() {
public Collection<Link> getAdjLinks() {
return adjLinks;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment