<commit_before>/**
 * <NAME>
 * Dijkstra Car Strategy
 * A strategy algorithm for cars that uses Dijkstra's algorithm to find
 * the shortest path from the starting node to the destination node
 */
package traffic.strategy;

import java.util.ArrayList;
import java.util.List;

import traffic.graph.Graph;
import traffic.graph.GraphNode;

public class DijkstraCarStrategy implements CarStrategy {

	public DijkstraCarStrategy(){}
	
	/**
	 * Uses Dijkstra's algorithm to find the shortest path from one node to the end
	 * Returns a list corresponding to the path for the car to take
	 */
	public List<Integer> getPath(Graph g, int currentNode, int destNode ) {
		int [] dist = new int [g.getNumNodes()];
		int [] prev = new int [g.getNumNodes()];
		boolean [] visited = new boolean [g.getNumNodes()];
		for (int i=0; i<dist.length; i++) {
			dist[i] = Integer.MAX_VALUE;
			prev[i] = Integer.MAX_VALUE;
		}
		dist[currentNode] = 0;
		for (int i=0; i<dist.length; i++) {
			int next = minVertex(dist, visited);
			visited[next] = true;
			if(next == destNode) {
				List<Integer> path = new ArrayList<Integer>();
				while(next != Integer.MAX_VALUE) {
					path.add(0, next);
					next = prev[next];
				}
				path.remove(0);
				return path;
			}
			List<GraphNode> n = g.getNeighbors(next);
		    for (int j=0; j<n.size(); j++) {
		    	//TODO: the indices can no longer be the IDs
		    	int v = 0; //n.get(j);
		        int w = dist[next] + g.getDelayAtNode(next);
		        if (dist[v] > w) {
		        	dist[v] = w;
		            prev[v] = next;
		        }
		    }
	   }
	   return null;
	}
	
	//Finds the closest vertex on the graph from the current one
	private int minVertex (int [] dist, boolean [] v) {
		int x = Integer.MAX_VALUE;
		int y = -1;
	    for (int i=0; i<dist.length; i++) {
	    	if (!v[i] && dist[i]<x) {
	    		y=i;
	        	x=dist[i];
	        }
	    }
	    return y;
	}	

}<commit_msg>Changed one line in Dijkstra's to properly compute the correct path<commit_after>/**
 * <NAME>
 * Dijkstra Car Strategy
 * A strategy algorithm for cars that uses Dijkstra's algorithm to find
 * the shortest path from the starting node to the destination node
 */
package traffic.strategy;

import java.util.ArrayList;
import java.util.List;

import traffic.graph.Graph;
import traffic.graph.GraphNode;

public class DijkstraCarStrategy implements CarStrategy {

	public DijkstraCarStrategy(){}
	
	/**
	 * Uses Dijkstra's algorithm to find the shortest path from one node to the end
	 * Returns a list corresponding to the path for the car to take
	 */
	public List<Integer> getPath(Graph g, int currentNode, int destNode ) {
		int [] dist = new int [g.getNumNodes()];
		int [] prev = new int [g.getNumNodes()];
		boolean [] visited = new boolean [g.getNumNodes()];
		for (int i=0; i<dist.length; i++) {
			dist[i] = Integer.MAX_VALUE;
			prev[i] = Integer.MAX_VALUE;
		}
		dist[currentNode] = 0;
		for (int i=0; i<dist.length; i++) {
			int next = minVertex(dist, visited);
			visited[next] = true;
			if(next == destNode) {
				List<Integer> path = new ArrayList<Integer>();
				while(next != Integer.MAX_VALUE) {
					path.add(0, next);
					next = prev[next];
				}
				path.remove(0);
				return path;
			}
			List<GraphNode> n = g.getNeighbors(next);
		    for (int j=0; j<n.size(); j++) {
		    	//TODO: the indices can no longer be the IDs
		    	int v = n.get(j).getID();
		        int w = dist[next] + g.getDelayAtNode(next);
		        if (dist[v] > w) {
		        	dist[v] = w;
		            prev[v] = next;
		        }
		    }
	   }
	   return null;
	}
	
	//Finds the closest vertex on the graph from the current one
	private int minVertex (int [] dist, boolean [] v) {
		int x = Integer.MAX_VALUE;
		int y = -1;
	    for (int i=0; i<dist.length; i++) {
	    	if (!v[i] && dist[i]<x) {
	    		y=i;
	        	x=dist[i];
	        }
	    }
	    return y;
	}	

}
{'fraction_non_alphanumeric': 0.13417460726242597, 'fraction_numerical': 0.004378058202420809, 'mean_word_length': 2.653809971777987, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7311774', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1310, 'n_words': 409}