Differential D4028 Diff 14692 java/src/main/java/org/softwareheritage/graph/experiments/topology/ClusteringCoefficient.java
Changeset View
Changeset View
Standalone View
Standalone View
java/src/main/java/org/softwareheritage/graph/experiments/topology/ClusteringCoefficient.java
package org.softwareheritage.graph.experiments.topology; | package org.softwareheritage.graph.experiments.topology; | ||||
import ch.qos.logback.classic.Level; | import ch.qos.logback.classic.Level; | ||||
import ch.qos.logback.classic.Logger; | import ch.qos.logback.classic.Logger; | ||||
import com.martiansoftware.jsap.*; | import com.martiansoftware.jsap.*; | ||||
import it.unimi.dsi.big.webgraph.ImmutableGraph; | import it.unimi.dsi.big.webgraph.ImmutableGraph; | ||||
import it.unimi.dsi.big.webgraph.LazyLongIterator; | import it.unimi.dsi.big.webgraph.LazyLongIterator; | ||||
import it.unimi.dsi.big.webgraph.Transform; | |||||
import it.unimi.dsi.logging.ProgressLogger; | import it.unimi.dsi.logging.ProgressLogger; | ||||
import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
import org.softwareheritage.graph.Graph; | import org.softwareheritage.graph.Graph; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.*; | import java.util.*; | ||||
import java.util.concurrent.ThreadLocalRandom; | import java.util.concurrent.ThreadLocalRandom; | ||||
public class ClusteringCoefficient { | public class ClusteringCoefficient { | ||||
private Graph graph; | private Graph graph; | ||||
private void load_graph(String graphBasename) throws IOException { | private void load_graph(String graphBasename) throws IOException { | ||||
System.err.println("Loading graph " + graphBasename + " ..."); | System.err.println("Loading graph " + graphBasename + " ..."); | ||||
this.graph = new Graph(graphBasename).symmetrize(); | this.graph = new Graph(graphBasename).symmetrize(); | ||||
System.err.println("Graph loaded."); | System.err.println("Graph loaded."); | ||||
} | } | ||||
private static JSAPResult parse_args(String[] args) { | private static JSAPResult parse_args(String[] args) { | ||||
JSAPResult config = null; | JSAPResult config = null; | ||||
try { | try { | ||||
SimpleJSAP jsap = new SimpleJSAP( | SimpleJSAP jsap = new SimpleJSAP(ClusteringCoefficient.class.getName(), "", | ||||
ClusteringCoefficient.class.getName(), | |||||
"", | |||||
new Parameter[]{ | new Parameter[]{ | ||||
new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, | new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'g', | ||||
'g', "graph", "Basename of the compressed graph"), | "graph", "Basename of the compressed graph"), | ||||
new FlaggedOption("outdir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, | new FlaggedOption("outdir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'o', | ||||
'o', "outdir", "Directory where to put the results"), | "outdir", "Directory where to put the results"),}); | ||||
} | |||||
); | |||||
config = jsap.parse(args); | config = jsap.parse(args); | ||||
if (jsap.messagePrinted()) { | if (jsap.messagePrinted()) { | ||||
System.exit(1); | System.exit(1); | ||||
} | } | ||||
} catch (JSAPException e) { | } catch (JSAPException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | public void compute_approx(Formatter out_global) { | ||||
while ((succ = u_iterator.nextLong()) != -1) { | while ((succ = u_iterator.nextLong()) != -1) { | ||||
if (succ == v) | if (succ == v) | ||||
triangles++; | triangles++; | ||||
} | } | ||||
} | } | ||||
trials++; | trials++; | ||||
if (trials % 100 == 0 || true) { | if (trials % 100 == 0 || true) { | ||||
double gC = (double)triangles / (double)trials; | double gC = (double) triangles / (double) trials; | ||||
out_global.format("C: %f (triangles: %d, trials: %d)\n", gC, triangles, trials); | out_global.format("C: %f (triangles: %d, trials: %d)\n", gC, triangles, trials); | ||||
System.out.format("C: %f (triangles: %d, trials: %d)\n", gC, triangles, trials); | System.out.format("C: %f (triangles: %d, trials: %d)\n", gC, triangles, trials); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public static void main(String[] args) { | public static void main(String[] args) { | ||||
JSAPResult config = parse_args(args); | JSAPResult config = parse_args(args); | ||||
Show All 10 Lines | public static void main(String[] args) { | ||||
} | } | ||||
Logger rootLogger = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); | Logger rootLogger = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); | ||||
rootLogger.setLevel(Level.DEBUG); | rootLogger.setLevel(Level.DEBUG); | ||||
new File(outdirPath).mkdirs(); | new File(outdirPath).mkdirs(); | ||||
try { | try { | ||||
ccoef.compute_approx( | ccoef.compute_approx(new Formatter(outdirPath + "/local.txt")); | ||||
new Formatter(outdirPath + "/local.txt") | |||||
); | |||||
/* | /* | ||||
ccoef.compute( | * ccoef.compute( symmetric, new ProgressLogger(rootLogger), new Formatter(outdirPath + | ||||
symmetric, | * "/local.txt"), new Formatter(outdirPath + "/global.txt") ); | ||||
new ProgressLogger(rootLogger), | |||||
new Formatter(outdirPath + "/local.txt"), | |||||
new Formatter(outdirPath + "/global.txt") | |||||
); | |||||
*/ | */ | ||||
} catch (FileNotFoundException e) { | } catch (FileNotFoundException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
} | } | ||||
} | } |