giraph-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arun Kumar <toga...@gmail.com>
Subject Counting Triangle in giraph
Date Fri, 21 Mar 2014 14:20:38 GMT
Hi

i am working on giraph version1.0 and i have created a TriangleCounting
program based on some previous posts .My program runs with out any error
but it is not giving any relevant data .
for clarity i am attaching the program and the input used .

Can somebody help me in finding the issue?

*The command to invoke the program over hadoop is:*
hadoop jar
/usr/local/giraph/giraph-examples/target/giraph-examples-1.0.0-for-hadoop-1.0.2-jar-with-dependencies.jar
org.apache.giraph.GiraphRunner org.apache.giraph.examples.TriangleCounting
-vif
org.apache.giraph.io.formats.JsonLongDoubleFloatDoubleVertexInputFormat
-vip /user/hduser/inputgraph/tiny_graph.txt -of
org.apache.giraph.io.formats.IdWithValueTextOutputFormat -op
/user/hduser/output/count -w 1
*Inputdata used:*
[0,0,[[1,1],[3,3]]]
[1,0,[[0,1],[2,2],[3,1]]]
[2,0,[[1,2],[4,4]]]
[3,0,[[0,3],[1,1],[4,4]]]

*output got:*
0    0.0
2    0.0
1    0.0
3    0.0
4    0.0
*Program:*

import org.apache.giraph.edge.Edge;
import org.apache.giraph.graph.Vertex;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.log4j.Logger;

import java.io.IOException;

@Algorithm(
    name = "Traingle Counting in Giraph",
    description = "Return the total number of triangle and also enumerates
traingles per vertex"
)
public class TriangleCounting extends Vertex<LongWritable,
DoubleWritable,FloatWritable, DoubleWritable> {

  /** Class logger */
  private static final Logger LOG =
Logger.getLogger(TriangleCounting.class);

  @Override
  public void compute(Iterable<DoubleWritable> messages) throws IOException
{

  /** First Superstep releases messages to vertexIds() whose value is
greater than its value. Both VertexId and Message are double **/
  if (getSuperstep() == 0) {
    for (Edge<LongWritable, FloatWritable> edge:getEdges()) {
      if (edge.getTargetVertexId().compareTo(getId()) == 1) {
      double d=getId().get();
        sendMessage(edge.getTargetVertexId(),new DoubleWritable(d));
        if (LOG.isDebugEnabled()) {
          LOG.debug("Vertex " + getId() + " sent message " + getId() + " to
vertex " + edge.getTargetVertexId());
        }
        System.out.println("Vertex " + getId() + " sent message " + getId()
+ " to vertex " + edge.getTargetVertexId());
      }
    }
  }

  /** Second superstep releases messages to message.get() < vertex.getId()
< targetVertexId() **/
  if (getSuperstep() == 1) {
    for (DoubleWritable message: messages) {
        for (Edge<LongWritable, FloatWritable> edge: getEdges()) {
        double etvid=edge.getTargetVertexId().compareTo(getId()) +
getId().get();
          if (new DoubleWritable(etvid).compareTo(message) == 2) {
            sendMessage(edge.getTargetVertexId(), message);
            if (LOG.isDebugEnabled()) {
              LOG.debug("Vertex " + getId() + " sent message " + message +
" to vertex " + edge.getTargetVertexId());
            }
            System.out.println("Vertex " + getId() + " sent message " +
message + " to vertex " + edge.getTargetVertexId());
          }
        }
    }
  }
  /** Sends messages to all its neighbours, the messages it receives **/
  if (getSuperstep() == 2) {
    for (DoubleWritable message: messages) {
        sendMessageToAllEdges(message);
    }
  }

  if (getSuperstep() == 3) {
      double Value = 0.0;
      for (DoubleWritable message: messages) {
          if (getId().equals(message)) {
              Value += 1.0;
              System.out.println("Vertex " + getId() + " received message "
+ message);
          }
      }
      setValue(new DoubleWritable(Value));
  }

  voteToHalt();
  }
}

Mime
View raw message