Index: proiecte/Traffic/.project
===================================================================
--- proiecte/Traffic/.project	(revision 145)
+++ proiecte/Traffic/.project	(revision 145)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Traffic</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+	</buildSpec>
+	<natures>
+	</natures>
+</projectDescription>
Index: proiecte/Traffic/DijkstraColSeq.java
===================================================================
--- proiecte/Traffic/DijkstraColSeq.java	(revision 145)
+++ proiecte/Traffic/DijkstraColSeq.java	(revision 145)
@@ -0,0 +1,97 @@
+/**
+ * Sequential Version of Dijkstra's Algorithm
+ */
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.Scanner;
+import java.util.TreeMap;
+import java.util.List;
+
+public class DijkstraColSeq {
+
+	private final static Integer infinity = 2000;
+	static int len = 0;
+
+	/**
+	 * @param args
+	 *            0 - Filename where Vertices and Edges are stored
+	 * @param args
+	 *            1 - Name of the source vertex
+	 * @param args
+	 *            2 - Name of the destination vertex
+	 */
+	public static void main(String[] args) {
+		String fileName = null;
+		Vertex source = null;
+		Vertex destination = null;
+		if (args.length == 3) {
+			fileName = args[0];
+			source = new Vertex(Integer.parseInt(args[1]));
+			destination = new Vertex(Integer.parseInt(args[2]));
+		} else {
+			System.err.println("Invalid command-line arguements");
+			System.exit(0);
+		}
+
+		List<Vertex> vertices = new ArrayList<Vertex>();
+		ArrayList<Edge> edges = new ArrayList<Edge>();
+		try {
+			BufferedReader in = new BufferedReader(new FileReader(fileName));
+			String line = in.readLine();
+			len = Integer.parseInt( line );
+			while ((line = in.readLine()) != null) {
+				Scanner scan = new Scanner( line );
+				Vertex start = new Vertex( scan.nextInt() );
+				Vertex end = new Vertex( scan.nextInt() );
+				if( !vertices.contains( start ) ) vertices.add( start );
+				if( !vertices.contains( end ) ) vertices.add( end );
+				edges.add( new Edge( start, end, scan.nextInt() ) );
+			}
+			in.close();
+		} catch( Exception e ) {
+			e.printStackTrace();
+		}
+		
+		Graph g = new Graph(vertices, edges);
+		
+		//*** Dijkstra's Algorithm ***\\
+		TreeMap<Vertex, Integer> distFromSource = new TreeMap<Vertex, Integer>();
+		TreeMap<Vertex, Vertex> previousNode = new TreeMap<Vertex, Vertex>();
+		TreeMap<Vertex, Integer> unvisitedNodes = new TreeMap<Vertex, Integer>();
+		for( Vertex v : g.getVertices() ) {
+			distFromSource.put( v, infinity );
+			previousNode.put( v, null );
+			unvisitedNodes.put( v, null );
+		}
+		distFromSource.put(source, 0);
+		
+		for( Vertex v : unvisitedNodes.keySet() ) {
+			Vertex currentNode = v;
+			for( Vertex v2 : unvisitedNodes.keySet() ) {
+				if( distFromSource.get( v2 ) < distFromSource.get( currentNode ) && unvisitedNodes.get( v2 ) == null )
+					currentNode = v2;
+			}
+			unvisitedNodes.put( currentNode, new Integer( 1 ) );
+			for( Edge e : g.getEdgesContaining( currentNode ) ) {
+				int newDist = distFromSource.get( currentNode ) + e.getDistance();
+				Vertex otherVertex = e.getOtherVertex( currentNode );
+				if( newDist < distFromSource.get( otherVertex ) ) {
+					distFromSource.put( otherVertex, newDist );
+					previousNode.put( otherVertex, currentNode );
+				}
+			}
+		}
+		
+		Vertex prev = previousNode.get( destination );
+		String output = "[" + destination.getName() + "]";
+		while( !source.equals( prev ) ) {
+			output = "[" + prev.getName() + "] -> " + output;
+			prev = previousNode.get( prev );
+		}
+		output = "[" + source.getName() + "] -> " + output + " (Total Distance = " + distFromSource.get( destination ) + ")";
+		System.out.println( output );
+	}
+
+}
Index: proiecte/Traffic/DijkstraColSmp.java
===================================================================
--- proiecte/Traffic/DijkstraColSmp.java	(revision 145)
+++ proiecte/Traffic/DijkstraColSmp.java	(revision 145)
@@ -0,0 +1,122 @@
+/**
+ * Sequential Version of Dijkstra's Algorithm
+ */
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.Scanner;
+import java.util.TreeMap;
+import java.util.Map;
+import java.util.Collections;
+import java.util.List;
+import edu.rit.pj.Comm;
+import edu.rit.pj.ParallelRegion;
+import edu.rit.pj.ParallelTeam;
+import edu.rit.pj.ParallelIteration;
+
+public class DijkstraColSmp {
+
+	private final static Integer infinity = 2000;
+	static int len = 0;
+	static Graph g;
+	static Map<Vertex, Integer> distFromSource;
+	static Map<Vertex, Vertex> previousNode;
+	static Map<Vertex, Integer> unvisitedNodes;
+	static Vertex currentNode;
+
+	/**
+	 * @param args
+	 *            0 - Filename where Vertices and Edges are stored
+	 * @param args
+	 *            1 - Name of the source vertex
+	 * @param args
+	 *            2 - Name of the destination vertex
+	 */
+	public static void main(String[] args) throws Exception{
+		Comm.init (args);
+		double begin = System.currentTimeMillis();
+		String fileName = null;
+		Vertex source = null;
+		Vertex destination = null;
+		if (args.length == 3) {
+			fileName = args[0];
+			source = new Vertex(Integer.parseInt(args[1]));
+			destination = new Vertex(Integer.parseInt(args[2]));
+		} else {
+			System.err.println("Invalid command-line arguements");
+			System.exit(0);
+		}
+
+		List<Vertex> vertices = Collections.synchronizedList( new ArrayList<Vertex>() );
+		ArrayList<Edge> edges = new ArrayList<Edge>();
+		try {
+			BufferedReader in = new BufferedReader(new FileReader(fileName));
+			String line = in.readLine();
+			len = Integer.parseInt( line );
+			while ((line = in.readLine()) != null) {
+				Scanner scan = new Scanner( line );
+				Vertex start = new Vertex( scan.nextInt() );
+				Vertex end = new Vertex( scan.nextInt() );
+				if( !vertices.contains( start ) ) vertices.add( start );
+				if( !vertices.contains( end ) ) vertices.add( end );
+				edges.add( new Edge( start, end, scan.nextInt() ) );
+			}
+			in.close();
+		} catch( Exception e ) {
+			e.printStackTrace();
+		}
+		
+		g = new Graph( vertices, edges );
+		
+		//*** Dijkstra's Algorithm ***\\
+		distFromSource = new TreeMap<Vertex, Integer>();
+		previousNode = new TreeMap<Vertex, Vertex>();
+		unvisitedNodes = new TreeMap<Vertex, Integer>();
+		for( Vertex v : g.getVertices() ) {
+			distFromSource.put( v, infinity );
+			previousNode.put( v, null );
+			unvisitedNodes.put( v, null );
+		}
+		distFromSource.put(source, 0);
+		
+		new ParallelTeam().execute( new ParallelRegion()
+            		{
+            		public void run() throws Exception
+			{
+				for( Vertex v : unvisitedNodes.keySet() ) {
+					currentNode = v;
+					for( Vertex v2 : unvisitedNodes.keySet() ) {
+						if( distFromSource.get( v2 ) < distFromSource.get( currentNode ) && unvisitedNodes.get( v2 ) == null )
+							currentNode = v2;
+					}
+					unvisitedNodes.put( currentNode, new Integer( 1 ) );
+					execute( g.getEdgesContaining( currentNode ), new ParallelIteration<Edge>()
+                 				{
+						public void run( Edge e )
+                     					{
+							int newDist = distFromSource.get( currentNode ) + e.getDistance();
+							Vertex otherVertex = e.getOtherVertex( currentNode );
+							if( newDist < distFromSource.get( otherVertex ) ) {
+								distFromSource.put( otherVertex, newDist );
+								previousNode.put( otherVertex, currentNode );
+								}
+							}
+						});
+					}
+				}
+			});
+		
+		Vertex prev = previousNode.get( destination );
+		String output = "[" + destination.getName() + "]";
+		while( !source.equals( prev ) ) {
+			output = "[" + prev.getName() + "] -> " + output;
+			prev = previousNode.get( prev );
+		}
+		output = "[" + source.getName() + "] -> " + output + " (Total Distance = " + distFromSource.get( destination ) + ")";
+		System.out.println( output );
+		double end = System.currentTimeMillis();
+		System.out.println("Runing time: "+ (end - begin));
+	}
+
+}
Index: proiecte/Traffic/DijkstraMatSeq.java
===================================================================
--- proiecte/Traffic/DijkstraMatSeq.java	(revision 145)
+++ proiecte/Traffic/DijkstraMatSeq.java	(revision 145)
@@ -0,0 +1,98 @@
+/**
+ * Sequential Version of Dijkstra's Algorithm
+ */
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.util.Scanner;
+
+public class DijkstraMatSeq {
+
+	private final static Integer infinity = 2000;
+
+	/**
+	 * @param args
+	 *            0 - Filename where Vertices and Edges are stored
+	 * @param args
+	 *            1 - Name of the source vertex
+	 * @param args
+	 *            2 - Name of the destination vertex
+	 */
+	public static void main( String[] args ) {
+		long time = -System.currentTimeMillis();
+		String fileName = null;
+		int source = 0;
+		int destination = 0;
+		if (args.length == 3) {
+			fileName = args[0];
+			source = Integer.parseInt(args[1]);
+			destination = Integer.parseInt(args[2]);
+		} else {
+			System.err.println("Invalid command-line arguements");
+			System.exit(0);
+		}
+
+		int[][] graph = null;
+		int len = 0;
+		try {
+			BufferedReader in = new BufferedReader(new FileReader(fileName));
+			String line = in.readLine();
+			len = Integer.parseInt( line );
+			graph = new int[len][len];
+			for( int a = 0; a < len; a++ ) {
+				for( int b = 0; b < len; b++ ) {
+					graph[a][b] = infinity;
+				}
+			}
+			while ((line = in.readLine()) != null) {
+				Scanner scan = new Scanner( line );
+				int pointA = scan.nextInt();
+				int pointB = scan.nextInt();
+				int dist = scan.nextInt();
+				graph[pointA][pointB] = dist;
+				graph[pointB][pointA] = dist;
+			}
+			in.close();
+		} catch( Exception e ) {
+			e.printStackTrace();
+		}
+		
+		//*** Dijkstra's Algorithm ***\\
+		int[] distFromSource = new int[len];
+		int[] previousNode = new int[len];
+		int[] unvisitedNodes = new int[len];
+		for( int i = 0; i < len; i++ ) {
+			distFromSource[i] = infinity;
+			previousNode[i] = -1;
+		}
+		distFromSource[source] = 0;
+		
+		for( int j = 0; j < len; j++ ) {
+			int currentNode = j;
+			for( int j2 = 0; j2 < len; j2++ ) {
+				if( distFromSource[j2] < distFromSource[currentNode] && unvisitedNodes[j2] != 1 )
+					currentNode = j2;
+			}
+			unvisitedNodes[currentNode] = 1;
+			for( int k = j; k < graph[currentNode].length; k++ ) {
+				int newDist = distFromSource[currentNode] + graph[currentNode][k];
+				if( newDist < distFromSource[k] ) {
+					distFromSource[k] = newDist;
+					previousNode[k] = currentNode;
+				}
+			}
+		}
+		
+		//Print out the output
+		int prev = previousNode[destination];
+		String output = "[" + destination + "]";
+		while( source != prev ) {
+			output = "[" + prev + "] -> " + output;
+			prev = previousNode[prev];
+		}
+		output = "[" + source + "] -> " + output + " (Total Distance = " + distFromSource[destination] + ")";
+		System.out.println( output );
+		System.out.println( "Running Time : " + (System.currentTimeMillis() + time) );
+	}
+
+}
Index: proiecte/Traffic/DijkstraMatSmp.java
===================================================================
--- proiecte/Traffic/DijkstraMatSmp.java	(revision 145)
+++ proiecte/Traffic/DijkstraMatSmp.java	(revision 145)
@@ -0,0 +1,113 @@
+/**
+ * Smp Version of Dijkstra's Algorithm
+ */
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.util.Scanner;
+import edu.rit.pj.*;
+
+public class DijkstraMatSmp {
+
+	final static Integer infinity = 2000;
+	static int[] distFromSource;
+	static int[] previousNode;
+	static int[] unvisitedNodes;
+	static int[][] graph = null;
+	static int len = 0;
+
+	/**
+	 * @param args
+	 *            0 - Filename where Vertices and Edges are stored
+	 * @param args
+	 *            1 - Name of the source vertex
+	 * @param args
+	 *            2 - Name of the destination vertex
+	 */
+	public static void main( String[] args ) throws Exception {
+		long time = -System.currentTimeMillis();
+		Comm.init( args );
+		String fileName = null;
+		int source = 0;
+		int destination = 0;
+		if (args.length == 3) {
+			fileName = args[0];
+			source = Integer.parseInt(args[1]);
+			destination = Integer.parseInt(args[2]);
+		} else {
+			System.err.println("Invalid command-line arguements");
+			System.exit(0);
+		}
+
+		try {
+			BufferedReader in = new BufferedReader(new FileReader(fileName));
+			String line = in.readLine();
+			len = Integer.parseInt( line );
+			graph = new int[len][len];
+			for( int a = 0; a < len; a++ ) {
+				for( int b = 0; b < len; b++ ) {
+					graph[a][b] = infinity;
+				}
+			}
+			while ((line = in.readLine()) != null) {
+				Scanner scan = new Scanner( line );
+				int pointA = scan.nextInt();
+				int pointB = scan.nextInt();
+				int dist = scan.nextInt();
+				graph[pointA][pointB] = dist;
+				graph[pointB][pointA] = dist;
+			}
+			in.close();
+		} catch( Exception e ) {
+			e.printStackTrace();
+		}
+		
+		//*** Dijkstra's Algorithm ***\\
+		distFromSource = new int[len];
+		previousNode = new int[len];
+		unvisitedNodes = new int[len];
+		for( int i = 0; i < len; i++ ) {
+			distFromSource[i] = infinity;
+			previousNode[i] = -1;
+		}
+		distFromSource[source] = 0;
+		
+		new ParallelTeam().execute( new ParallelRegion() 
+			{
+				public void run() throws Exception {
+					execute( 0, len-1, new IntegerForLoop()
+						{
+							public void run (int first, int last) {
+								for( int j = first; j <= last; j++ ) {
+									int currentNode = j;
+									for( int j2 = 0; j2 < len; j2++ ) {
+										if( distFromSource[j2] < distFromSource[currentNode] && unvisitedNodes[j2] != 1 )
+											currentNode = j2;
+									}
+									unvisitedNodes[currentNode] = 1;
+									for( int k = j; k < graph[currentNode].length; k++ ) {
+										int newDist = distFromSource[currentNode] + graph[currentNode][k];
+										if( newDist < distFromSource[k] ) {
+											distFromSource[k] = newDist;
+											previousNode[k] = currentNode;
+										}
+									}
+								}
+							}
+						});
+				}
+			});
+		
+		//Print out the output
+		int prev = previousNode[destination];
+		String output = "[" + destination + "]";
+		while( source != prev ) {
+			output = "[" + prev + "] -> " + output;
+			prev = previousNode[prev];
+		}
+		output = "[" + source + "] -> " + output + " (Total Distance = " + distFromSource[destination] + ")";
+		System.out.println( output );
+		System.out.println( "Running Time : " + (System.currentTimeMillis() + time) );
+	}
+
+}
Index: proiecte/Traffic/Edge.java
===================================================================
--- proiecte/Traffic/Edge.java	(revision 145)
+++ proiecte/Traffic/Edge.java	(revision 145)
@@ -0,0 +1,73 @@
+/**
+ * Edge Class
+ */
+
+public class Edge {
+	
+	private Vertex start;
+	private Vertex end;
+	private int distance;
+	
+	/**
+	 * @param name
+	 * @param start
+	 * @param end
+	 * @param distance
+	 */
+	public Edge(Vertex start, Vertex end, int distance) {
+		this.start = start;
+		this.end = end;
+		this.distance = distance;
+	}
+
+	/**
+	 * @return the start
+	 */
+	public Vertex getStart() {
+		return start;
+	}
+
+	/**
+	 * @param start the start to set
+	 */
+	public void setStart(Vertex start) {
+		this.start = start;
+	}
+
+	/**
+	 * @return the end
+	 */
+	public Vertex getEnd() {
+		return end;
+	}
+
+	/**
+	 * @param end the end to set
+	 */
+	public void setEnd(Vertex end) {
+		this.end = end;
+	}
+
+	/**
+	 * @return the distance
+	 */
+	public int getDistance() {
+		return distance;
+	}
+
+	/**
+	 * @param distance the distance to set
+	 */
+	public void setDistance(int distance) {
+		this.distance = distance;
+	}
+	
+	/**
+	 * @param v the vertex not to return
+	 * @return the other vertex
+	 */
+	public Vertex getOtherVertex( Vertex v ) {
+		if( v.equals( start ) ) return end;
+		return start;
+	}
+}
Index: proiecte/Traffic/Graph.java
===================================================================
--- proiecte/Traffic/Graph.java	(revision 145)
+++ proiecte/Traffic/Graph.java	(revision 145)
@@ -0,0 +1,82 @@
+/**
+ * Graph Class
+ */
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.List;
+
+public class Graph {
+	
+	private List<Vertex> vertices;
+	private ArrayList<Edge> edges;
+	
+	/**
+	 * @param vertices
+	 * @param edges
+	 */
+	public Graph(List<Vertex> vertices, ArrayList<Edge> edges) {
+		this.vertices = vertices;
+		this.edges = edges;
+	}
+
+	/**
+	 * @return the vertices
+	 */
+	public List<Vertex> getVertices() {
+		return vertices;
+	}
+
+	/**
+	 * @param vertices the vertices to set
+	 */
+	public void setVertices(List<Vertex> vertices) {
+		this.vertices = vertices;
+	}
+
+	/**
+	 * @return the edges
+	 */
+	public ArrayList<Edge> getEdges() {
+		return edges;
+	}
+
+	/**
+	 * @param edges the edges to set
+	 */
+	public void setEdges(ArrayList<Edge> edges) {
+		this.edges = edges;
+	}
+	
+	/**
+	 * @param v the vertex to search for
+	 * @param unvisitedNodes the set of all unvisited nodes
+	 * @return the edges which contain v
+	 */
+	public ArrayList<Edge> getEdgesContaining( Vertex v ) {
+		ArrayList<Edge> list = new ArrayList<Edge>();
+		for( Edge e : edges ) {
+			if( (e.getStart().equals( v ) || e.getEnd().equals( v )) )
+				list.add( e );
+		}
+		return list;
+	}
+	
+	/**
+	 * @param unvisitedNodes the map of vertices and Integer (If a node has been already seen)
+	 * @param distances the map of Vertices to their distances
+	 * @return the vertex which contains the smallest distance
+	 */
+	public synchronized Vertex getSmallestNode( Map<Vertex,Integer> unvisitedNodes, Map<Vertex,Integer> distances ) {
+		Vertex smallest = null;
+		for( Vertex v : unvisitedNodes.keySet() ) {
+			if( smallest == null )
+				smallest = v;
+			else {
+				if( distances.get( v ) < distances.get( smallest ) && unvisitedNodes.get( v ) == null )
+					smallest = v;
+			}
+		}
+		return smallest;
+	}
+}
Index: proiecte/Traffic/Vertex.java
===================================================================
--- proiecte/Traffic/Vertex.java	(revision 145)
+++ proiecte/Traffic/Vertex.java	(revision 145)
@@ -0,0 +1,52 @@
+/**
+ * Vertex Class
+ */
+
+public class Vertex implements Comparable<Vertex> {
+	
+	private int name;
+
+	/**
+	 * @param name
+	 */
+	public Vertex(int name) {
+		this.name = name;
+	}
+
+	/**
+	 * @return the name
+	 */
+	public int getName() {
+		return name;
+	}
+
+	/**
+	 * @param name the name to set
+	 */
+	public void setName(int name) {
+		this.name = name;
+	}
+	
+	/**
+	 * @param v the vertex to compare this vertex to
+	 * @return 0 if equals, negative is less than, and positive if greater than
+	 */
+	public int compareTo( Vertex v ) {
+		if( name == v.getName() )
+			return 0;
+		else if( name < v.getName() )
+			return -1;
+		return 1;
+	}
+	
+	/**
+	 * @param v the vertex to check equivalence
+	 * @return true if equals and false otherwise
+	 */
+	public boolean equals( Vertex v ) {
+		if( name == v.getName() ) {
+			return true;
+		}
+		return false;
+	}
+}
