Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
junming402 committed Apr 20, 2019
1 parent 3ae2011 commit b9cff21
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/Sampling/EstimateSampler.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class EstimateSampler {

public static void main(String[] args) throws Exception {
new EstimateSampler().sample("combined");
new EstimateSampler().sample("combined", 0.1);
}

public void sample(String inputFile, double epsilon) throws Exception {
Expand Down Expand Up @@ -45,7 +45,7 @@ public void sample(String inputFile, double epsilon) throws Exception {
if (i < nextNeighbour) {
String edgeKey = constructEdgeKey(i, nextNeighbour);
double pe = Math.min(1, p / strengthMap.get(edgeKey));
System.out.println("Sampling probability is "+pe);
//System.out.println("Sampling probability is "+pe);

originalSize += 1;
if (isSample(pe)) {
Expand All @@ -60,7 +60,7 @@ public void sample(String inputFile, double epsilon) throws Exception {
}
}

System.out.println("Compression rate = " + (sampledSize / originalSize));
System.out.println("epsilon =" + epsilon + ", Compression rate = " + (sampledSize / originalSize));

FileOutputStream outputStream = new FileOutputStream(Const.SAMPLED_DIR + inputFile);
outputStream.write(String.valueOf(size).getBytes());
Expand Down
24 changes: 17 additions & 7 deletions src/Sampling/Experiment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

Expand All @@ -10,27 +11,36 @@

public class Experiment {

private static final double[] epsilons = new double[] {0.05, 0.1, 0.15, 0.2, 0.25, 0.3};
private static final int accuracySampleSize = 50;
private static final double[] epsilons = new double[] {0.2, 0.25, 0.3, 0.35, 0.4};
private static final int accuracySampleSize = 10;

public static void main(String[] args) throws Exception {
new Experiment().doExperiment("clique");
new Experiment().doExperiment("random");
}

public void doExperiment(String file) throws Exception {
Scanner in = new Scanner(new BufferedReader(new FileReader(Const.SAMPLED_DIR + file)));
Scanner in = new Scanner(new BufferedReader(new FileReader(Const.OUTPUT_DIR + file)));
int nNodes = in.nextInt();
in.close();
System.out.println(file + " has " + nNodes + " nodes");

ArrayList<Integer> samples = new ArrayList<>();

for (int i = 0; i < accuracySampleSize; i++) {
Random randomGenerator = new Random();
samples.add(randomGenerator.nextInt(nNodes) % nNodes);
samples.add(randomGenerator.nextInt(nNodes) % nNodes);
}

for (int i = 0; i < epsilons.length; i++) {
new EstimateSampler().sample(file, epsilons[i]);
MinCutSolver origin = new MinCutSolver(file, false);
MinCutSolver sampled = new MinCutSolver(file, true);
double avgAccuracy = 0;
for (int t = 0; t < accuracySampleSize; t++) {
Random randomGenerator = new Random();
int src = randomGenerator.nextInt() % nNodes;
int des = randomGenerator.nextInt() % nNodes;
int src = samples.get(2 * t);
int des = samples.get(2 * t + 1);
System.out.println(t + ": (" + src + ", " + des + ")");
int actualMincut = origin.IterativeSolve(src, des);
int sampledMincut = sampled.IterativeSolve(src, des);
double accuracy = 1.0 * Math.abs(actualMincut - sampledMincut) / actualMincut;
Expand Down
7 changes: 2 additions & 5 deletions src/minCut/MinCutSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
public class MinCutSolver {

public static void main(String[] args) throws IOException {
MinCutSolver solver = new MinCutSolver("sample", true);
System.out.println("Min cut is " + solver.IterativeSolve(17899, 16879));
MinCutSolver solver = new MinCutSolver("clique", true);
System.out.println("Min cut is " + solver.IterativeSolve(4, 16));
}

private Graph graph;
Expand Down Expand Up @@ -81,11 +81,8 @@ private static void verifier() throws IOException {

public int IterativeSolve(int source, int dest) {
this.graph.resetGraph();
int total = 0;
int improvement = findResidualIterative(source, dest, new HashMap<>());
while (improvement != Integer.MAX_VALUE) {
total += improvement;
System.out.println("Now is " + total);
improvement = findResidualIterative(source, dest, new HashMap<>());
}

Expand Down

0 comments on commit b9cff21

Please sign in to comment.