用giraph运行程序

时间:2016-10-10 10:45:25

标签: java hadoop giraph

我正在尝试运行图形算法的示例但我收到的错误是找不到basicComputation,但在我的代码中我导入了BasicComputation

import org.apache.giraph.Algorithm;
import org.apache.giraph.graph.BasicComputation;
import org.apache.giraph.conf.LongConfOption;
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;
/**
 * Demonstrates the basic Pregel shortest paths implementation.
 */
@Algorithm(
    name = "Shortest paths",
    description = "Finds all shortest paths from a selected vertex"
)
public class SimpleShortestPathsComputation extends BasicComputation<
    LongWritable, DoubleWritable, FloatWritable, DoubleWritable> {
  /** The shortest paths id */
  public static final LongConfOption SOURCE_ID =
      new LongConfOption("SimpleShortestPathsVertex.sourceId", 1, null);
  /** Class logger */
  private static final Logger LOG =
          Logger.getLogger(SimpleShortestPathsComputation.class);
  /**
   * Is this vertex the source id?
   *
   * @param vertex Vertex
   * @return True if the source id
   */
  private boolean isSource(Vertex<LongWritable, ?, ?> vertex) {
    return vertex.getId().get() == SOURCE_ID.get(getConf());
  }
  @Override
  public void compute(
      Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
      Iterable<DoubleWritable> messages) throws IOException {
    if (getSuperstep() == 0) {
      vertex.setValue(new DoubleWritable(Double.MAX_VALUE));
    }
    double minDist = isSource(vertex) ? 0d : Double.MAX_VALUE;
    for (DoubleWritable message : messages) {
      minDist = Math.min(minDist, message.get());
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug("Vertex " + vertex.getId() + " got minDist = " + minDist +
          " vertex value = " + vertex.getValue());
    }
    if (minDist < vertex.getValue().get()) {
      vertex.setValue(new DoubleWritable(minDist));
      for (Edge<LongWritable, FloatWritable> edge : vertex.getEdges()) {
        double distance = minDist + edge.getValue().get();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Vertex " + vertex.getId() + " sent to " +
                edge.getTargetVertexId() + " = " + distance);
          }
          sendMessage(edge.getTargetVertexId(), new DoubleWritable(distance));
        }
      }
      vertex.voteToHalt();
    }
  }

我用来运行程序的命令:

root@salma-SATELLITE-C855-1EQ:/usr/local/hadoop# ./bin/hadoop jar /root/workspace/projet_stage/target/projet_stage-0.0.1-SNAPSHOT.jar projet.SimpleShortestPathsComputation -vif org.apache.giraph.io.formats.JsonLongDoubleFloatDoubleVertexInputFormat -vip /in/in -of org.apache.giraph.io.formats.IdWithValueTextOutputFormat -op /outsimpleshortpath -w 2 -mc 

错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/giraph/graph/BasicComputation

0 个答案:

没有答案