本文整理了Java中org.apache.giraph.graph.Vertex.getNumEdges()
方法的一些代码示例,展示了Vertex.getNumEdges()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex.getNumEdges()
方法的具体详情如下:
包路径:org.apache.giraph.graph.Vertex
类名称:Vertex
方法名:getNumEdges
[英]Get the number of outgoing edges on this vertex.
[中]获取此顶点上的传出边数。
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
protected double transitionProbability(
Vertex<LongWritable, DoubleWritable, NullWritable> vertex,
double stateProbability, Edge<LongWritable, NullWritable> edge) {
// Uniform transition probability
return stateProbability / vertex.getNumEdges();
}
代码示例来源:origin: org.apache.giraph/giraph-core
@Override
public long getEdgeCount() {
long edges = 0;
for (Vertex<I, V, E> vertex : vertexMap.values()) {
edges += vertex.getNumEdges();
}
return edges;
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex,
Iterable<LongIdDoubleValueFriendsList> messages) throws IOException {
DoubleWritable vertexValue = new DoubleWritable(0.0);
if (vertex.getNumEdges() > 0) {
vertexValue.set(Math.log(1.0 / (double) vertex.getNumEdges()));
}
vertex.setValue(vertexValue);
}
代码示例来源:origin: org.apache.giraph/giraph-core
@Override
public long getEdgeCount() {
long edges = 0;
for (byte[] vertexBytes : vertexMap.values()) {
WritableUtils.reinitializeVertexFromByteArray(vertexBytes,
representativeVertex, useUnsafeSerialization, getConf());
edges += representativeVertex.getNumEdges();
}
return edges;
}
代码示例来源:origin: org.apache.giraph/giraph-core
@Override
public void writeVertex(
Vertex<WritableComparable, Writable, Writable> vertex)
throws IOException, InterruptedException {
StringBuilder sb = new StringBuilder(vertex.getNumEdges() * 10);
for (Edge<WritableComparable, Writable> edge : vertex.getEdges()) {
addEdge(sb, vertex.getId(), edge);
}
addNodeInfo(vertex, sb);
getRecordWriter().write(new Text(sb.toString()), null);
}
}
代码示例来源:origin: org.apache.giraph/giraph-core
/** Increment V & E counts for new vertex read, store values
* for that outgoing _temporary_ Partition, which shares the
* Partition ID for the actual remote Partition the collection
* will eventually be processed in.
* @param partitionOwner the owner of the Partition this data
* will eventually belong to.
* @param vertex the vertex to extract counts from.
* @param <I> the vertex id type.
* @param <V> the vertex value type.
* @param <E> the edge value type.
*/
public <I extends WritableComparable, V extends Writable,
E extends Writable> void
incrementCounters(PartitionOwner partitionOwner,
Vertex<I, V, E> vertex) {
final int id = partitionOwner.getPartitionId();
// vertex counts
vertexAccumulator
.put(id, getVerticesForPartition(id) + 1);
totalVertexCount++;
// edge counts
totalEdgeCount += vertex.getNumEdges();
edgeAccumulator.put(id, getEdgesForPartition(id) +
vertex.getNumEdges());
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, NullWritable, NullWritable> vertex,
Iterable<LongWritable> messages) throws IOException {
HashSet<LongWritable> toDelete = new HashSet<LongWritable>();
for (LongWritable id : messages) {
toDelete.add(new LongWritable(id.get()));
}
Iterator<MutableEdge<LongWritable,NullWritable>> edgeIterator =
vertex.getMutableEdges().iterator();
while (edgeIterator.hasNext()) {
if (toDelete.contains(edgeIterator.next().getTargetVertexId())) {
edgeIterator.remove();
}
}
if (vertex.getNumEdges()<getConf().getInt(K_VALUE, K_VALUE_DEFAULT)) {
sendMessageToAllEdges(vertex, vertex.getId());
removeVertexRequest(vertex.getId());
}
vertex.voteToHalt();
}
}
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
public void compute(
Vertex<LongWritable, LongWritable, DoubleWritable> vertex,
Iterable<DoubleWritable> messages) throws IOException {
LongWritable vertexValue = vertex.getValue();
vertexValue.set(vertex.getNumEdges());
vertex.setValue(vertexValue);
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
private void migrate(
Vertex<LongWritable, VertexValue, EdgeValue> vertex,
short currentPartition, short newPartition) {
vertex.getValue().setCurrentPartition(newPartition);
// update partitions loads
int numberOfEdges = vertex.getNumEdges();
aggregate(loadAggregatorNames[currentPartition], new LongWritable(
-numberOfEdges));
aggregate(loadAggregatorNames[newPartition], new LongWritable(
numberOfEdges));
aggregate(AGGREGATOR_MIGRATIONS, new LongWritable(1));
// inform the neighbors
PartitionMessage message = new PartitionMessage(vertex.getId()
.get(), newPartition);
sendMessageToAllEdges(vertex, message);
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, NullWritable> vertex,
Iterable<LongIdFriendsList> messages)
throws IOException {
// Add the friends of this vertex in a HashSet so that we can check
// for the existence of triangles quickly.
HashSet<LongWritable> friends = new HashSet<LongWritable>();
for (Edge<LongWritable, NullWritable> edge : vertex.getEdges()) {
friends.add(new LongWritable(edge.getTargetVertexId().get()));
}
int edges = vertex.getNumEdges();
int triangles = 0;
for (LongIdFriendsList msg : messages) {
for (LongWritable id : msg.getMessage()) {
if (friends.contains(id)) {
// Triangle found
triangles++;
}
}
}
double clusteringCoefficient =
((double)triangles) / ((double)edges*(edges-1));
DoubleWritable clCoefficient = new DoubleWritable(clusteringCoefficient);
aggregate(CL_COEFFICIENT_AGGREGATOR, clCoefficient);
vertex.setValue(clCoefficient);
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, VertexValue, EdgeValue> vertex,
Iterable<PartitionMessage> messages) throws IOException {
boolean isActive = messages.iterator().hasNext();
short currentPartition = vertex.getValue().getCurrentPartition();
int numberOfEdges = vertex.getNumEdges();
// update neighbors partitions
updateNeighborsPartitions(vertex, messages);
// count labels occurrences in the neighborhood
int totalLabels = computeNeighborsLabels(vertex);
// compute the most attractive partition
short newPartition = computeNewPartition(vertex, totalLabels);
// request migration to the new destination
if (newPartition != currentPartition && isActive) {
requestMigration(vertex, numberOfEdges, currentPartition,
newPartition);
}
}
代码示例来源:origin: org.apache.giraph/giraph-core
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex,
Iterable<BytesWritable> messages) throws IOException {
RandomMessageBenchmarkWorkerContext workerContext = getWorkerContext();
if (getSuperstep() < workerContext.getNumSupersteps()) {
for (int i = 0; i < workerContext.getNumMessagePerEdge(); i++) {
workerContext.randomizeMessageBytes();
sendMessageToAllEdges(vertex,
new BytesWritable(workerContext.getMessageBytes()));
long bytesSent = workerContext.getMessageBytes().length *
vertex.getNumEdges();
aggregate(AGG_SUPERSTEP_TOTAL_BYTES, new LongWritable(bytesSent));
aggregate(AGG_SUPERSTEP_TOTAL_MESSAGES,
new LongWritable(vertex.getNumEdges()));
}
} else {
vertex.voteToHalt();
}
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, VertexValue, EdgeValue> vertex,
Iterable<PartitionMessage> messages) throws IOException {
short partition = vertex.getValue().getCurrentPartition();
if (partition == -1) {
partition = (short) rnd.nextInt(numberOfPartitions);
}
aggregate(loadAggregatorNames[partition],
new LongWritable(vertex.getNumEdges()));
vertex.getValue().setCurrentPartition(partition);
vertex.getValue().setNewPartition(partition);
PartitionMessage message = new PartitionMessage(vertex.getId()
.get(), partition);
sendMessageToAllEdges(vertex, message);
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, NullWritable, DoubleWritable> vertex,
Iterable<LongIdBloomFilter> messages) throws IOException {
BloomFilter filter = new BloomFilter(numBits, numFunctions, hashType);
for (Edge<LongWritable, DoubleWritable> e : vertex.getEdges()) {
filter.add(new Key(Longs.toByteArray(e.getTargetVertexId().get())));
}
sendMessageToAllEdges(vertex,
new LongIdBloomFilter(vertex.getId(), filter, vertex.getNumEdges()));
}
}
代码示例来源:origin: org.apache.giraph/giraph-examples
/**
* Creates list of parents based on the received ids and halts the vertices
* that don't have any parent or outgoing edge, hence, they can't be
* part of an SCC.
* @param vertex Current vertex.
* @param messages Received ids from the Transpose phase.
*/
private void trim(Vertex<LongWritable, SccVertexValue, NullWritable> vertex,
Iterable<LongWritable> messages) {
SccVertexValue vertexValue = vertex.getValue();
// Keep the ids of the parent nodes to allow for backwards traversal
for (LongWritable parent : messages) {
vertexValue.addParent(parent.get());
}
// If this node doesn't have any parents or outgoing edges,
// it can't be part of an SCC
vertexValue.set(vertex.getId().get());
if (vertex.getNumEdges() == 0 || vertexValue.getParents() == null) {
vertexValue.deactivate();
} else {
messageValue.set(vertexValue.get());
sendMessageToAllEdges(vertex, messageValue);
}
}
代码示例来源: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: org.apache.giraph/giraph-examples
long edges = vertex.getNumEdges();
sendMessageToAllEdges(vertex,
new DoubleWritable(vertex.getValue().get() / edges));
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
Iterable<DoubleWritable> messages) {
if (getSuperstep() == 0) {
vertex.setValue(new DoubleWritable(1f / getTotalNumVertices()));
}
if (getSuperstep() >= 1) {
double sum = 0;
for (DoubleWritable message : messages) {
sum += message.get();
}
DoubleWritable vertexValue =
new DoubleWritable((0.15f / getTotalNumVertices()) + 0.85f * sum);
vertex.setValue(vertexValue);
}
if (getSuperstep() < getContext().getConfiguration().getInt(
MAX_SUPERSTEPS, MAX_SUPERSTEPS_DEFAULT)) {
long edges = vertex.getNumEdges();
sendMessageToAllEdges(vertex,
new DoubleWritable(vertex.getValue().get() / edges));
} else {
vertex.voteToHalt();
}
}
}
代码示例来源:origin: org.apache.giraph/giraph-examples
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, FloatWritable> vertex,
Iterable<DoubleWritable> messages) throws IOException {
if (getSuperstep() >= 1) {
double sum = 0;
for (DoubleWritable message : messages) {
sum += message.get();
}
DoubleWritable vertexValue =
new DoubleWritable((0.15f / getTotalNumVertices()) + 0.85f * sum);
vertex.setValue(vertexValue);
aggregate(MAX_AGG, vertexValue);
aggregate(MIN_AGG, vertexValue);
aggregate(SUM_AGG, new LongWritable(1));
LOG.info(vertex.getId() + ": PageRank=" + vertexValue +
" max=" + getAggregatedValue(MAX_AGG) +
" min=" + getAggregatedValue(MIN_AGG));
}
if (getSuperstep() < MAX_SUPERSTEPS) {
long edges = vertex.getNumEdges();
sendMessageToAllEdges(vertex,
new DoubleWritable(vertex.getValue().get() / edges));
} else {
vertex.voteToHalt();
}
}
代码示例来源:origin: org.apache.giraph/giraph-core
@Override
public void compute(
Vertex<IntWritable, FloatWritable, NullWritable> vertex,
Iterable<FloatWritable> messages) throws IOException {
if (getSuperstep() >= 1) {
float sum = 0;
for (FloatWritable message : messages) {
sum += message.get();
}
vertex.getValue().set((0.15f / getTotalNumVertices()) + 0.85f * sum);
}
if (getSuperstep() < getConf().getInt(SUPERSTEP_COUNT, 0)) {
sendMessageToAllEdges(vertex,
new FloatWritable(vertex.getValue().get() / vertex.getNumEdges()));
} else {
vertex.voteToHalt();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!