Skip to content
Snippets Groups Projects
Commit 1ffa5400 authored by User expired's avatar User expired
Browse files

fixed problem with failed tests (and poor performance)

parent 3d3ff55b
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,6 @@ import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* The Isochrone algorithm as described in the paper. As the
......@@ -34,6 +33,14 @@ import java.util.stream.Collectors;
* algorithms which define the loading of the data from the database.
*/
public abstract class Isochrone {
private static final Predicate<Link> PREDICATE_LINK_CONT = new Predicate<Link>() {
private final Double dMin = Double.MIN_VALUE;
@Override
public boolean test(final Link link) {
return link.isContinuous() && !dMin.equals(link.getStartOffset());
}
};
private final Collection<Integer> dateCodes;
private final AbstractQueue<Node> nodeQueue;
private final long qDuration;
......@@ -170,16 +177,11 @@ public abstract class Isochrone {
cConnections = prepareContinuousLinks(node, links);
updateNodeQueue(expandContinuousLinks(cConnections));
output.addLinks(links.stream().filter(new Predicate<Link>() {
@Override
public boolean test(final Link link) {
return link.isContinuous();
}
}).collect(Collectors.toList()));
dConnections = prepareDiscreteLinks(node, links);
updateNodeQueue(expandDiscreteLinks(dConnections));
output.addLinks(links.parallelStream().filter(PREDICATE_LINK_CONT));
if (qIsExpiring && node.isExpired()) {
removeNode(nodeId);
}
......@@ -229,7 +231,7 @@ public abstract class Isochrone {
}
} else {
nConnection.addLink(targetNode, link);
}
}
}
/**
......
......@@ -475,7 +475,13 @@ public class Database {
final short degree = rs.getShort("DEGREE");
final int targetId = rs.getInt("TARGET");
final Link link = new Link(linkId, sourceId, targetId, (rs.getByte("EDGE_MODE") == NW_MODE_CONTINUOUS) ? rs.getDouble("LENGTH") : rs.getShort("ROUTE_ID"));
Link link = null;
if (rs.getByte("EDGE_MODE") == NW_MODE_CONTINUOUS) {
link = new Link(linkId, sourceId, targetId, rs.getDouble("LENGTH"));
} else {
link = new Link(linkId, sourceId, targetId, rs.getShort("ROUTE_ID"));
}
addLink(addNodes(link, degree, nodes), link, adjList);
}
} catch (final SQLException e) {
......@@ -501,6 +507,7 @@ public class Database {
try {
rs = stmt.executeQuery();
while (rs.next()) {
final int linkId = rs.getInt("ID");
final int startNodeId = rs.getInt("SOURCE");
final int endNodeId = rs.getInt("TARGET");
......@@ -525,8 +532,12 @@ public class Database {
node.setAdjLinks(new ArrayList<Link>());
}
final int linkId = rs.getInt("ID");
final Link link = new Link(linkId, startNodeId, endNodeId, (rs.getByte("EDGE_MODE") == NW_MODE_CONTINUOUS) ? rs.getDouble("LENGTH") : rs.getShort("ROUTE_ID"));
final Link link;
if (rs.getByte("EDGE_MODE") == NW_MODE_CONTINUOUS) {
link = new Link(linkId, startNodeId, endNodeId, rs.getDouble("LENGTH"));
} else {
link = new Link(linkId, startNodeId, endNodeId, rs.getShort("ROUTE_ID"));
}
node.addAdjLink(link);
links.put(linkId, link);
if (!nodes.containsKey(start)) {
......@@ -617,6 +628,8 @@ public class Database {
// Private methods
private Link createLinkFromResultSet(final int nodeId, final int adjNodeId, final ResultSet rs) throws SQLException {
final int linkId = rs.getInt("ID");
int start, end;
if (isIncoming) {
start = adjNodeId;
......@@ -626,7 +639,14 @@ public class Database {
end = adjNodeId;
}
return new Link(rs.getInt("ID"), start, end, (rs.getByte("EDGE_MODE") == NW_MODE_CONTINUOUS) ? rs.getDouble("LENGTH") : rs.getShort("ROUTE_ID"));
final Link link;
if (rs.getByte("EDGE_MODE") == NW_MODE_CONTINUOUS) {
link = new Link(linkId, start, end, rs.getDouble("LENGTH"));
} else {
link = new Link(linkId, start, end, rs.getShort("ROUTE_ID"));
}
return link;
}
/**
......@@ -755,7 +775,7 @@ public class Database {
*/
private static void addNode(final int nodeId, final short nrAdjLinks, final Map<Integer, Node> nodes) {
if (nodes == null) {
return;
return; // Just for safety
}
final Node node = nodes.get(nodeId);
......
package it.unibz.inf.isochrone.network;
import java.util.Collection;
import java.util.function.Consumer;
import java.util.stream.Stream;
public abstract class AbstractOutput implements IOutput {
private final Consumer<Link> linkConsumer = new Consumer<Link>() {
@Override
public void accept(final Link link) {
addLink(link);
}
};
private final Consumer<Node> nodeConsumer = new Consumer<Node>() {
@Override
public void accept(final Node node) {
addNode(node);
}
};
/**
* This is called after all links and nodes are stored in this output.
......@@ -22,10 +36,18 @@ public abstract class AbstractOutput implements IOutput {
}
}
public void addLinks(final Stream<Link> linkStream) {
linkStream.forEach(linkConsumer);
}
public void addNodes(final Collection<Node> nodes) {
for (final Node node : nodes) {
addNode(node);
}
}
public void addNodes(final Stream<Node> nodeStream) {
nodeStream.forEach(nodeConsumer);
}
}
package it.unibz.inf.isochrone.network;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
/**
* A sample output class, which simply stores all nodes and returns if needed.
......@@ -15,8 +14,8 @@ public class MemoryOutput extends AbstractOutput {
// Constructor
public MemoryOutput() {
links = new ArrayList<>();
nodes = new HashSet<>();
links = new LinkedHashSet<>();
nodes = new LinkedHashSet<>();
}
// Getter
......
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