use of org.neo4j.graphdb.PropertyContainer in project neo4j-mobile-android by neo4j-contrib.
the class Dijkstra method getPath.
/**
* @return One of the shortest paths found or null.
*/
public List<PropertyContainer> getPath() {
if (startNode == null || endNode == null) {
throw new RuntimeException("Start or end node undefined.");
}
calculate();
if (foundPathsMiddleNodes == null || foundPathsMiddleNodes.size() == 0) {
return null;
}
Node middleNode = foundPathsMiddleNodes.iterator().next();
LinkedList<PropertyContainer> path = new LinkedList<PropertyContainer>();
path.addAll(Util.constructSinglePathToNode(middleNode, predecessors1, true, false));
path.addAll(Util.constructSinglePathToNode(middleNode, predecessors2, false, true));
return path;
}
use of org.neo4j.graphdb.PropertyContainer in project neo4j-mobile-android by neo4j-contrib.
the class Dijkstra method getPaths.
/**
* @return All the found paths or null.
*/
public List<List<PropertyContainer>> getPaths() {
if (startNode == null || endNode == null) {
throw new RuntimeException("Start or end node undefined.");
}
calculateMultiple();
if (foundPathsMiddleNodes == null || foundPathsMiddleNodes.size() == 0) {
return Collections.emptyList();
}
// Currently we use a set to avoid duplicate paths
// TODO: can this be done smarter?
Set<List<PropertyContainer>> paths = new HashSet<List<PropertyContainer>>();
for (Node middleNode : foundPathsMiddleNodes) {
List<List<PropertyContainer>> paths1 = Util.constructAllPathsToNode(middleNode, predecessors1, true, false);
List<List<PropertyContainer>> paths2 = Util.constructAllPathsToNode(middleNode, predecessors2, false, true);
// For all combinations...
for (List<PropertyContainer> part1 : paths1) {
for (List<PropertyContainer> part2 : paths2) {
// Combine them
LinkedList<PropertyContainer> path = new LinkedList<PropertyContainer>();
path.addAll(part1);
path.addAll(part2);
// Add to collection
paths.add(path);
}
}
}
return new LinkedList<List<PropertyContainer>>(paths);
}
use of org.neo4j.graphdb.PropertyContainer in project blueprints by tinkerpop.
the class Neo4j2BatchGraph method populateKeyIndices.
private static <T extends PropertyContainer> void populateKeyIndices(final GraphDatabaseService rawGraphDB, final AutoIndexer<T> rawAutoIndexer, final Iterable<T> rawElements, final Class elementClass) {
if (!rawAutoIndexer.isEnabled())
return;
final Set<String> properties = rawAutoIndexer.getAutoIndexedProperties();
Transaction tx = rawGraphDB.beginTx();
final PropertyContainer kernel = ((GraphDatabaseAPI) rawGraphDB).getDependencyResolver().resolveDependency(NodeManager.class).newGraphProperties();
kernel.setProperty(elementClass.getSimpleName() + INDEXED_KEYS_POSTFIX, properties.toArray(new String[properties.size()]));
int count = 0;
for (final PropertyContainer pc : rawElements) {
for (final String property : properties) {
if (!pc.hasProperty(property))
continue;
pc.setProperty(property, pc.getProperty(property));
count++;
if (count >= 10000) {
count = 0;
tx.success();
tx.finish();
tx = rawGraphDB.beginTx();
}
}
}
tx.success();
tx.finish();
}
use of org.neo4j.graphdb.PropertyContainer in project graphdb by neo4j-attic.
the class DijkstraMultiplePathsTest method test7.
@Test
public void test7() {
Relationship edgeAB = graph.makeEdge("a", "b");
Relationship edgeBC = graph.makeEdge("b", "c");
Relationship edgeCD = graph.makeEdge("c", "d");
Relationship edgeDE = graph.makeEdge("d", "e");
Relationship edgeAB2 = graph.makeEdge("a", "b2");
Relationship edgeB2C = graph.makeEdge("b2", "c");
Relationship edgeCD2 = graph.makeEdge("c", "d2");
Relationship edgeD2E = graph.makeEdge("d2", "e");
Dijkstra<Double> dijkstra = new Dijkstra<Double>(0.0, graph.getNode("a"), graph.getNode("e"), new CostEvaluator<Double>() {
public Double getCost(Relationship relationship, Direction direction) {
return 1.0;
}
}, new DoubleAdder(), new DoubleComparator(), Direction.OUTGOING, MyRelTypes.R1);
// path discovery flags
boolean pathBD = false;
boolean pathB2D = false;
boolean pathBD2 = false;
boolean pathB2D2 = false;
List<List<PropertyContainer>> paths = dijkstra.getPaths();
assertTrue(paths.size() == 4);
for (List<PropertyContainer> path : paths) {
assertTrue(path.size() == 9);
assertTrue(path.get(0).equals(graph.getNode("a")));
assertTrue(path.get(4).equals(graph.getNode("c")));
assertTrue(path.get(8).equals(graph.getNode("e")));
// first choice
if (path.get(2).equals(graph.getNode("b"))) {
assertTrue(path.get(1).equals(edgeAB));
assertTrue(path.get(3).equals(edgeBC));
} else {
assertTrue(path.get(1).equals(edgeAB2));
assertTrue(path.get(2).equals(graph.getNode("b2")));
assertTrue(path.get(3).equals(edgeB2C));
}
// second choice
if (path.get(6).equals(graph.getNode("d"))) {
assertTrue(path.get(5).equals(edgeCD));
assertTrue(path.get(7).equals(edgeDE));
} else {
assertTrue(path.get(5).equals(edgeCD2));
assertTrue(path.get(6).equals(graph.getNode("d2")));
assertTrue(path.get(7).equals(edgeD2E));
}
// combinations
if (path.get(2).equals(graph.getNode("b"))) {
if (path.get(6).equals(graph.getNode("d"))) {
pathBD = true;
} else if (path.get(6).equals(graph.getNode("d2"))) {
pathBD2 = true;
}
} else {
if (path.get(6).equals(graph.getNode("d"))) {
pathB2D = true;
} else if (path.get(6).equals(graph.getNode("d2"))) {
pathB2D2 = true;
}
}
}
assertTrue(pathBD);
assertTrue(pathB2D);
assertTrue(pathBD2);
assertTrue(pathB2D2);
}
use of org.neo4j.graphdb.PropertyContainer in project neo4j by neo4j.
the class TestTimeline method createTimestampedEntity.
private Pair<PropertyContainer, Long> createTimestampedEntity(EntityCreator<PropertyContainer> creator, TimelineIndex<PropertyContainer> timeline, long timestamp) {
PropertyContainer entity = creator.create();
timeline.add(entity, timestamp);
return Pair.of(entity, timestamp);
}
Aggregations