public BellmanFordAlgorithm(IWeightedGraph<N, Number> graph, N source) {
		for(N node : graph) {
			nodes.put(node, new Node<N>(node, Double.MAX_VALUE));
		}
		nodes.get(source).distance = 0;
		
		List<WeightedEdge<N, Number>> edges = graph.getEdges();
		for(int i = 1; i < graph.size(); i++) {
			for(WeightedEdge<N, Number> edge : edges) {
				if(nodes.get(edge.from).distance + edge.weight.doubleValue() < nodes.get(edge.to).distance) {
					nodes.get(edge.to).distance = nodes.get(edge.from).distance + edge.weight.doubleValue();
					nodes.get(edge.to).previousNode = nodes.get(edge.from);
				}
			}
		}
		
		for(WeightedEdge<N, Number> edge : edges) {
			if(nodes.get(edge.from).distance + edge.weight.doubleValue() < nodes.get(edge.to).distance) {
				System.err.println("Graph contains a negative-weight cycle");
				return;
			}
		}
		
		for(N node : graph) {
			ArrayList<Node<N>> tempPath = new ArrayList<Node<N>>();
			Node<N> current = nodes.get(node);
			while(current != null) {
				tempPath.add(current);
				current = current.previousNode;
			}
			Collections.reverse(tempPath);
			paths.put(node, tempPath);
		}
	}