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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package ml.grafos.okapi.iFub;

import java.io.IOException;
import java.util.regex.Pattern;

import org.apache.giraph.io.EdgeReader;
import org.apache.giraph.io.formats.TextEdgeInputFormat;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.TaskAttemptContext;

public class LongLongEdgesListInputFormat extends
TextEdgeInputFormat<LongWritable, NullWritable> {
/** Splitter for endpoints */
private static final Pattern SEPARATOR = Pattern.compile("[\001\t ]");

@Override
public EdgeReader<LongWritable, NullWritable> createEdgeReader(
InputSplit split, TaskAttemptContext context)
throws IOException {
return new LongLongEdgesReader();
}

public class LongLongEdgesReader extends
TextEdgeReaderFromEachLineProcessed<String[]> {
@Override
protected String[] preprocessLine(Text line) throws IOException {
return SEPARATOR.split(line.toString());
}

@Override
protected LongWritable getSourceVertexId(String[] endpoints)
throws IOException {
return new LongWritable(Long.parseLong(endpoints[0]));
}

@Override
protected LongWritable getTargetVertexId(String[] endpoints)
throws IOException {
return new LongWritable(Long.parseLong(endpoints[1]));
}

@Override
protected NullWritable getValue(String[] endpoints) throws IOException {

return NullWritable.get();
}
}
}
47 changes: 47 additions & 0 deletions src/main/java/ml/grafos/okapi/iFub/MaxDegreeComputation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Inria Sophia Antipolis - Team COATI - 2015
* @author Flavian Jacquot
*
*/
package ml.grafos.okapi.iFub;

import java.io.IOException;

import org.apache.giraph.graph.BasicComputation;
import org.apache.giraph.graph.Vertex;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.log4j.Logger;
/*
* This class simply aggregate the degrees with a maxLong aggregator
* and aggregate the id of vertices with maximum degree.
*/
public class MaxDegreeComputation extends BasicComputation<LongWritable, iFubVertexValue, NullWritable, IntWritable>{
private Logger LOG = Logger.getLogger(MaxDegreeComputation.class);
int maxDegree=1;
boolean sourceFound = false;
@Override
public void preSuperstep() {
super.preSuperstep();
maxDegree=(int)((LongWritable)getAggregatedValue(iFubMasterCompute.MAX_DEGREE)).get();
}

@Override
public void compute(
Vertex<LongWritable, iFubVertexValue, NullWritable> vertex,
Iterable<IntWritable> messages) throws IOException {
if(getSuperstep()==0)
aggregate(iFubMasterCompute.MAX_DEGREE, new LongWritable(vertex.getNumEdges()));
else
{
if(vertex.getNumEdges()==maxDegree&&!sourceFound)
{
sourceFound=true;
LOG.info("Source FOUND ! "+vertex.getId());
aggregate(iFubMasterCompute.SOURCE_ID, new LongWritable(vertex.getId().get()));
}
}
}

}
27 changes: 27 additions & 0 deletions src/main/java/ml/grafos/okapi/iFub/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Inria Sophia Antipolis - Team COATI - 2015 - Flavian Jacquot

This folder contains an implementation of the iFub algorithm : an exact algorithm to compute the diameter of undirected graphs.
It's described in an article at http://www.sciencedirect.com/science/article/pii/S0304397512008687

I've tried it on several graphs from http://snap.stanford.edu/data/ :
com-amazon ~1M edges
com-Friendster ~2B edges

In this folder you can found formats to make an undirected graph.
The master compute iFubMasterCompute must be declared in the giraph job command with -mc :

Example :

COMPUTE_CLASS="ml.graphos.okapi.iFub.iFubBFSCompute -mc ml.graphos.okapi.iFub.iFubMasterCompute"
EIF=ml.graphos.okapi.iFub.iFubInputToUndirected
EIP=data/com-amazon.ungraph.txt
VOF=org.apache.giraph.io.formats.IdWithValueTextOutputFormat
OP=output/FS30G.UN.txt
WORKER=8

$HADOOP_HOME/bin/hadoop jar $GIRAPH_JAR org.apache.giraph.GiraphRunner $COMPUTE_CLASS -eif $EIF -eip $EIP -vof $VOF -op $OP -w $WORKER

The result is printed as a counter in the job trace.
The number of BFS is also printed.

For any question you can contact me at tki1.50@gmail.com
22 changes: 22 additions & 0 deletions src/main/java/ml/grafos/okapi/iFub/README~
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Inria Sophia Antipolis - Team COATI - 2015 - Flavian Jacquot

This folder contains an implementation of the iFub algorithm : an exact algorithm to compute the diameter of undirected graphs.
It's described in an article at http://www.sciencedirect.com/science/article/pii/S0304397512008687

I've tried it on several graphs from http://snap.stanford.edu/data/ :
com-amazon ~1M edges
com-Friendster ~2B edges

In this folder you can found formats to make an undirected graph.
The master compute iFubMasterCompute must be declared in the giraph job command with -mc :

Example :

COMPUTE_CLASS="ml.graphos.okapi.iFub.iFubBFSCompute -mc ml.graphos.okapi.iFub.iFubMasterCompute"
EIF=ml.graphos.okapi.iFub.iFubInputToUndirected
EIP=data/com-amazon.ungraph.txt
VOF=org.apache.giraph.io.formats.IdWithValueTextOutputFormat
OP=output/FS30G.UN.txt
WORKER=8

$HADOOP_HOME/bin/hadoop jar $GIRAPH_JAR org.apache.giraph.GiraphRunner $COMPUTE_CLASS -eif $EIF -eip $EIP -vof $VOF -op $OP -w $WORKER
34 changes: 34 additions & 0 deletions src/main/java/ml/grafos/okapi/iFub/ToUndirected.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ml.grafos.okapi.iFub;

import java.io.IOException;

import org.apache.giraph.edge.EdgeFactory;
import org.apache.giraph.graph.BasicComputation;
import org.apache.giraph.graph.Vertex;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;

public class ToUndirected extends BasicComputation<LongWritable, NullWritable, NullWritable, LongWritable>{

@Override
public void compute(Vertex<LongWritable, NullWritable, NullWritable> vertex, Iterable<LongWritable> inbox) throws IOException {
// TODO Auto-generated method stub
if(getSuperstep()==0)
{
sendMessageToAllEdges(vertex, vertex.getId());
}
else if(getSuperstep()==1)
{
for(LongWritable sourceId : inbox)
{
if(vertex.getEdgeValue(sourceId)==null)
{
vertex.addEdge(EdgeFactory.create(sourceId));
}
}
}
vertex.voteToHalt();

}

}
27 changes: 27 additions & 0 deletions src/main/java/ml/grafos/okapi/iFub/iFubAssignLayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Inria Sophia Antipolis - Team COATI - 2015
* @author Flavian Jacquot
*
*/
package ml.grafos.okapi.iFub;
/*
* This class is used to assign the layer of every vertex and reset the source flag
*/
import java.io.IOException;

import org.apache.giraph.graph.BasicComputation;
import org.apache.giraph.graph.Vertex;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;

public class iFubAssignLayer extends BasicComputation<LongWritable, iFubVertexValue, NullWritable, IntWritable> {


@Override
public void compute(Vertex<LongWritable, iFubVertexValue, NullWritable> vertex, Iterable<IntWritable> arg1) throws IOException {
vertex.getValue().setLayer(vertex.getValue().getDistance());
vertex.getValue().setSource(false);
}

}
79 changes: 79 additions & 0 deletions src/main/java/ml/grafos/okapi/iFub/iFubBFSCompute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Inria Sophia Antipolis - Team COATI - 2015
* @author Flavian Jacquot
*
*/
package ml.grafos.okapi.iFub;

import java.io.IOException;

import org.apache.giraph.edge.Edge;
import org.apache.giraph.graph.BasicComputation;
import org.apache.giraph.graph.Vertex;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
/*
* This class is a version of BFS used in iFub.
* There is a cache for the sourceID and the current BFS step=distance from source
* The method propagateDistance update the aggregators for the iFub Algorithm
*/
public class iFubBFSCompute extends BasicComputation<LongWritable, iFubVertexValue, NullWritable, IntWritable>{
private long Source_ID;
private long bfsStep;

private boolean isSource(
Vertex<LongWritable, iFubVertexValue, NullWritable> vertex) {
return vertex.getId().get() == Source_ID;
}
@Override
public void preSuperstep() {
// TODO Auto-generated method stub
super.preSuperstep();
this.bfsStep = ((LongWritable)getAggregatedValue(iFubMasterCompute.BFS_STEP)).get();
if(bfsStep==0)
this.Source_ID = ((LongWritable)getAggregatedValue(iFubMasterCompute.SOURCE_ID)).get();
}
@Override
public void compute(
Vertex<LongWritable, iFubVertexValue, NullWritable> vertex,
Iterable<IntWritable> messages) throws IOException {

if (bfsStep==0) {
if(vertex.getValue()==null)
{
vertex.setValue(new iFubVertexValue());
}

vertex.getValue().setDistance(Long.MAX_VALUE);
if (isSource(vertex)) {
vertex.getValue().setSource(true);
propagateDistance(vertex);
}

}
else
{
if (messages.iterator().hasNext()
&& vertex.getValue().getDistance() == Long.MAX_VALUE) {
propagateDistance(vertex);
}
}
}

private void propagateDistance(
Vertex<LongWritable, iFubVertexValue, NullWritable> vertex)
throws IOException {
aggregate(iFubMasterCompute.NUM_ACTIVE_VERTEX, new LongWritable(1));

aggregate(iFubMasterCompute.LOWER_B,new LongWritable(bfsStep));
vertex.getValue().setDistance(bfsStep);
sendMessageToAllEdges(vertex, new IntWritable(0));
for(Edge<LongWritable,NullWritable> arrete : vertex.getEdges())
{
sendMessage(arrete.getTargetVertexId(), new IntWritable(1));
}
}


}
54 changes: 54 additions & 0 deletions src/main/java/ml/grafos/okapi/iFub/iFubInputToUndirected.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Inria Sophia Antipolis - Team COATI - 2015
* @author Flavian Jacquot
*
*/
package ml.grafos.okapi.iFub;

import org.apache.giraph.io.EdgeReader;
import org.apache.giraph.io.ReverseEdgeDuplicator;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.TaskAttemptContext;

import cutGraph.LongLongEdgesListInputFormat;

import java.io.IOException;

/**
* Simple text-based {@link org.apache.giraph.io.EdgeInputFormat} for
* unweighted graphs with long ids.
*
* Each line consists of: source_vertex target_vertex
*
* This version also creates the reverse edges.
*/
public class iFubInputToUndirected
extends LongLongEdgesListInputFormat {
@Override
public EdgeReader<LongWritable, NullWritable> createEdgeReader(
InputSplit split, TaskAttemptContext context) throws IOException {
EdgeReader<LongWritable, NullWritable> edgeReader =
super.createEdgeReader(split, context);
edgeReader.setConf(getConf());
return new ReverseEdgeDuplicator<LongWritable, NullWritable>(edgeReader);
}
}
Loading