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

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

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

Vertex.getEdgeValue介绍

[英]Return the value of the first edge with the given target vertex id, or null if there is no such edge. Note: edge value objects returned by this method may be invalidated by the next call. Thus, keeping a reference to an edge value almost always leads to undesired behavior.
[中]返回具有给定目标顶点id的第一条边的值,如果没有这样的边,则返回null。注意:此方法返回的边值对象可能会在下次调用时失效。因此,保留对边值的引用几乎总是会导致不希望的行为。

代码示例

代码示例来源:origin: grafos-ml/okapi

  1. @Override
  2. public void compute(Vertex<WritableComparable, Writable, Writable> vertex,
  3. Iterable<WritableComparable> messages) throws IOException {
  4. int count = 0;
  5. for (WritableComparable msg : messages) {
  6. // If this vertex has a neighbor with this ID, then this means it
  7. // participates in a triangle.
  8. if (vertex.getEdgeValue(msg)!=null) {
  9. count++;
  10. }
  11. }
  12. if (count>0) {
  13. vertex.setValue(new IntWritable(count));
  14. }
  15. vertex.voteToHalt();
  16. }
  17. }

代码示例来源:origin: grafos-ml/okapi

  1. private void updateNeighborsPartitions(
  2. Vertex<LongWritable, VertexValue, EdgeValue> vertex,
  3. Iterable<PartitionMessage> messages) {
  4. for (PartitionMessage message : messages) {
  5. LongWritable otherId = new LongWritable(message.getSourceId());
  6. EdgeValue oldValue = vertex.getEdgeValue(otherId);
  7. vertex.setEdgeValue(
  8. otherId,
  9. new EdgeValue(message.getPartition(), oldValue
  10. .getWeight()));
  11. }
  12. }

代码示例来源:origin: grafos-ml/okapi

  1. @Override
  2. public void compute(Vertex<LongWritable, NullWritable, DoubleBooleanPair> vertex,
  3. Iterable<LongWritable> messages) throws IOException {
  4. // handle set-semimetric-label messages
  5. for (LongWritable trg: messages) {
  6. if (vertex.getEdgeValue(trg) != null) {
  7. vertex.setEdgeValue(trg, vertex.getEdgeValue(trg).setSemimetric(true));
  8. }
  9. }
  10. for (Edge<LongWritable, DoubleBooleanPair> edge : vertex.getEdges()) {
  11. if (edge.getValue().isSemimetric()) {
  12. // remove edge
  13. removeEdgesRequest(vertex.getId(), edge.getTargetVertexId());
  14. }
  15. }
  16. }
  17. }

代码示例来源:origin: grafos-ml/okapi

  1. private void processUpdates(Vertex<LongWritable, IntWritable, MBMEdgeValue> vertex, Iterable<MBMMessage> messages) throws AssertionError {
  2. Set<LongWritable> toRemove = new HashSet<LongWritable>();
  3. int numIncluded = 0;
  4. for (MBMMessage msg : messages) {
  5. MBMEdgeValue edgeValue = vertex.getEdgeValue(msg.getId());
  6. if (edgeValue == null) {
  7. // edge has already been removed, do nothing
  8. if (LOG.isDebugEnabled())
  9. LOG.debug(String.format("Superstep %d Vertex %d: message for removed edge from vertex %d", getSuperstep(), vertex.getId().get(), msg
  10. .getId().get()));
  11. } else {
  12. if (msg.getState() == State.PROPOSED && edgeValue.getState() == State.PROPOSED) {
  13. edgeValue.setState(State.INCLUDED);
  14. numIncluded++;
  15. } else if (msg.getState() == State.REMOVED) {
  16. toRemove.add(msg.getId());
  17. }
  18. }
  19. }
  20. // update capacity
  21. vertex.getValue().set(vertex.getValue().get() - numIncluded);
  22. // remove edges locally
  23. for (LongWritable e : toRemove)
  24. vertex.removeEdges(e);
  25. if (LOG.isDebugEnabled())
  26. LOG.debug(String.format("Superstep %d Vertex %d: included %d edges, removed %d edges", getSuperstep(), vertex.getId().get(), numIncluded,
  27. toRemove.size()));
  28. }

代码示例来源:origin: grafos-ml/okapi

  1. @Override
  2. public void compute(Vertex<I, V, E> vertex,
  3. Iterable<MessageWrapper<I,M1>> messages) throws IOException {
  4. for (MessageWrapper<I,M1> msg : messages) {
  5. E edgeValue = vertex.getEdgeValue(msg.getSourceId());
  6. if (edgeValue == null) {
  7. I clonedId = null;
  8. E clonedEdgeValue = null;
  9. try {
  10. clonedId = (I)msg.getSourceId().getClass().newInstance();
  11. clonedEdgeValue = (E)msg.getMessage().getClass().newInstance();
  12. } catch (InstantiationException e) {
  13. throw new IOException(e);
  14. } catch (IllegalAccessException e) {
  15. throw new IOException(e);
  16. }
  17. ReflectionUtils.copy(
  18. getContext().getConfiguration(), msg.getSourceId(), clonedId);
  19. ReflectionUtils.copy(
  20. getContext().getConfiguration(), msg.getMessage(), clonedEdgeValue);
  21. Edge<I, E> edge = EdgeFactory.create(clonedId, clonedEdgeValue);
  22. vertex.addEdge(edge);
  23. }
  24. }
  25. }
  26. }

代码示例来源:origin: grafos-ml/okapi

  1. @Override
  2. public void compute(
  3. Vertex<LongWritable, NullWritable, DoubleWritable> vertex,
  4. Iterable<LongIdFriendsList> messages) throws IOException {
  5. for (LongIdFriendsList msg : messages) {
  6. LongWritable src = msg.getSourceId();
  7. DoubleWritable edgeValue = vertex.getEdgeValue(src);
  8. assert(edgeValue!=null);
  9. long totalFriends = vertex.getNumEdges();
  10. long commonFriends = 0;
  11. for (LongWritable id : msg.getMessage()) {
  12. if (vertex.getEdgeValue(id)!=null) { // This is a common friend
  13. commonFriends++;
  14. } else {
  15. totalFriends++;
  16. }
  17. }
  18. // The Jaccard similarity is commonFriends/totalFriends
  19. // If the edge to the vertex with ID src does not exist, which is the
  20. // case in a directed graph, this call has no effect.
  21. vertex.setEdgeValue(src, new DoubleWritable(
  22. (double)commonFriends/(double)totalFriends));
  23. }
  24. if (!conversionEnabled) {
  25. vertex.voteToHalt();
  26. }
  27. }
  28. }

代码示例来源:origin: grafos-ml/okapi

  1. if (vertex.getEdgeValue(id1)!=null) {
  2. double weight_ab = vertex.getEdgeValue(id2).getWeight();
  3. double weight_ac = vertex.getEdgeValue(id1).getWeight();
  4. double weight_bc = msg.getWeight();
  5. sendMessage(id2, id1);
  6. } else if (weight_ab+weight_bc < weight_ac) {
  7. vertex.setEdgeValue(id1, vertex.getEdgeValue(id1).setSemimetric(true));
  8. sendMessage(id1, vertex.getId());
  9. vertex.setEdgeValue(id2, vertex.getEdgeValue(id2).setSemimetric(true));
  10. sendMessage(id2, vertex.getId());

代码示例来源:origin: grafos-ml/okapi

  1. public void computeRankingMeasure(
  2. Vertex<CfLongId, FloatMatrixWritable, BooleanWritable> vertex,
  3. Iterable<FloatMatrixMessage> messages) {
  4. if (vertex.getId().isUser()){
  5. ArrayList<FloatBoolean> scores = new ArrayList<FloatBoolean>();
  6. for(FloatMatrixMessage msg : messages){
  7. scores.add(new FloatBoolean(msg.getScore(),
  8. vertex.getEdgeValue(msg.getSenderId()).get()));
  9. }
  10. Collections.sort(scores);
  11. float rankingMeasure = computePrecision(scores, this.k);
  12. aggregate(AVG_PRECISION_AGGREGATOR,
  13. new FloatAvgAggregator.PartialAvg(rankingMeasure,1));
  14. }
  15. }

代码示例来源:origin: grafos-ml/okapi

  1. @Override
  2. public void compute(
  3. Vertex<LongWritable, VertexValue, EdgeValue> vertex,
  4. Iterable<LongWritable> messages) throws IOException {
  5. for (LongWritable other : messages) {
  6. EdgeValue edgeValue = vertex.getEdgeValue(other);
  7. if (edgeValue == null) {
  8. edgeValue = new EdgeValue();
  9. edgeValue.setWeight((byte) 1);
  10. Edge<LongWritable, EdgeValue> edge = EdgeFactory.create(
  11. new LongWritable(other.get()), edgeValue);
  12. vertex.addEdge(edge);
  13. } else {
  14. edgeValue = new EdgeValue();
  15. edgeValue.setWeight(edgeWeight);
  16. vertex.setEdgeValue(other, edgeValue);
  17. }
  18. }
  19. }

代码示例来源:origin: grafos-ml/okapi

  1. @Override
  2. public void compute(
  3. Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex,
  4. Iterable<LongIdDoubleValueFriendsList> messages) throws IOException {
  5. for (LongIdDoubleValueFriendsList msg : messages) {
  6. DoubleWritable partialValue = msg.getVertexValue();
  7. for (LongWritable id : msg.getNeighborsList()) {
  8. if (id != vertex.getId()) {
  9. if (vertex.getEdgeValue(id) != null) {
  10. DoubleWritable currentEdgeValue = vertex.getEdgeValue(id);
  11. // if the edge exists, add up the partial value to the current sum
  12. vertex.setEdgeValue(id, new DoubleWritable(currentEdgeValue.get()
  13. + partialValue.get()));
  14. }
  15. }
  16. }
  17. }
  18. if (!conversionEnabled) {
  19. vertex.voteToHalt();
  20. }
  21. }
  22. }

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

  1. @Override
  2. public void checkOutput(NumericTestGraph<LongWritable, Writable, LongWritable> graph) {
  3. Assert.assertEquals(1, graph.getVertex(1).getNumEdges());
  4. Assert.assertNull(graph.getVertex(1).getEdgeValue(new LongWritable(-1)));
  5. Assert.assertEquals(2, graph.getVertex(1).getEdgeValue(new LongWritable(2)).get());
  6. Assert.assertEquals(1, graph.getVertex(2).getNumEdges());
  7. Assert.assertEquals(-1, graph.getVertex(2).getEdgeValue(new LongWritable(-1)).get());
  8. }
  9. },

代码示例来源:origin: grafos-ml/okapi

  1. @Override
  2. public void compute(Vertex<LongWritable, NullWritable,DoubleBooleanPair> vertex,
  3. Iterable<LongWritable> messages) throws IOException {
  4. final long vertexId = vertex.getId().get();
  5. final long superstep = getSuperstep();
  6. if (((vertexId % megasteps) * 3) == superstep) {
  7. for (Edge<LongWritable, DoubleBooleanPair> edge: vertex.getEdges()) {
  8. if (edge.getTargetVertexId().compareTo(vertex.getId()) > 0) {
  9. sendMessage(edge.getTargetVertexId(), vertex.getId());
  10. }
  11. }
  12. }
  13. // handle set-semimetric-label messages
  14. for (LongWritable trg: messages) {
  15. if (vertex.getEdgeValue(trg) != null) {
  16. vertex.setEdgeValue(trg, vertex.getEdgeValue(trg).setSemimetric(true));
  17. }
  18. }
  19. }
  20. }

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

  1. Long senderId = Long.valueOf(message.getSenderId());
  2. LongWritable wId = new LongWritable(senderId);
  3. LongWritable tag = vertex.getEdgeValue(wId);

代码示例来源:origin: grafos-ml/okapi

  1. @Override
  2. public void compute(Vertex<LongWritable, Writable, DoubleBooleanPair> vertex,
  3. Iterable<LongWritable> messages) throws IOException {
  4. for (LongWritable msg : messages) {
  5. assert(msg.compareTo(vertex.getId())<0); // This can never happen
  6. double weight = vertex.getEdgeValue(msg).getWeight();
  7. // This means there is an edge:
  8. // 1) FROM vertex with ID=msg.get()
  9. // 2) TO vertex with ID=vertex.getId().get()
  10. // 3) with the specified weight.
  11. SimpleEdge t = new SimpleEdge(msg.get(), vertex.getId().get(), weight);
  12. for (Edge<LongWritable, DoubleBooleanPair> edge: vertex.getEdges()) {
  13. if (vertex.getId().compareTo(edge.getTargetVertexId()) < 0) {
  14. sendMessage(edge.getTargetVertexId(), t);
  15. }
  16. }
  17. }
  18. }
  19. }

代码示例来源:origin: grafos-ml/okapi

  1. @Override
  2. public void compute(Vertex<LongWritable, Writable, DoubleWritable> vertex,
  3. Iterable<LongWritable> messages) throws IOException {
  4. for (LongWritable msg : messages) {
  5. assert(msg.compareTo(vertex.getId())<0); // This can never happen
  6. double weight = vertex.getEdgeValue(msg).get();
  7. // This means there is an edge:
  8. // 1) FROM vertex with ID=msg.get()
  9. // 2) TO vertex with ID=vertex.getId().get()
  10. // 3) with the specified weight.
  11. SimpleEdge t = new SimpleEdge(msg.get(), vertex.getId().get(), weight);
  12. for (Edge<LongWritable, DoubleWritable> edge: vertex.getEdges()) {
  13. if (vertex.getId().compareTo(edge.getTargetVertexId()) < 0) {
  14. sendMessage(edge.getTargetVertexId(), t);
  15. }
  16. }
  17. }
  18. vertex.voteToHalt();
  19. }
  20. }

代码示例来源:origin: grafos-ml/okapi

  1. @Override
  2. public void compute(
  3. Vertex<LongWritable, NullWritable, DoubleWritable> vertex,
  4. Iterable<LongIdBloomFilter> messages) throws IOException {
  5. for (LongIdBloomFilter msg : messages) {
  6. LongWritable src = msg.getSourceId();
  7. BloomFilter filter = msg.getMessage();
  8. DoubleWritable edgeValue = vertex.getEdgeValue(src);
  9. assert(edgeValue!=null);
  10. long totalFriends = msg.getNumElements();
  11. long commonFriends = 0;
  12. for (Edge<LongWritable, DoubleWritable> e : vertex.getEdges()) {
  13. Key k = new Key(Longs.toByteArray(e.getTargetVertexId().get()));
  14. if (filter.membershipTest(k)) { // This is a common friend
  15. commonFriends++;
  16. } else {
  17. totalFriends++;
  18. }
  19. }
  20. // The Jaccard similarity is commonFriends/totalFriends
  21. // If the edge to the vertex with ID src does not exist, which is the
  22. // case in a directed graph, this call has no effect.
  23. vertex.setEdgeValue(src, new DoubleWritable(
  24. (double)Math.min(commonFriends, totalFriends)/(double)totalFriends));
  25. }
  26. if (!conversionEnabled) {
  27. vertex.voteToHalt();
  28. }
  29. }
  30. }

代码示例来源:origin: grafos-ml/okapi

  1. @Override
  2. public void compute(
  3. Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex,
  4. Iterable<LongIdAndValueBloomFilter> messages) throws IOException {
  5. for (LongIdAndValueBloomFilter msg : messages) {
  6. DoubleWritable partialValue = msg.getVertexValue();
  7. BloomFilter filter = msg.getNeighborsList();
  8. for (Edge<LongWritable, DoubleWritable> e : vertex.getEdges()) {
  9. Key k = new Key(Longs.toByteArray(e.getTargetVertexId().get()));
  10. if (filter.membershipTest(k)) { // common neighbor
  11. DoubleWritable currentEdgeValue = vertex.getEdgeValue(e.getTargetVertexId());
  12. // add up the partial value to the current sum
  13. vertex.setEdgeValue(e.getTargetVertexId(), new DoubleWritable (currentEdgeValue.get()
  14. + partialValue.get()));
  15. }
  16. }
  17. }
  18. if (!conversionEnabled) {
  19. vertex.voteToHalt();
  20. }
  21. }
  22. }

代码示例来源:origin: grafos-ml/okapi

  1. if (vertex.getEdgeValue(msg.get(0))!=null) {
  2. final Vertex<WritableComparable, Writable, Writable> _vertex = vertex;
  3. ArrayListWritable<WritableComparable> pair = new ArrayListWritable() {

代码示例来源:origin: grafos-ml/okapi

  1. private void sendUpdates(Vertex<LongWritable, IntWritable, MBMEdgeValue> vertex) {
  2. final MBMMessage proposeMsg = new MBMMessage(vertex.getId(), State.PROPOSED);
  3. // get top-capacity available edges by weight
  4. final int capacity = vertex.getValue().get();
  5. MinMaxPriorityQueue<Entry<LongWritable, MBMEdgeValue>> maxHeap = MinMaxPriorityQueue.orderedBy(new Comparator<Entry<LongWritable, MBMEdgeValue>>() {
  6. @Override
  7. public int compare(Entry<LongWritable, MBMEdgeValue> o1, Entry<LongWritable, MBMEdgeValue> o2) {
  8. return -1 * Double.compare(o1.getValue().getWeight(), o2.getValue().getWeight()); // reverse comparator, largest weight first
  9. }
  10. }).maximumSize(capacity).create();
  11. // prepare list of available edges
  12. for (Edge<LongWritable, MBMEdgeValue> e : vertex.getEdges()) {
  13. if (e.getValue().getState() == State.DEFAULT || e.getValue().getState() == State.PROPOSED) {
  14. maxHeap.add(Maps.immutableEntry(e.getTargetVertexId(), e.getValue()));
  15. }
  16. }
  17. if (maxHeap.isEmpty()) {
  18. // all remaining edges are INCLUDED, nothing else to do
  19. checkSolution(vertex.getEdges());
  20. vertex.voteToHalt();
  21. } else {
  22. // propose up to capacity
  23. while (!maxHeap.isEmpty()) {
  24. Entry<LongWritable, MBMEdgeValue> entry = maxHeap.removeFirst();
  25. vertex.getEdgeValue(entry.getKey()).setState(State.PROPOSED);
  26. sendMessage(entry.getKey(), proposeMsg);
  27. }
  28. }
  29. }

代码示例来源:origin: grafos-ml/okapi

  1. for (FloatMatrixMessage msg : messages) {
  2. mat_M.putColumn(i, msg.getFactors());
  3. mat_R.put(i, 0, vertex.getEdgeValue(msg.getSenderId()).get());
  4. i++;

相关文章