Skip to content
Snippets Groups Projects
Commit c4734db3 authored by Mohamed Awadalla's avatar Mohamed Awadalla
Browse files

Updates for 23sp

parent ec0ee151
No related branches found
No related tags found
No related merge requests found
package cse332.graph;
import java.util.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class GraphUtil {
......@@ -37,28 +39,28 @@ public class GraphUtil {
}
/**
* Find the cycle given the predecessor array
* Find if a cycle exists given the predecessor array
* @param prev predecessor array
* @return cycle, as a list, or empty list if there is no cycle
*/
public static List<Integer> getCycle(int[] prev) {
int n = prev.length;
int[] vis = new int[n];
int[] visited = new int[n];
for (int i = 0; i < n; i++) {
if (vis[i] < 0) continue;
if (visited[i] < 0) continue;
int j = i;
while (prev[j] >= 0 && vis[j] == 0) {
vis[j] = ~i;
while (prev[j] >= 0 && visited[j] == 0) {
visited[j] = ~i;
j = prev[j];
}
if (vis[j] != ~i) continue;
LinkedList<Integer> ll = new LinkedList<>();
if (visited[j] != ~i) continue;
LinkedList<Integer> cycleList = new LinkedList<>();
int u = j;
do {
ll.addFirst(u);
cycleList.addFirst(u);
u = prev[u];
} while (u != j);
return ll;
return cycleList;
}
return new LinkedList<>();
}
......
package main;
import cse332.interfaces.BellmanFordSolver;
import cse332.graph.GraphUtil;
import cse332.interfaces.BellmanFordSolver;
import solvers.OutSequential;
public class Main {
......
......@@ -2,23 +2,26 @@ package main;
import cse332.exceptions.NotYetImplementedException;
import java.util.List;
import java.util.Map;
public class Parser {
/**
* Parse an adjacency matrix into an adjacency list.
* @param adjMatrix Adjacency matrix
* @return Adjacency list
* @return Adjacency list of maps from node to weight
*/
public static Object parse(int[][] adjMatrix) {
public static List<Map<Integer, Integer>> parse(int[][] adjMatrix) {
throw new NotYetImplementedException();
}
/**
* Parse an adjacency matrix into an adjacency list with incoming edges instead of outgoing edges.
* @param adjMatrix Adjacency matrix
* @return Adjacency list with incoming edges
* @return Adjacency list of maps from node to weight with incoming edges
*/
public static Object parseInverse(int[][] adjMatrix) {
public static List<Map<Integer, Integer>> parseInverse(int[][] adjMatrix) {
throw new NotYetImplementedException();
}
......
......@@ -19,6 +19,10 @@ public class ArrayCopyTask extends RecursiveAction {
private final int[] src, dst;
private final int lo, hi;
public static void sequential() {
throw new NotYetImplementedException();
}
public ArrayCopyTask(int[] src, int[] dst, int lo, int hi) {
throw new NotYetImplementedException();
}
......
......@@ -5,11 +5,12 @@ import cse332.interfaces.BellmanFordSolver;
import main.Parser;
import java.util.List;
import java.util.Map;
public class InParallel implements BellmanFordSolver {
public List<Integer> solve(int[][] adjMatrix, int source) {
Object g = Parser.parseInverse(adjMatrix);
List<Map<Integer, Integer>> g = Parser.parseInverse(adjMatrix);
throw new NotYetImplementedException();
}
......
......@@ -5,13 +5,14 @@ import cse332.interfaces.BellmanFordSolver;
import main.Parser;
import java.util.List;
import java.util.Map;
public class OutParallelBad implements BellmanFordSolver {
public List<Integer> solve(int[][] adjMatrix, int source) {
Object g = Parser.parse(adjMatrix);
List<Map<Integer, Integer>> g = Parser.parse(adjMatrix);
throw new NotYetImplementedException();
}
}
\ No newline at end of file
}
......@@ -5,13 +5,14 @@ import cse332.interfaces.BellmanFordSolver;
import main.Parser;
import java.util.List;
import java.util.Map;
public class OutParallelLock implements BellmanFordSolver {
public List<Integer> solve(int[][] adjMatrix, int source) {
Object g = Parser.parse(adjMatrix);
List<Map<Integer, Integer>> g = Parser.parse(adjMatrix);
throw new NotYetImplementedException();
}
}
\ No newline at end of file
}
......@@ -5,13 +5,14 @@ import cse332.interfaces.BellmanFordSolver;
import main.Parser;
import java.util.List;
import java.util.Map;
public class OutSequential implements BellmanFordSolver {
public List<Integer> solve(int[][] adjMatrix, int source) {
Object g = Parser.parse(adjMatrix);
List<Map<Integer, Integer>> g = Parser.parse(adjMatrix);
throw new NotYetImplementedException();
}
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment