本文整理了Java中org.apache.giraph.graph.Vertex.getEdges()
方法的一些代码示例,展示了Vertex.getEdges()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex.getEdges()
方法的具体详情如下:
包路径:org.apache.giraph.graph.Vertex
类名称:Vertex
方法名:getEdges
[英]Get a read-only view of the out-edges of this vertex. Note: edge objects returned by this iterable may be invalidated as soon as the next element is requested. Thus, keeping a reference to an edge almost always leads to undesired behavior. Accessing the edges with other methods (e.g., addEdge()) during iteration leads to undefined behavior.
[中]获取此顶点外边缘的只读视图。注意:此iterable返回的边缘对象可能会在请求下一个元素时立即失效。因此,保持对边的引用几乎总是会导致不希望的行为。在迭代过程中,使用其他方法(例如addEdge())访问边会导致未定义的行为。
代码示例来源:origin: apache/giraph
@Override
public Iterable<Edge<I, E>> get(Vertex<I, V, E> vertex) {
return vertex.getEdges();
}
};
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Constructor.
*
* @param vertex The source vertex of the out edges
*/
public TargetVertexIdIterator(Vertex<I, ?, ?> vertex) {
edgesIterator =
((Vertex<I, Writable, Writable>) vertex).getEdges().iterator();
}
代码示例来源:origin: grafos-ml/okapi
private void debug(Vertex<LongWritable, IntWritable, MBMEdgeValue> vertex) {
LOG.debug(vertex);
for (Edge<LongWritable, MBMEdgeValue> e : vertex.getEdges())
LOG.debug(String.format("Edge(%d, %s)", e.getTargetVertexId().get(), e.getValue().toString()));
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public Text convertVertexToLine(Vertex<LongWritable, IntWritable, MBMEdgeValue> vertex) throws IOException {
StringBuffer sb = new StringBuffer(vertex.getId().toString());
sb.append(delimiter);
sb.append(vertex.getValue());
for (Edge<LongWritable, MBMEdgeValue> edge : vertex.getEdges()) {
sb.append(delimiter).append(edge.getTargetVertexId());
sb.append(delimiter).append(edge.getValue().getWeight());
// skip the state, which is always INCLUDED
}
return new Text(sb.toString());
}
}
代码示例来源:origin: grafos-ml/okapi
/**
* This method computes the degree of a vertex as the sum of its edge weights.
* @param v
* @return
*/
public static double computeDegree(
Vertex<LongWritable,VertexValue,DoubleWritable> v) {
double degree = 0.0;
for (Edge<LongWritable, DoubleWritable> edge : v.getEdges()) {
degree += edge.getValue().get();
}
return degree;
}
代码示例来源: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
/**
* Writes vertex edges (Id, edges) to stream.
*
* @param output The output stream
* @param vertex The vertex to serialize
* @throws IOException
*/
private void writeOutEdges(DataOutput output, Vertex<I, V, E> vertex)
throws IOException {
vertex.getId().write(output);
OutEdges<I, E> edges = (OutEdges<I, E>) vertex.getEdges();
edges.write(output);
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, NullWritable, DoubleWritable> vertex,
Iterable<LongIdFriendsList> messages) throws IOException {
for (Edge<LongWritable, DoubleWritable> e: vertex.getEdges()) {
vertex.setEdgeValue(e.getTargetVertexId(), covertToDistance(e.getValue()));
}
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, NullWritable, DoubleWritable> vertex,
Iterable<LongIdBloomFilter> messages) throws IOException {
for (Edge<LongWritable, DoubleWritable> e: vertex.getEdges()) {
vertex.setEdgeValue(e.getTargetVertexId(), covertToDistance(e.getValue()));
}
vertex.voteToHalt();
}
}
代码示例来源: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
private void removeVertex(Vertex<LongWritable, IntWritable, MBMEdgeValue> vertex) {
Set<LongWritable> toRemove = new HashSet<LongWritable>();
final MBMMessage removeMsg = new MBMMessage(vertex.getId(), State.REMOVED);
for (Edge<LongWritable, MBMEdgeValue> e : vertex.getEdges()) {
MBMEdgeValue edgeState = e.getValue();
// remove remaining DEFAULT edges
if (edgeState.getState() == State.DEFAULT) {
sendMessage(e.getTargetVertexId(), removeMsg);
toRemove.add(e.getTargetVertexId());
}
}
for (LongWritable e : toRemove)
vertex.removeEdges(e);
}
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Read vertex edges from an input and set them to the vertex.
*
* @param in The input stream
* @param partition The partition owning the vertex
* @throws IOException
*/
private void readOutEdges(DataInput in, Partition<I, V, E> partition)
throws IOException {
I id = conf.createVertexId();
id.readFields(in);
Vertex<I, V, E> v = partition.getVertex(id);
OutEdges<I, E> edges = (OutEdges<I, E>) v.getEdges();
edges.readFields(in);
partition.saveVertex(v);
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex,
Iterable<LongIdAndValueBloomFilter> 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 LongIdAndValueBloomFilter(vertex.getValue(), filter));
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex,
Iterable<LongIdAndValueBloomFilter> messages) throws IOException {
for (Edge<LongWritable, DoubleWritable> e: vertex.getEdges()) {
vertex.setEdgeValue(e.getTargetVertexId(),
new DoubleWritable(e.getValue().get()*(-1.0)));
}
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(
Vertex<LongWritable, DoubleWritable, DoubleWritable> vertex,
Iterable<LongIdDoubleValueFriendsList> messages) throws IOException {
for (Edge<LongWritable, DoubleWritable> e: vertex.getEdges()) {
vertex.setEdgeValue(e.getTargetVertexId(),
new DoubleWritable(e.getValue().get()*(-1.0)));
}
vertex.voteToHalt();
}
}
代码示例来源: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: grafos-ml/okapi
@Override
public void compute(Vertex<WritableComparable, Writable, Writable> vertex,
Iterable<Writable> messages) throws IOException {
for (Edge<WritableComparable, Writable> edge: vertex.getEdges()) {
if (edge.getTargetVertexId().compareTo(vertex.getId()) > 0) {
sendMessage(edge.getTargetVertexId(), vertex.getId());
}
}
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<LongWritable, NullWritable,DoubleWritable> vertex,
Iterable<Writable> messages) throws IOException {
for (Edge<LongWritable, DoubleWritable> edge: vertex.getEdges()) {
if (edge.getTargetVertexId().compareTo(vertex.getId()) > 0) {
sendMessage(edge.getTargetVertexId(), vertex.getId());
}
}
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<WritableComparable, Writable, Writable> vertex,
Iterable<WritableComparable> messages) throws IOException {
for (WritableComparable msg : messages) {
assert(msg.compareTo(vertex.getId())<0); // This can never happen
for (Edge<WritableComparable, Writable> edge: vertex.getEdges()) {
if (vertex.getId().compareTo(edge.getTargetVertexId()) < 0) {
sendMessage(edge.getTargetVertexId(), msg);
}
}
}
vertex.voteToHalt();
}
}
代码示例来源:origin: grafos-ml/okapi
@Override
public void compute(Vertex<CfLongId, FloatMatrixWritable, FloatWritable> vertex, Iterable<FloatMatrixMessage> messages) throws IOException {
vertex.setValue(new FloatMatrixWritable(FloatMatrix.rand(DIM)));
if(getSuperstep() == 0){
Iterable<Edge<CfLongId, FloatWritable>> edges = vertex.getEdges();
sendMessage(vertex.getId(), emptyMsg); //send message to myself in order to be executed in the next super step
for (Edge<CfLongId, FloatWritable> edge : edges) {
sendMessage(edge.getTargetVertexId(), new FloatMatrixMessage(vertex.getId(), emptyList, edge.getValue().get()));
}
}
vertex.voteToHalt();
}
内容来源于网络,如有侵权,请联系作者删除!