本文整理了Java中org.apache.giraph.graph.Vertex.getEdgeValue()
方法的一些代码示例,展示了Vertex.getEdgeValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex.getEdgeValue()
方法的具体详情如下:
包路径:org.apache.giraph.graph.Vertex
类名称: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
@Override
public void compute(Vertex<WritableComparable, Writable, Writable> vertex,
Iterable<WritableComparable> messages) throws IOException {
int count = 0;
for (WritableComparable msg : messages) {
// If this vertex has a neighbor with this ID, then this means it
// participates in a triangle.
if (vertex.getEdgeValue(msg)!=null) {
count++;
}
}
if (count>0) {
vertex.setValue(new IntWritable(count));
}
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
private void updateNeighborsPartitions(
Vertex<LongWritable, VertexValue, EdgeValue> vertex,
Iterable<PartitionMessage> messages) {
for (PartitionMessage message : messages) {
LongWritable otherId = new LongWritable(message.getSourceId());
EdgeValue oldValue = vertex.getEdgeValue(otherId);
vertex.setEdgeValue(
otherId,
new EdgeValue(message.getPartition(), oldValue
.getWeight()));
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<LongWritable, NullWritable, DoubleBooleanPair> vertex,
Iterable<LongWritable> messages) throws IOException {
// handle set-semimetric-label messages
for (LongWritable trg: messages) {
if (vertex.getEdgeValue(trg) != null) {
vertex.setEdgeValue(trg, vertex.getEdgeValue(trg).setSemimetric(true));
}
}
for (Edge<LongWritable, DoubleBooleanPair> edge : vertex.getEdges()) {
if (edge.getValue().isSemimetric()) {
// remove edge
removeEdgesRequest(vertex.getId(), edge.getTargetVertexId());
}
}
}
}
代码示例来源:origin: grafos-ml/okapi
private void processUpdates(Vertex<LongWritable, IntWritable, MBMEdgeValue> vertex, Iterable<MBMMessage> messages) throws AssertionError {
Set<LongWritable> toRemove = new HashSet<LongWritable>();
int numIncluded = 0;
for (MBMMessage msg : messages) {
MBMEdgeValue edgeValue = vertex.getEdgeValue(msg.getId());
if (edgeValue == null) {
// edge has already been removed, do nothing
if (LOG.isDebugEnabled())
LOG.debug(String.format("Superstep %d Vertex %d: message for removed edge from vertex %d", getSuperstep(), vertex.getId().get(), msg
.getId().get()));
} else {
if (msg.getState() == State.PROPOSED && edgeValue.getState() == State.PROPOSED) {
edgeValue.setState(State.INCLUDED);
numIncluded++;
} else if (msg.getState() == State.REMOVED) {
toRemove.add(msg.getId());
}
}
}
// update capacity
vertex.getValue().set(vertex.getValue().get() - numIncluded);
// remove edges locally
for (LongWritable e : toRemove)
vertex.removeEdges(e);
if (LOG.isDebugEnabled())
LOG.debug(String.format("Superstep %d Vertex %d: included %d edges, removed %d edges", getSuperstep(), vertex.getId().get(), numIncluded,
toRemove.size()));
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<I, V, E> vertex,
Iterable<MessageWrapper<I,M1>> messages) throws IOException {
for (MessageWrapper<I,M1> msg : messages) {
E edgeValue = vertex.getEdgeValue(msg.getSourceId());
if (edgeValue == null) {
I clonedId = null;
E clonedEdgeValue = null;
try {
clonedId = (I)msg.getSourceId().getClass().newInstance();
clonedEdgeValue = (E)msg.getMessage().getClass().newInstance();
} catch (InstantiationException e) {
throw new IOException(e);
} catch (IllegalAccessException e) {
throw new IOException(e);
}
ReflectionUtils.copy(
getContext().getConfiguration(), msg.getSourceId(), clonedId);
ReflectionUtils.copy(
getContext().getConfiguration(), msg.getMessage(), clonedEdgeValue);
Edge<I, E> edge = EdgeFactory.create(clonedId, clonedEdgeValue);
vertex.addEdge(edge);
}
}
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, NullWritable, DoubleWritable> vertex,
Iterable<LongIdFriendsList> messages) throws IOException {
for (LongIdFriendsList msg : messages) {
LongWritable src = msg.getSourceId();
DoubleWritable edgeValue = vertex.getEdgeValue(src);
assert(edgeValue!=null);
long totalFriends = vertex.getNumEdges();
long commonFriends = 0;
for (LongWritable id : msg.getMessage()) {
if (vertex.getEdgeValue(id)!=null) { // This is a common friend
commonFriends++;
} else {
totalFriends++;
}
}
// The Jaccard similarity is commonFriends/totalFriends
// If the edge to the vertex with ID src does not exist, which is the
// case in a directed graph, this call has no effect.
vertex.setEdgeValue(src, new DoubleWritable(
(double)commonFriends/(double)totalFriends));
}
if (!conversionEnabled) {
vertex.voteToHalt();
}
}
}
代码示例来源:origin: grafos-ml/okapi
if (vertex.getEdgeValue(id1)!=null) {
double weight_ab = vertex.getEdgeValue(id2).getWeight();
double weight_ac = vertex.getEdgeValue(id1).getWeight();
double weight_bc = msg.getWeight();
sendMessage(id2, id1);
} else if (weight_ab+weight_bc < weight_ac) {
vertex.setEdgeValue(id1, vertex.getEdgeValue(id1).setSemimetric(true));
sendMessage(id1, vertex.getId());
vertex.setEdgeValue(id2, vertex.getEdgeValue(id2).setSemimetric(true));
sendMessage(id2, vertex.getId());
代码示例来源:origin: grafos-ml/okapi
public void computeRankingMeasure(
Vertex<CfLongId, FloatMatrixWritable, BooleanWritable> vertex,
Iterable<FloatMatrixMessage> messages) {
if (vertex.getId().isUser()){
ArrayList<FloatBoolean> scores = new ArrayList<FloatBoolean>();
for(FloatMatrixMessage msg : messages){
scores.add(new FloatBoolean(msg.getScore(),
vertex.getEdgeValue(msg.getSenderId()).get()));
}
Collections.sort(scores);
float rankingMeasure = computePrecision(scores, this.k);
aggregate(AVG_PRECISION_AGGREGATOR,
new FloatAvgAggregator.PartialAvg(rankingMeasure,1));
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, VertexValue, EdgeValue> vertex,
Iterable<LongWritable> messages) throws IOException {
for (LongWritable other : messages) {
EdgeValue edgeValue = vertex.getEdgeValue(other);
if (edgeValue == null) {
edgeValue = new EdgeValue();
edgeValue.setWeight((byte) 1);
Edge<LongWritable, EdgeValue> edge = EdgeFactory.create(
new LongWritable(other.get()), edgeValue);
vertex.addEdge(edge);
} else {
edgeValue = new EdgeValue();
edgeValue.setWeight(edgeWeight);
vertex.setEdgeValue(other, edgeValue);
}
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex,
Iterable<LongIdDoubleValueFriendsList> messages) throws IOException {
for (LongIdDoubleValueFriendsList msg : messages) {
DoubleWritable partialValue = msg.getVertexValue();
for (LongWritable id : msg.getNeighborsList()) {
if (id != vertex.getId()) {
if (vertex.getEdgeValue(id) != null) {
DoubleWritable currentEdgeValue = vertex.getEdgeValue(id);
// if the edge exists, add up the partial value to the current sum
vertex.setEdgeValue(id, new DoubleWritable(currentEdgeValue.get()
+ partialValue.get()));
}
}
}
}
if (!conversionEnabled) {
vertex.voteToHalt();
}
}
}
代码示例来源:origin: apache/giraph
@Override
public void checkOutput(NumericTestGraph<LongWritable, Writable, LongWritable> graph) {
Assert.assertEquals(1, graph.getVertex(1).getNumEdges());
Assert.assertNull(graph.getVertex(1).getEdgeValue(new LongWritable(-1)));
Assert.assertEquals(2, graph.getVertex(1).getEdgeValue(new LongWritable(2)).get());
Assert.assertEquals(1, graph.getVertex(2).getNumEdges());
Assert.assertEquals(-1, graph.getVertex(2).getEdgeValue(new LongWritable(-1)).get());
}
},
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<LongWritable, NullWritable,DoubleBooleanPair> vertex,
Iterable<LongWritable> messages) throws IOException {
final long vertexId = vertex.getId().get();
final long superstep = getSuperstep();
if (((vertexId % megasteps) * 3) == superstep) {
for (Edge<LongWritable, DoubleBooleanPair> edge: vertex.getEdges()) {
if (edge.getTargetVertexId().compareTo(vertex.getId()) > 0) {
sendMessage(edge.getTargetVertexId(), vertex.getId());
}
}
}
// handle set-semimetric-label messages
for (LongWritable trg: messages) {
if (vertex.getEdgeValue(trg) != null) {
vertex.setEdgeValue(trg, vertex.getEdgeValue(trg).setSemimetric(true));
}
}
}
}
代码示例来源:origin: org.apache.giraph/giraph-examples
Long senderId = Long.valueOf(message.getSenderId());
LongWritable wId = new LongWritable(senderId);
LongWritable tag = vertex.getEdgeValue(wId);
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<LongWritable, Writable, DoubleBooleanPair> vertex,
Iterable<LongWritable> messages) throws IOException {
for (LongWritable msg : messages) {
assert(msg.compareTo(vertex.getId())<0); // This can never happen
double weight = vertex.getEdgeValue(msg).getWeight();
// This means there is an edge:
// 1) FROM vertex with ID=msg.get()
// 2) TO vertex with ID=vertex.getId().get()
// 3) with the specified weight.
SimpleEdge t = new SimpleEdge(msg.get(), vertex.getId().get(), weight);
for (Edge<LongWritable, DoubleBooleanPair> edge: vertex.getEdges()) {
if (vertex.getId().compareTo(edge.getTargetVertexId()) < 0) {
sendMessage(edge.getTargetVertexId(), t);
}
}
}
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<LongWritable, Writable, DoubleWritable> vertex,
Iterable<LongWritable> messages) throws IOException {
for (LongWritable msg : messages) {
assert(msg.compareTo(vertex.getId())<0); // This can never happen
double weight = vertex.getEdgeValue(msg).get();
// This means there is an edge:
// 1) FROM vertex with ID=msg.get()
// 2) TO vertex with ID=vertex.getId().get()
// 3) with the specified weight.
SimpleEdge t = new SimpleEdge(msg.get(), vertex.getId().get(), weight);
for (Edge<LongWritable, DoubleWritable> edge: vertex.getEdges()) {
if (vertex.getId().compareTo(edge.getTargetVertexId()) < 0) {
sendMessage(edge.getTargetVertexId(), t);
}
}
}
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, NullWritable, DoubleWritable> vertex,
Iterable<LongIdBloomFilter> messages) throws IOException {
for (LongIdBloomFilter msg : messages) {
LongWritable src = msg.getSourceId();
BloomFilter filter = msg.getMessage();
DoubleWritable edgeValue = vertex.getEdgeValue(src);
assert(edgeValue!=null);
long totalFriends = msg.getNumElements();
long commonFriends = 0;
for (Edge<LongWritable, DoubleWritable> e : vertex.getEdges()) {
Key k = new Key(Longs.toByteArray(e.getTargetVertexId().get()));
if (filter.membershipTest(k)) { // This is a common friend
commonFriends++;
} else {
totalFriends++;
}
}
// The Jaccard similarity is commonFriends/totalFriends
// If the edge to the vertex with ID src does not exist, which is the
// case in a directed graph, this call has no effect.
vertex.setEdgeValue(src, new DoubleWritable(
(double)Math.min(commonFriends, totalFriends)/(double)totalFriends));
}
if (!conversionEnabled) {
vertex.voteToHalt();
}
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex,
Iterable<LongIdAndValueBloomFilter> messages) throws IOException {
for (LongIdAndValueBloomFilter msg : messages) {
DoubleWritable partialValue = msg.getVertexValue();
BloomFilter filter = msg.getNeighborsList();
for (Edge<LongWritable, DoubleWritable> e : vertex.getEdges()) {
Key k = new Key(Longs.toByteArray(e.getTargetVertexId().get()));
if (filter.membershipTest(k)) { // common neighbor
DoubleWritable currentEdgeValue = vertex.getEdgeValue(e.getTargetVertexId());
// add up the partial value to the current sum
vertex.setEdgeValue(e.getTargetVertexId(), new DoubleWritable (currentEdgeValue.get()
+ partialValue.get()));
}
}
}
if (!conversionEnabled) {
vertex.voteToHalt();
}
}
}
代码示例来源:origin: grafos-ml/okapi
if (vertex.getEdgeValue(msg.get(0))!=null) {
final Vertex<WritableComparable, Writable, Writable> _vertex = vertex;
ArrayListWritable<WritableComparable> pair = new ArrayListWritable() {
代码示例来源:origin: grafos-ml/okapi
private void sendUpdates(Vertex<LongWritable, IntWritable, MBMEdgeValue> vertex) {
final MBMMessage proposeMsg = new MBMMessage(vertex.getId(), State.PROPOSED);
// get top-capacity available edges by weight
final int capacity = vertex.getValue().get();
MinMaxPriorityQueue<Entry<LongWritable, MBMEdgeValue>> maxHeap = MinMaxPriorityQueue.orderedBy(new Comparator<Entry<LongWritable, MBMEdgeValue>>() {
@Override
public int compare(Entry<LongWritable, MBMEdgeValue> o1, Entry<LongWritable, MBMEdgeValue> o2) {
return -1 * Double.compare(o1.getValue().getWeight(), o2.getValue().getWeight()); // reverse comparator, largest weight first
}
}).maximumSize(capacity).create();
// prepare list of available edges
for (Edge<LongWritable, MBMEdgeValue> e : vertex.getEdges()) {
if (e.getValue().getState() == State.DEFAULT || e.getValue().getState() == State.PROPOSED) {
maxHeap.add(Maps.immutableEntry(e.getTargetVertexId(), e.getValue()));
}
}
if (maxHeap.isEmpty()) {
// all remaining edges are INCLUDED, nothing else to do
checkSolution(vertex.getEdges());
vertex.voteToHalt();
} else {
// propose up to capacity
while (!maxHeap.isEmpty()) {
Entry<LongWritable, MBMEdgeValue> entry = maxHeap.removeFirst();
vertex.getEdgeValue(entry.getKey()).setState(State.PROPOSED);
sendMessage(entry.getKey(), proposeMsg);
}
}
}
代码示例来源:origin: grafos-ml/okapi
for (FloatMatrixMessage msg : messages) {
mat_M.putColumn(i, msg.getFactors());
mat_R.put(i, 0, vertex.getEdgeValue(msg.getSenderId()).get());
i++;
内容来源于网络,如有侵权,请联系作者删除!