Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/main/java/experiments/autofix/classes/AutofixClass_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@


package experiments.autofix.classes;

import java.util.*;

public class AutofixClass_1 {
public static int[][] AutofixMethod_2(int[][] g, int n, int m, int[] verticesToConnect) {
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
g[i][j] = Math.min(g[i][j], g[i][k] + g[k][j]);
int[][] dp = new int[1 << m][n];
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
dp[1 << i][j] = g[verticesToConnect[i]][j];
return dp;
}
public static void AutofixMethod_1(int[][] dp, int m, int n, int[][] g) {
for (int i = 1; i < 1 << m; i++) {
if (((i - 1) & i) != 0) {
for (int j = 0; j < n; j++) {
dp[i][j] = Integer.MAX_VALUE / 2;
for (int k = (i - 1) & i; k > 0; k = (k - 1) & i) {
dp[i][j] = Math.min(dp[i][j], dp[k][j] + dp[i ^ k][j]);
}
}
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
dp[i][j] = Math.min(dp[i][j], dp[i][k] + g[k][j]);
}
}
}
}
}
}
19 changes: 6 additions & 13 deletions src/main/java/experiments/package1/Biconnectivity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@


package experiments.package1;

import java.util.*;

import java.util.stream.Stream;

public class Biconnectivity {

List<Integer>[] graph;
boolean[] visited;
Stack<Integer> stack;
Expand All @@ -14,7 +16,6 @@ public class Biconnectivity {
List<List<Integer>> edgeBiconnectedComponents;
List<Integer> cutPoints;
List<String> bridges;

public List<List<Integer>> biconnectivity(List<Integer>[] graph) {
int n = graph.length;
this.graph = graph;
Expand All @@ -26,14 +27,11 @@ public List<List<Integer>> biconnectivity(List<Integer>[] graph) {
edgeBiconnectedComponents = new ArrayList<>();
cutPoints = new ArrayList<>();
bridges = new ArrayList<>();

for (int u = 0; u < n; u++)
if (!visited[u])
dfs(u, -1);

return edgeBiconnectedComponents;
}

void dfs(int u, int p) {
visited[u] = true;
lowlink[u] = tin[u] = time++;
Expand All @@ -44,12 +42,12 @@ void dfs(int u, int p) {
if (v == p)
continue;
if (visited[v]) {
lowlink[u] = Math.min(lowlink[u], tin[v]); // or lowlink[u] = Math.min(lowlink[u], lowlink[v]);
lowlink[u] = Math.min(lowlink[u], tin[v]);
} else {
dfs(v, u);
lowlink[u] = Math.min(lowlink[u], lowlink[v]);
cutPoint |= tin[u] <= lowlink[v];
if (tin[u] < lowlink[v]) // or if (lowlink[v] == tin[v])
cutPoint |= tin[u] <= lowlink[v];
if (tin[u] < lowlink[v])
bridges.add("(" + u + "," + v + ")");
++children;
}
Expand All @@ -69,7 +67,6 @@ void dfs(int u, int p) {
edgeBiconnectedComponents.add(component);
}
}

public static List<Integer>[] ebcTree(List<Integer>[] graph, List<List<Integer>> components) {
int[] comp = new int[graph.length];
for (int i = 0; i < components.size(); i++)
Expand All @@ -82,19 +79,15 @@ public static List<Integer>[] ebcTree(List<Integer>[] graph, List<List<Integer>>
g[comp[u]].add(comp[v]);
return g;
}

public static void main(String[] args) {
List<Integer>[] graph = Stream.generate(ArrayList::new).limit(6).toArray(List[]::new);

int[][] esges = {{0, 1}, {1, 2}, {0, 2}, {2, 3}, {1, 4}, {4, 5}, {5, 1}};
for (int[] edge : esges) {
graph[edge[0]].add(edge[1]);
graph[edge[1]].add(edge[0]);
}

Biconnectivity bc = new Biconnectivity();
List<List<Integer>> components = bc.biconnectivity(graph);

System.out.println("edge-biconnected components:" + components);
System.out.println("cut points: " + bc.cutPoints);
System.out.println("bridges:" + bc.bridges);
Expand Down
Loading