Permalink
Browse files

removed duplicated file

  • Loading branch information...
1 parent 21ff46e commit 04f39156dee97656359fbc20e434f858e72aac88 @NicholasAStuart NicholasAStuart committed Feb 19, 2013
View
@@ -1,4 +1,7 @@
*.log
target/
.idea/
-furnace.iml
+furnace.iml
+/.settings
+/.classpath
+/.project
@@ -1,102 +0,0 @@
-package com.tinkerpop.furnace.algorithms;
-
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import com.tinkerpop.blueprints.Direction;
-import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.Graph;
-import com.tinkerpop.blueprints.Vertex;
-
-/**
- *
- * Implementation of Dijkstra's Algorithm using Tinkerpop's Pipelines.
- *
- * @author Nicholas A. Stuart (nicholasastuart@gmail.com)
- *
- */
-public class DijkstrasAlgorithm extends SingleSourceShortestPathAlgorithm {
- public DijkstrasAlgorithm(Graph graph) {
- super(graph);
- }
-
- @Override
- public Map<Vertex, Long> compute(Vertex source, String weightPropertyName, String... weightedEdgeLabels) {
- if (source == null) {
- throw new NullPointerException("Source cannot be null");
- }
- if (weightedEdgeLabels == null) {
- throw new NullPointerException("Weighted edge labels cannot be null");
- }
- if (weightPropertyName == null || weightPropertyName.isEmpty()) {
- throw new IllegalArgumentException("Weight property name cannot be null or empty");
- }
- for (String weightedEdgeLabel : weightedEdgeLabels) {
- if (weightedEdgeLabel == null) {
- throw new IllegalArgumentException("One of the weighted edge labels was null");
- }
- }
-
- Graph graph = getGraph();
- source = graph.getVertex(source.getId());
- if (source == null) {
- throw new IllegalStateException("Source vertex does not belong to this graph.");
- }
- return performDijkstrasAlgorithm(graph, source, weightPropertyName, weightedEdgeLabels);
- }
-
- private Map<Vertex, Long> performDijkstrasAlgorithm(Graph graph, Vertex source, String weightPropertyName, final String... weightedEdgeLabels) {
- final Map<Vertex, Long> distanceMap = new HashMap<Vertex, Long>();
- Set<Vertex> remainingNodes = new HashSet<Vertex>();
- // Map<Vertex, Edge> previousMap = new HashMap<Vertex, Edge>();
-
- Comparator<Vertex> distanceComparator = new Comparator<Vertex>() {
- @Override
- public int compare(Vertex vertex1, Vertex vertex2) {
- return (int) (distanceMap.get(vertex2) - distanceMap.get(vertex1));
- }
- };
-
- for (Vertex vertex : graph.getVertices()) {
- distanceMap.put(vertex, Long.MAX_VALUE);
- remainingNodes.add(vertex);
- }
- distanceMap.put(source, 0L);
-
- while (!remainingNodes.isEmpty()) {
- Vertex smallestVertex = Collections.min(remainingNodes, distanceComparator);
- remainingNodes.remove(smallestVertex);
- Long currentDistance = distanceMap.get(smallestVertex);
- if (currentDistance == Long.MAX_VALUE) {
- break;
- }
-
- for (Edge edge : smallestVertex.getEdges(Direction.OUT, weightedEdgeLabels)) {
- Vertex neighborVertex = edge.getVertex(Direction.IN);
- if (remainingNodes.contains(neighborVertex)) {
- Long edgeWeight = null;
- try {
- edgeWeight = Long.valueOf(edge.getProperty(weightPropertyName).toString());
- } catch (NumberFormatException nfe) {
- throw new IllegalArgumentException("Edge " + edge + " weight property not castable to Long");
- } catch (NullPointerException npe) {
- throw new IllegalArgumentException("Edge " + edge + " did not contain the property key " + weightPropertyName);
- }
- Long couldBeShorterDistance = currentDistance + edgeWeight;
- if (couldBeShorterDistance < currentDistance) {
- couldBeShorterDistance = Long.MAX_VALUE;
- }
- if (couldBeShorterDistance < distanceMap.get(neighborVertex)) {
- distanceMap.put(neighborVertex, couldBeShorterDistance);
- // previousMap.put(neighborVertex, edge);
- }
- }
- }
- }
- return distanceMap;
- }
-}
@@ -1,28 +0,0 @@
-package com.tinkerpop.furnace.algorithms;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.tinkerpop.blueprints.Element;
-import com.tinkerpop.blueprints.Graph;
-import com.tinkerpop.blueprints.Vertex;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class ShortestPath {
-
- private final Graph graph;
-
- public ShortestPath(final Graph graph) {
- this.graph = graph;
- }
-
- public List<Element> compute(final Vertex start, final Vertex end, final String... labels) {
- return new ArrayList<Element>();
- }
-
- public Graph getGraph() {
- return graph;
- }
-}
@@ -1,33 +0,0 @@
-package com.tinkerpop.furnace.algorithms;
-
-import java.util.Map;
-
-import com.tinkerpop.blueprints.Graph;
-import com.tinkerpop.blueprints.Vertex;
-
-/**
- * @author Nicholas A. Stuart (nicholasastuart@gmail.com)
- */
-public abstract class SingleSourceShortestPathAlgorithm {
- private final Graph graph;
-
- public SingleSourceShortestPathAlgorithm(final Graph graph) {
- this.graph = graph;
- }
-
- /**
- *
- * @param source
- * Source node from which to find the shortest path from.
- * @param weightPropertyName
- * Name of the property on each edge to use for weight. Cannot be {@code null} or empty.
- * @param weightedEdgeLabel
- * Edge label to go out from the vertex. {@code null} or empty is allowed and will use any edge label to traverse.
- * @return {@code Map<Vertex, Long>} with key of {@code Vertex} in the graph and value of distance to {@code Vertex}.
- */
- public abstract Map<Vertex, Long> compute(final Vertex source, final String weightPropertyName, final String... weightedEdgeLabels);
-
- public final Graph getGraph() {
- return graph;
- }
-}

0 comments on commit 04f3915

Please sign in to comment.