Skip to content

Commit

Permalink
[gelly] Added Algorithm string to the library methods
Browse files Browse the repository at this point in the history
  • Loading branch information
andralungu committed May 16, 2015
1 parent dfa0f78 commit 949b529
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import org.apache.flink.graph.Graph;
import org.apache.flink.graph.Vertex;
import org.apache.flink.graph.example.utils.CommunityDetectionData;
import org.apache.flink.graph.library.SimpleCommunityDetection;
import org.apache.flink.graph.library.CommunityDetectionAlgorithm;
import org.apache.flink.graph.utils.Tuple3ToEdgeMap;

/**
* This example shows how to use the {@link org.apache.flink.graph.library.SimpleCommunityDetection}
* This example shows how to use the {@link org.apache.flink.graph.library.CommunityDetectionAlgorithm}
* library method:
* <ul>
* <li> with the edge data set given as a parameter
Expand All @@ -43,12 +43,12 @@
* For example: <code>1\t2\t1.0\n1\t3\t2.0\n</code> defines two edges,
* 1-2 with weight 1.0 and 1-3 with weight 2.0.
*
* Usage <code>SimpleCommunityDetection &lt;edge path&gt; &lt;result path&gt;
* Usage <code>CommunityDetection &lt;edge path&gt; &lt;result path&gt;
* &lt;number of iterations&gt; &lt;delta&gt;</code><br>
* If no parameters are provided, the program is run with default data from
* {@link org.apache.flink.graph.example.utils.CommunityDetectionData}
*/
public class CommunityDetectionExample implements ProgramDescription {
public class CommunityDetection implements ProgramDescription {

@SuppressWarnings("serial")
public static void main(String [] args) throws Exception {
Expand All @@ -73,7 +73,7 @@ public Long map(Long label) throws Exception {
// the result is in the form of <vertexId, communityId>, where the communityId is the label
// which the vertex converged to
DataSet<Vertex<Long, Long>> communityVertices =
graph.run(new SimpleCommunityDetection(maxIterations, delta)).getVertices();
graph.run(new CommunityDetectionAlgorithm(maxIterations, delta)).getVertices();

// emit result
if (fileOutput) {
Expand All @@ -82,12 +82,12 @@ public Long map(Long label) throws Exception {
communityVertices.print();
}

env.execute("Executing Simple Community Detection Example");
env.execute("Executing Community Detection Example");
}

@Override
public String getDescription() {
return "Simple Community Detection";
return "Community Detection";
}

// *************************************************************************
Expand All @@ -103,7 +103,7 @@ public String getDescription() {
private static boolean parseParameters(String [] args) {
if(args.length > 0) {
if(args.length != 4) {
System.err.println("Usage SimpleCommunityDetection <edge path> <output path> " +
System.err.println("Usage CommunityDetection <edge path> <output path> " +
"<num iterations> <delta>");
return false;
}
Expand All @@ -117,7 +117,7 @@ private static boolean parseParameters(String [] args) {
} else {
System.out.println("Executing SimpleCommunityDetection example with default parameters and built-in default data.");
System.out.println("Provide parameters to read input data from files.");
System.out.println("Usage SimpleCommunityDetection <edge path> <output path> " +
System.out.println("Usage CommunityDetection <edge path> <output path> " +
"<num iterations> <delta>");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import org.apache.flink.graph.Edge;
import org.apache.flink.graph.Graph;
import org.apache.flink.graph.Vertex;
import org.apache.flink.graph.example.utils.ConnectedComponentsExampleData;
import org.apache.flink.graph.library.ConnectedComponents;
import org.apache.flink.graph.example.utils.ConnectedComponentsDefaultData;
import org.apache.flink.graph.library.ConnectedComponentsAlgorithm;
import org.apache.flink.types.NullValue;

/**
* This example shows how to use the {@link org.apache.flink.graph.library.ConnectedComponents}
* This example shows how to use the {@link org.apache.flink.graph.library.ConnectedComponentsAlgorithm}
* library method:
* <ul>
* <li> with the edge data set given as a parameter
Expand All @@ -47,9 +47,9 @@
* Usage <code>ConnectedComponents &lt;edge path&gt; &lt;result path&gt;
* &lt;number of iterations&gt; </code><br>
* If no parameters are provided, the program is run with default data from
* {@link org.apache.flink.graph.example.utils.ConnectedComponentsExampleData}
* {@link org.apache.flink.graph.example.utils.ConnectedComponentsDefaultData}
*/
public class ConnectedComponentsExample implements ProgramDescription {
public class ConnectedComponents implements ProgramDescription {

@SuppressWarnings("serial")
public static void main(String [] args) throws Exception {
Expand All @@ -70,7 +70,7 @@ public Long map(Long value) throws Exception {
}, env);

DataSet<Vertex<Long, Long>> verticesWithMinIds = graph
.run(new ConnectedComponents(maxIterations)).getVertices();
.run(new ConnectedComponentsAlgorithm(maxIterations)).getVertices();

// emit result
if (fileOutput) {
Expand All @@ -94,7 +94,7 @@ public String getDescription() {
private static boolean fileOutput = false;
private static String edgeInputPath = null;
private static String outputPath = null;
private static Integer maxIterations = ConnectedComponentsExampleData.MAX_ITERATIONS;
private static Integer maxIterations = ConnectedComponentsDefaultData.MAX_ITERATIONS;

private static boolean parseParameters(String [] args) {
if(args.length > 0) {
Expand Down Expand Up @@ -135,7 +135,7 @@ public Edge<Long, NullValue> map(Tuple2<Long, Long> value) throws Exception {
}
});
} else {
return ConnectedComponentsExampleData.getDefaultEdgeDataSet(env);
return ConnectedComponentsDefaultData.getDefaultEdgeDataSet(env);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.flink.graph.Edge;
import org.apache.flink.graph.Graph;
import org.apache.flink.graph.Vertex;
import org.apache.flink.graph.library.LabelPropagation;
import org.apache.flink.graph.library.LabelPropagationAlgorithm;
import org.apache.flink.graph.utils.Tuple2ToVertexMap;
import org.apache.flink.types.NullValue;
import org.apache.flink.util.Collector;
Expand All @@ -48,7 +48,7 @@
*
* If no arguments are provided, the example runs with a random graph of 100 vertices.
*/
public class LabelPropagationExample implements ProgramDescription {
public class LabelPropagation implements ProgramDescription {

public static void main(String[] args) throws Exception {

Expand All @@ -67,7 +67,7 @@ public static void main(String[] args) throws Exception {

// Set up the program
DataSet<Vertex<Long, Long>> verticesWithCommunity = graph.run(
new org.apache.flink.graph.library.LabelPropagation<Long>(maxIterations)).getVertices();
new LabelPropagationAlgorithm<Long>(maxIterations)).getVertices();

// Emit results
if(fileOutput) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.apache.flink.graph.Graph;
import org.apache.flink.graph.Vertex;
import org.apache.flink.graph.example.utils.MusicProfilesData;
import org.apache.flink.graph.library.LabelPropagation;
import org.apache.flink.graph.library.LabelPropagationAlgorithm;
import org.apache.flink.types.NullValue;
import org.apache.flink.util.Collector;

Expand Down Expand Up @@ -140,7 +140,7 @@ public Long map(String value) {
public Long map(Tuple2<Long, Long> value) {
return value.f1;
}
}).run(new LabelPropagation<String>(maxIterations))
}).run(new LabelPropagationAlgorithm<String>(maxIterations))
.getVertices();

if (fileOutput) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.flink.graph.Edge;
import org.apache.flink.graph.Graph;
import org.apache.flink.graph.Vertex;
import org.apache.flink.graph.library.PageRank;
import org.apache.flink.graph.library.PageRankAlgorithm;
import org.apache.flink.graph.utils.Tuple3ToEdgeMap;
import org.apache.flink.util.Collector;

Expand All @@ -41,7 +41,7 @@
* and random edge weights.
*
*/
public class PageRankExample implements ProgramDescription {
public class PageRank implements ProgramDescription {

@SuppressWarnings("serial")
public static void main(String[] args) throws Exception {
Expand Down Expand Up @@ -73,7 +73,7 @@ public Double map(Tuple2<Double, Long> value) {
});

DataSet<Vertex<Long, Double>> pageRanks = networkWithWeights.run(
new PageRank<Long>(DAMPENING_FACTOR, maxIterations))
new PageRankAlgorithm<Long>(DAMPENING_FACTOR, maxIterations))
.getVertices();

if (fileOutput) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.flink.graph.Graph;
import org.apache.flink.graph.Vertex;
import org.apache.flink.graph.example.utils.SingleSourceShortestPathsData;
import org.apache.flink.graph.library.SingleSourceShortestPaths;
import org.apache.flink.graph.library.SingleSourceShortestPathsAlgorithm;
import org.apache.flink.graph.utils.Tuple3ToEdgeMap;

/**
Expand All @@ -40,7 +40,7 @@
* If no arguments are provided, the example runs with default data from {@link SingleSourceShortestPathsData}.
*
*/
public class SingleSourceShortestPathsExample implements ProgramDescription {
public class SingleSourceShortestPaths implements ProgramDescription {

@SuppressWarnings("serial")
public static void main(String[] args) throws Exception {
Expand All @@ -62,7 +62,7 @@ public Double map(Long value) {
}, env);

DataSet<Vertex<Long, Double>> singleSourceShortestPaths = graph
.run(new org.apache.flink.graph.library.SingleSourceShortestPaths<Long>(srcVertexId, maxIterations))
.run(new SingleSourceShortestPathsAlgorithm<Long>(srcVertexId, maxIterations))
.getVertices();

// emit result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Provides the default data sets used for the connected components example program.
* If no parameters are given to the program, the default data sets are used.
*/
public class ConnectedComponentsExampleData {
public class ConnectedComponentsDefaultData {

public static final Integer MAX_ITERATIONS = 4;

Expand All @@ -48,5 +48,5 @@ public static DataSet<Edge<Long, NullValue>> getDefaultEdgeDataSet(ExecutionEnvi

public static final String VERTICES_WITH_MIN_ID = "1,1\n" + "2,1\n" + "3,1\n" + "4,1";

private ConnectedComponentsExampleData() {}
private ConnectedComponentsDefaultData() {}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.util.TreeMap;

/**
* Simple Community Detection Algorithm.
* Community Detection Algorithm.
*
* Initially, each vertex is assigned a tuple formed of its own id along with a score equal to 1.0, as value.
* The vertices propagate their labels and max scores in iterations, each time adopting the label with the
Expand All @@ -44,13 +44,13 @@
*
* @see <a href="http://arxiv.org/pdf/0808.2633.pdf">article explaining the algorithm in detail</a>
*/
public class SimpleCommunityDetection implements GraphAlgorithm<Long, Long, Double> {
public class CommunityDetectionAlgorithm implements GraphAlgorithm<Long, Long, Double> {

private Integer maxIterations;

private Double delta;

public SimpleCommunityDetection(Integer maxIterations, Double delta) {
public CommunityDetectionAlgorithm(Integer maxIterations, Double delta) {

this.maxIterations = maxIterations;
this.delta = delta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
* is reached.
*/
@SuppressWarnings("serial")
public class ConnectedComponents implements GraphAlgorithm<Long, Long, NullValue>{
public class ConnectedComponentsAlgorithm implements GraphAlgorithm<Long, Long, NullValue>{

private Integer maxIterations;

public ConnectedComponents(Integer maxIterations) {
public ConnectedComponentsAlgorithm(Integer maxIterations) {
this.maxIterations = maxIterations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.flink.graph.spargel.VertexUpdateFunction;
import org.apache.flink.types.NullValue;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -40,11 +41,13 @@
*
*/
@SuppressWarnings("serial")
public class LabelPropagation<K> implements GraphAlgorithm<K, Long, NullValue> {

public class LabelPropagationAlgorithm<K extends Comparable<K> & Serializable>
implements GraphAlgorithm<K, Long, NullValue> {

private final int maxIterations;

public LabelPropagation(int maxIterations) {
public LabelPropagationAlgorithm(int maxIterations) {
this.maxIterations = maxIterations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
import org.apache.flink.graph.spargel.MessagingFunction;
import org.apache.flink.graph.spargel.VertexUpdateFunction;

public class PageRank<K> implements GraphAlgorithm<K, Double, Double> {
import java.io.Serializable;


public class PageRankAlgorithm<K extends Comparable<K> & Serializable> implements
GraphAlgorithm<K, Double, Double> {

private double beta;
private int maxIterations;

public PageRank(double beta, int maxIterations) {
public PageRankAlgorithm(double beta, int maxIterations) {
this.beta = beta;
this.maxIterations = maxIterations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@
import org.apache.flink.graph.spargel.MessagingFunction;
import org.apache.flink.graph.spargel.VertexUpdateFunction;

import java.io.Serializable;

@SuppressWarnings("serial")
public class SingleSourceShortestPaths<K> implements GraphAlgorithm<K, Double, Double> {
public class SingleSourceShortestPathsAlgorithm<K extends Comparable<K> & Serializable>
implements GraphAlgorithm<K, Double, Double> {

private final K srcVertexId;
private final Integer maxIterations;

public SingleSourceShortestPaths(K srcVertexId, Integer maxIterations) {
public SingleSourceShortestPathsAlgorithm(K srcVertexId, Integer maxIterations) {
this.srcVertexId = srcVertexId;
this.maxIterations = maxIterations;
}
Expand Down

0 comments on commit 949b529

Please sign in to comment.