本文整理了Java中org.apache.giraph.graph.Vertex.addEdge()
方法的一些代码示例,展示了Vertex.addEdge()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex.addEdge()
方法的具体详情如下:
包路径:org.apache.giraph.graph.Vertex
类名称:Vertex
方法名:addEdge
[英]Add an edge for this vertex (happens immediately)
[中]为该顶点添加边(立即发生)
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Add edges to the Vertex.
*
* @param vertex Vertex to add edges to
* @param vertexChanges contains edges to add
*/
protected void addEdges(Vertex<I, V, E> vertex,
VertexChanges<I, V, E> vertexChanges) {
if (vertex == null) {
return;
}
if (hasEdgeAdditions(vertexChanges)) {
for (Edge<I, E> edge : vertexChanges.getAddedEdgeList()) {
vertex.addEdge(edge);
}
}
}
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Add an edge to an existing vertex
*
* @param vertexId Edge origin
* @param edgePair The edge
* @return this
*/
public TestGraph<I, V, E> addEdge(I vertexId, Entry<I, E> edgePair) {
if (!vertices.containsKey(vertexId)) {
Vertex<I, V, E> v = conf.createVertex();
v.initialize(vertexId, conf.createVertexValue());
vertices.put(vertexId, v);
}
vertices.get(vertexId)
.addEdge(EdgeFactory.create(edgePair.getKey(),
edgePair.getValue()));
return this;
}
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Add an edge to an existing vertex
*
* @param vertexId Edge origin
* @param toVertex Edge destination
* @param edgeValue Edge value
* @return this
*/
public TestGraph<I, V, E> addEdge(I vertexId, I toVertex, E edgeValue) {
if (!vertices.containsKey(vertexId)) {
Vertex<I, V, E> v = conf.createVertex();
v.initialize(vertexId, conf.createVertexValue());
vertices.put(vertexId, v);
}
vertices.get(vertexId)
.addEdge(EdgeFactory.create(toVertex, edgeValue));
return this;
}
/**
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Add vertex
*
* @param vertex Vertex
* @return this
*/
public TestGraph<I, V, E> addVertex(Vertex<I, V, E> vertex) {
Vertex<I, V, E> previousVertex = vertices.get(vertex.getId());
if (previousVertex != null) {
vertexValueCombiner.combine(previousVertex.getValue(), vertex.getValue());
for (Edge<I, E> edge : vertex.getEdges()) {
previousVertex.addEdge(edge);
}
} else {
vertices.put(vertex.getId(), vertex);
}
return this;
}
代码示例来源: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
public void sampleIrrelevantEdges(
Vertex<CfLongId, FloatMatrixWritable, BooleanWritable> vertex) {
if (vertex.getId().isUser()){//only users
Iterable<Edge<CfLongId, BooleanWritable>> edges = vertex.getEdges();
HashSet<CfLongId> relevant = new HashSet<CfLongId>();
for (Edge<CfLongId, BooleanWritable> e : edges) {
relevant.add(e.getTargetVertexId());
}
for (int i=0; i<numberSamples; i++){
CfLongId random = getRandomItemId(relevant);
vertex.addEdge(EdgeFactory.create(random, new BooleanWritable(false)));
}
}
}
代码示例来源: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: org.apache.giraph/giraph-core
@Override
public boolean putOrCombine(Vertex<I, V, E> vertex) {
Vertex<I, V, E> originalVertex = vertexMap.get(vertex.getId());
if (originalVertex == null) {
originalVertex =
vertexMap.putIfAbsent(vertex.getId(), vertex);
if (originalVertex == null) {
return true;
}
}
synchronized (originalVertex) {
// Combine the vertex values
getVertexValueCombiner().combine(
originalVertex.getValue(), vertex.getValue());
// Add the edges to the representative vertex
for (Edge<I, E> edge : vertex.getEdges()) {
originalVertex.addEdge(edge);
}
}
return false;
}
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Combine two vertices together and store the serialized bytes
* in the vertex map.
*
* @param representativeVertex existing vertex
* @param representativeCombinerVertex new vertex to combine
*/
private void combine(Vertex<I, V, E> representativeVertex,
Vertex<I, V, E> representativeCombinerVertex) {
getVertexValueCombiner().combine(representativeVertex.getValue(),
representativeCombinerVertex.getValue());
// Add the edges to the representative vertex
for (Edge<I, E> edge : representativeCombinerVertex.getEdges()) {
representativeVertex.addEdge(edge);
}
vertexMap.put(representativeCombinerVertex.getId(),
WritableUtils.writeVertexToByteArray(
representativeVertex, useUnsafeSerialization, getConf()));
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<CfLongId, FloatMatrixWritable, FloatWritable> vertex,
Iterable<FloatMatrixMessage> messages) throws IOException {
FloatMatrixWritable vector =
new FloatMatrixWritable(getContext().getConfiguration().getInt(
VECTOR_SIZE, VECTOR_SIZE_DEFAULT));
Random randGen = new Random();
for (int i=0; i<vector.length; i++) {
vector.put(i, 0.01f*randGen.nextFloat());
}
vertex.setValue(vector);
for (FloatMatrixMessage msg : messages) {
DefaultEdge<CfLongId, FloatWritable> edge =
new DefaultEdge<CfLongId, FloatWritable>();
edge.setTargetVertexId(msg.getSenderId());
edge.setValue(new FloatWritable(msg.getScore()));
vertex.addEdge(edge);
}
// The score does not matter at this point.
sendMessageToAllEdges(vertex,
new FloatMatrixMessage(vertex.getId(), vertex.getValue(), 0.0f));
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<CfLongId, FloatMatrixWritable,
FloatWritable> vertex, Iterable<FloatMatrixMessage> messages)
throws IOException {
FloatMatrixWritable vector =
new FloatMatrixWritable(getContext().getConfiguration().getInt(
VECTOR_SIZE, VECTOR_SIZE_DEFAULT));
Random randGen = new Random();
for (int i=0; i<vector.length; i++) {
vector.put(i, 0.01f*randGen.nextFloat());
}
vertex.setValue(vector);
for (FloatMatrixMessage msg : messages) {
DefaultEdge<CfLongId, FloatWritable> edge =
new DefaultEdge<CfLongId, FloatWritable>();
edge.setTargetVertexId(msg.getSenderId());
edge.setValue(new FloatWritable(msg.getScore()));
vertex.addEdge(edge);
}
// The score does not matter at this point.
sendMessageToAllEdges(vertex,
new FloatMatrixMessage(vertex.getId(), vertex.getValue(), 0.0f));
vertex.voteToHalt();
}
}
代码示例来源:origin: org.apache.giraph/giraph-examples
" on superstep " + getSuperstep());
vertex.addEdge(newEdge);
sendMessage(edge.getTargetVertexId(),
new VerifiableMessage(
代码示例来源:origin: org.apache.giraph/giraph-examples
" to vertex " + edge.getTargetVertexId() +
" on superstep " + getSuperstep());
vertex.addEdge(newEdge);
sendMessage(edge.getTargetVertexId(), newEdgeValue);
代码示例来源:origin: grafos-ml/okapi
edge.setTargetVertexId(msg.getSenderId());
edge.setValue(new FloatWritable(msg.getScore()));
vertex.addEdge(edge);
内容来源于网络,如有侵权,请联系作者删除!