org.apache.giraph.graph.Vertex.initialize()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中org.apache.giraph.graph.Vertex.initialize()方法的一些代码示例,展示了Vertex.initialize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex.initialize()方法的具体详情如下:
包路径:org.apache.giraph.graph.Vertex
类名称:Vertex
方法名:initialize

Vertex.initialize介绍

[英]Initialize id and value. Vertex edges will be empty. This method (or the alternative form initialize(id, value, edges)) must be called after instantiation, unless readFields() is called.
[中]初始化id和值。顶点边将为空。除非调用readFields(),否则实例化后必须调用此方法(或替代形式initialize(id、value、edges))。

代码示例

代码示例来源:origin: qcri/Arabesque

  1. @Override
  2. public Vertex<IntWritable, NullWritable, NullWritable> getCurrentVertex() throws IOException, InterruptedException {
  3. Vertex<IntWritable, NullWritable, NullWritable> vertex =
  4. getConf().createVertex();
  5. IntWritable id = new IntWritable(inputSplit.getSplitIndex());
  6. List<Edge<IntWritable, NullWritable>> edges = Collections.emptyList();
  7. vertex.initialize(id, NullWritable.get(), edges);
  8. generated = true;
  9. return vertex;
  10. }

代码示例来源:origin: org.apache.giraph/giraph-examples

  1. @Override
  2. public Vertex<LongWritable, DoubleWritable, NullWritable>
  3. getCurrentVertex() throws IOException, InterruptedException {
  4. Vertex<LongWritable, DoubleWritable, NullWritable>
  5. vertex = conf.createVertex();
  6. String[] tokens =
  7. separator.split(getRecordReader().getCurrentValue().toString());
  8. List<Edge<LongWritable, NullWritable>> edges =
  9. Lists.newArrayListWithCapacity(tokens.length - 1);
  10. for (int n = 1; n < tokens.length; n++) {
  11. edges.add(EdgeFactory.create(
  12. new LongWritable(Long.parseLong(tokens[n])),
  13. NullWritable.get()));
  14. }
  15. LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0]));
  16. vertex.initialize(vertexId, new DoubleWritable(), edges);
  17. return vertex;
  18. }

代码示例来源:origin: org.apache.giraph/giraph-core

  1. /**
  2. * The backing store of the current vertex id is now released.
  3. * Further calls to getCurrentVertexId () without calling next()
  4. * will return null.
  5. *
  6. * @return Current vertex id that was released
  7. */
  8. public I releaseCurrentVertexId() {
  9. I releasedVertexId = vertex.getId();
  10. vertex.initialize(null, vertex.getValue());
  11. return releasedVertexId;
  12. }

代码示例来源:origin: apache/giraph

  1. public void initializeVertex(
  2. Vertex<I, V, E> v, I id, Supplier<V> valueSupplier,
  3. List<Edge<I, E>> edgesList) {
  4. v.initialize(
  5. id,
  6. valueSupplier != null ?
  7. valueSupplier.get() : getConf().createVertexValue(),
  8. edgesList != null ? edgesList : new ArrayList<Edge<I, E>>());
  9. }

代码示例来源:origin: org.apache.giraph/giraph-core

  1. /**
  2. * Create a vertex
  3. *
  4. * @param id the id of the vertex
  5. * @param value the vertex value
  6. * @param edges edges to other vertices
  7. * @return a new vertex
  8. */
  9. protected Vertex<I, V, E> makeVertex(I id, V value,
  10. Entry<I, E>... edges) {
  11. Vertex<I, V, E> vertex = conf.createVertex();
  12. vertex.initialize(id, value, createEdges(edges));
  13. return vertex;
  14. }

代码示例来源:origin: org.apache.giraph/giraph-core

  1. /**
  2. * Add an edge to an existing vertex
  3. *
  4. * @param vertexId Edge origin
  5. * @param edgePair The edge
  6. * @return this
  7. */
  8. public TestGraph<I, V, E> addEdge(I vertexId, Entry<I, E> edgePair) {
  9. if (!vertices.containsKey(vertexId)) {
  10. Vertex<I, V, E> v = conf.createVertex();
  11. v.initialize(vertexId, conf.createVertexValue());
  12. vertices.put(vertexId, v);
  13. }
  14. vertices.get(vertexId)
  15. .addEdge(EdgeFactory.create(edgePair.getKey(),
  16. edgePair.getValue()));
  17. return this;
  18. }

代码示例来源:origin: org.apache.giraph/giraph-examples

  1. @Override
  2. public Vertex<LongWritable, DoubleWritable, FloatWritable>
  3. getCurrentVertex() throws IOException, InterruptedException {
  4. Vertex<LongWritable, DoubleWritable, FloatWritable>
  5. vertex = conf.createVertex();
  6. String[] tokens = neighborSeparator.split(getRecordReader()
  7. .getCurrentValue().toString());
  8. List<Edge<LongWritable, FloatWritable>> edges =
  9. Lists.newArrayListWithCapacity(tokens.length - 1);
  10. for (int n = 1; n < tokens.length; n++) {
  11. String[] parts = weightSeparator.split(tokens[n]);
  12. edges.add(EdgeFactory.create(
  13. new LongWritable(Long.parseLong(parts[0])),
  14. new FloatWritable(Float.parseFloat(parts[1]))));
  15. }
  16. LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0]));
  17. vertex.initialize(vertexId, new DoubleWritable(), edges);
  18. return vertex;
  19. }

代码示例来源:origin: org.apache.giraph/giraph-examples

  1. @Override
  2. public Vertex<LongWritable, DoubleWritable, DoubleWritable>
  3. getCurrentVertex() throws IOException, InterruptedException {
  4. Vertex<LongWritable, DoubleWritable, DoubleWritable>
  5. vertex = conf.createVertex();
  6. String[] tokens =
  7. separator.split(getRecordReader().getCurrentValue().toString());
  8. List<Edge<LongWritable, DoubleWritable>> edges =
  9. Lists.newArrayListWithCapacity(tokens.length - 1);
  10. float weight = 1.0f / (tokens.length - 1);
  11. for (int n = 1; n < tokens.length; n++) {
  12. edges.add(EdgeFactory.create(
  13. new LongWritable(Long.parseLong(tokens[n])),
  14. new DoubleWritable(weight)));
  15. }
  16. LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0]));
  17. vertex.initialize(vertexId, new DoubleWritable(), edges);
  18. return vertex;
  19. }

代码示例来源:origin: org.apache.giraph/giraph-examples

  1. @Override
  2. public Vertex<LongWritable, DoubleWritable, DoubleWritable>
  3. getCurrentVertex() throws IOException, InterruptedException {
  4. Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex =
  5. conf.createVertex();
  6. String[] tokens = edgeSeparator.split(getRecordReader()
  7. .getCurrentValue().toString());
  8. List<Edge<LongWritable, DoubleWritable>> edges = Lists
  9. .newArrayListWithCapacity(tokens.length - 1);
  10. parse(tokens, edges);
  11. normalize(edges);
  12. LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0]));
  13. vertex.initialize(vertexId, new DoubleWritable(), edges);
  14. return vertex;
  15. }

代码示例来源:origin: org.apache.giraph/giraph-core

  1. /**
  2. * Add an edge to an existing vertex
  3. *
  4. * @param vertexId Edge origin
  5. * @param toVertex Edge destination
  6. * @param edgeValue Edge value
  7. * @return this
  8. */
  9. public TestGraph<I, V, E> addEdge(I vertexId, I toVertex, E edgeValue) {
  10. if (!vertices.containsKey(vertexId)) {
  11. Vertex<I, V, E> v = conf.createVertex();
  12. v.initialize(vertexId, conf.createVertexValue());
  13. vertices.put(vertexId, v);
  14. }
  15. vertices.get(vertexId)
  16. .addEdge(EdgeFactory.create(toVertex, edgeValue));
  17. return this;
  18. }
  19. /**

代码示例来源:origin: org.apache.giraph/giraph-examples

  1. @Override
  2. public Vertex<LongWritable, DoubleWritable, FloatWritable>
  3. getCurrentVertex() throws IOException {
  4. Vertex<LongWritable, DoubleWritable, FloatWritable> vertex =
  5. getConf().createVertex();
  6. LongWritable vertexId = new LongWritable(
  7. (inputSplit.getSplitIndex() * totalRecords) + recordsRead);
  8. DoubleWritable vertexValue = new DoubleWritable(vertexId.get() * 10d);
  9. long targetVertexId =
  10. (vertexId.get() + 1) %
  11. (inputSplit.getNumSplits() * totalRecords);
  12. float edgeValue = vertexId.get() * 100f;
  13. List<Edge<LongWritable, FloatWritable>> edges = Lists.newLinkedList();
  14. edges.add(EdgeFactory.create(new LongWritable(targetVertexId),
  15. new FloatWritable(edgeValue)));
  16. vertex.initialize(vertexId, vertexValue, edges);
  17. ++recordsRead;
  18. if (LOG.isInfoEnabled()) {
  19. LOG.info("next: Return vertexId=" + vertex.getId().get() +
  20. ", vertexValue=" + vertex.getValue() +
  21. ", targetVertexId=" + targetVertexId + ", edgeValue=" + edgeValue);
  22. }
  23. return vertex;
  24. }
  25. }

代码示例来源:origin: org.apache.giraph/giraph-core

  1. /**
  2. * Sends a request to create a vertex that will be available during the
  3. * next superstep.
  4. *
  5. * @param id Vertex id
  6. * @param value Vertex value
  7. * @param edges Initial edges
  8. */
  9. @Override
  10. public void addVertexRequest(I id, V value,
  11. OutEdges<I, E> edges) throws IOException {
  12. Vertex<I, V, E> vertex = getConf().createVertex();
  13. vertex.initialize(id, value, edges);
  14. workerClientRequestProcessor.addVertexRequest(vertex);
  15. }

代码示例来源:origin: org.apache.giraph/giraph-core

  1. /**
  2. * Reset the empty Vertex to an initial state.
  3. */
  4. private void resetEmptyVertex() {
  5. vertex = configuration.createVertex();
  6. I id = configuration.createVertexId();
  7. V value = configuration.createVertexValue();
  8. OutEdges<I, E> edges = configuration.createOutEdges();
  9. vertex.initialize(id, value, edges);
  10. }

代码示例来源:origin: org.apache.giraph/giraph-core

  1. @Override
  2. public final Vertex<I, V, Writable> getCurrentVertex() throws IOException,
  3. InterruptedException {
  4. Vertex<I, V, Writable> vertex = getConf().createVertex();
  5. vertex.initialize(getCurrentVertexId(), getCurrentVertexValue());
  6. return vertex;
  7. }
  8. }

代码示例来源:origin: org.apache.giraph/giraph-core

  1. /**
  2. * Moves to the next element in the iteration.
  3. */
  4. public void next() {
  5. // If the vertex was released, create another one
  6. if (vertex == null) {
  7. resetEmptyVertex();
  8. }
  9. // If the vertex id was released, create another one
  10. if (vertex.getId() == null) {
  11. vertex.initialize(configuration.createVertexId(), vertex.getValue());
  12. }
  13. try {
  14. WritableUtils.reinitializeVertexFromDataInput(
  15. extendedDataInput, vertex, configuration);
  16. } catch (IOException e) {
  17. throw new IllegalStateException("next: IOException", e);
  18. }
  19. }

代码示例来源:origin: apache/giraph

  1. /**
  2. * Creates a new Vertex object, without adding it into the graph.
  3. *
  4. * This function is safe to call from multiple threads at the same time,
  5. * and then synchronize only on actual addition of Vertex to the graph
  6. * itself.
  7. */
  8. public Vertex<I, V, E> makeVertex(
  9. Number vertexId, V vertexValue,
  10. Entry<? extends Number, ? extends Number>... edges) {
  11. Vertex<I, V, E> vertex = getConf().createVertex();
  12. List<Edge<I, E>> edgesList = new ArrayList<>();
  13. int i = 0;
  14. for (Entry<? extends Number, ? extends Number> edge: edges) {
  15. edgesList.add(EdgeFactory.create(
  16. numberToVertexId(edge.getKey()),
  17. numberToEdgeValue(edge.getValue())));
  18. i++;
  19. }
  20. vertex.initialize(
  21. numberToVertexId(vertexId),
  22. vertexValue != null ?
  23. vertexValue : getConf().createVertexValue(),
  24. edgesList);
  25. return vertex;
  26. }

代码示例来源:origin: apache/giraph

  1. /**
  2. * Creates a new Vertex object, without adding it into the graph.
  3. *
  4. * This function is safe to call from multiple threads at the same time,
  5. * and then synchronize only on actual addition of Vertex to the graph
  6. * itself.
  7. */
  8. public Vertex<I, V, E> makeVertex(
  9. Number vertexId, Number value,
  10. Number edgeValue, Number... edges) {
  11. Vertex<I, V, E> vertex = getConf().createVertex();
  12. List<Edge<I, E>> edgesList = new ArrayList<>();
  13. for (Number edge: edges) {
  14. edgesList.add(
  15. EdgeFactory.create(numberToVertexId.apply(edge),
  16. numberToEdgeValue(edgeValue)));
  17. }
  18. vertex.initialize(
  19. numberToVertexId.apply(vertexId),
  20. numberToVertexValue(value),
  21. edgesList);
  22. return vertex;
  23. }

代码示例来源:origin: apache/giraph

  1. /**
  2. * Creates a new Vertex object, without adding it into the graph.
  3. *
  4. * This function is safe to call from multiple threads at the same time,
  5. * and then synchronize only on actual addition of Vertex to the graph
  6. * itself.
  7. */
  8. public Vertex<I, V, E> makeVertex(
  9. Number vertexId, V vertexValue,
  10. Supplier<E> edgeSupplier, Number... edges) {
  11. Vertex<I, V, E> vertex = getConf().createVertex();
  12. List<Edge<I, E>> edgesList = new ArrayList<>();
  13. for (Number edge: edges) {
  14. edgesList.add(
  15. EdgeFactory.create(numberToVertexId.apply(edge),
  16. edgeSupplier != null ?
  17. edgeSupplier.get() : getConf().createEdgeValue()));
  18. }
  19. vertex.initialize(
  20. numberToVertexId.apply(vertexId),
  21. vertexValue != null ?
  22. vertexValue : getConf().createVertexValue(),
  23. edgesList);
  24. return vertex;
  25. }

代码示例来源:origin: org.apache.giraph/giraph-core

  1. vertex.initialize(new LongWritable(vertexId),
  2. new DoubleWritable(rnd.nextDouble()), edges);
  3. ++verticesRead;

代码示例来源:origin: org.apache.giraph/giraph-core

  1. @Override
  2. public void initialize(int partitionId, Progressable progressable) {
  3. super.initialize(partitionId, progressable);
  4. vertexMap = new MapMaker().concurrencyLevel(
  5. getConf().getNettyServerExecutionConcurrency()).makeMap();
  6. representativeVertex = getConf().createVertex();
  7. representativeVertex.initialize(
  8. getConf().createVertexId(),
  9. getConf().createVertexValue(),
  10. getConf().createOutEdges());
  11. representativeCombinerVertex = getConf().createVertex();
  12. representativeCombinerVertex.initialize(
  13. getConf().createVertexId(),
  14. getConf().createVertexValue(),
  15. getConf().createOutEdges());
  16. useUnsafeSerialization = getConf().useUnsafeSerialization();
  17. }

相关文章