本文整理了Java中org.apache.giraph.graph.Vertex
类的一些代码示例,展示了Vertex
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vertex
类的具体详情如下:
包路径:org.apache.giraph.graph.Vertex
类名称:Vertex
[英]Class which holds vertex id, data and edges.
[中]类,该类保存顶点id、数据和边。
代码示例来源: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: org.apache.giraph/giraph-core
/**
* The backing store of the current vertex id is now released.
* Further calls to getCurrentVertexId () without calling next()
* will return null.
*
* @return Current vertex id that was released
*/
public I releaseCurrentVertexId() {
I releasedVertexId = vertex.getId();
vertex.initialize(null, vertex.getValue());
return releasedVertexId;
}
代码示例来源: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
@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
@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();
}
代码示例来源: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
protected Text convertVertexToLine(
Vertex<CfLongId, FloatMatrixWritable, BooleanWritable> vertex)
throws IOException {
if (outputEdge.equals(vertex.getId())){
return new Text(vertex.getValue().toString());
}
return null;
}
};
代码示例来源:origin: apache/giraph
for (Vertex<I, V, E> vertex : partition) {
Iterable messages =
internalApi.takeMessages(vertex.getId());
if (vertex.isHalted() && !Iterables.isEmpty(messages)) {
vertex.wakeUp();
if (!vertex.isHalted()) {
localLogic.compute(vertex, messages);
vertex.unwrapMutableEdges();
if (!vertex.isHalted()) {
anyCurVertexAlive = true;
代码示例来源:origin: grafos-ml/okapi
protected void initFactorsIfNeeded(Vertex<CfLongId, FloatMatrixWritable, FloatWritable> vertex) {
if (null == vertex.getValue() || vertex.getValue().columns != d){
vertex.setValue(new FloatMatrixWritable(FloatMatrix.rand(d)));
}
}
代码示例来源:origin: org.apache.giraph/giraph-core
/**
* Writes Vertex data to output stream.
*
* @param output the output stream
* @param vertex The vertex to serialize
* @param conf Configuration
* @param <I> Vertex id
* @param <V> Vertex value
* @param <E> Edge value
* @throws IOException
*/
@SuppressWarnings("unchecked")
public static <I extends WritableComparable, V extends Writable,
E extends Writable> void writeVertexToDataOutput(
DataOutput output,
Vertex<I, V, E> vertex,
ImmutableClassesGiraphConfiguration<I, V, E> conf)
throws IOException {
vertex.getId().write(output);
vertex.getValue().write(output);
((OutEdges<I, E>) vertex.getEdges()).write(output);
output.writeBoolean(vertex.isHalted());
}
代码示例来源: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<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
/**
* We override this function as we need a special treatment for item biases. See the class documentation for the explanation.
*/
protected void initFactorsIfNeeded(Vertex<CfLongId,FloatMatrixWritable,FloatWritable> vertex) {
if (null == vertex.getValue() || vertex.getValue().columns != d+1){
vertex.setValue(new FloatMatrixWritable(FloatMatrix.rand(d + 1)));
}
if (vertex.getId().isUser()){//In BPR the first factor of the user is always 1, its to have item baselines
vertex.getValue().put(0, 1f);
}
}
代码示例来源: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 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: 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: 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: org.apache.giraph/giraph-core
/**
* Writes vertex data (Id, value and halted state) to stream.
*
* @param output The output stream
* @param vertex The vertex to serialize
* @throws IOException
*/
private void writeVertexData(DataOutput output, Vertex<I, V, E> vertex)
throws IOException {
vertex.getId().write(output);
V value = vertex.getValue();
if (value != null) {
output.writeBoolean(false);
value.write(output);
} else {
output.writeBoolean(true);
}
output.writeBoolean(vertex.isHalted());
}
代码示例来源: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<IntWritable, IntWritable, NullWritable> vertex,
Iterable<IntWritable> messages) throws IOException {
boolean changed = false;
for (IntWritable message : messages) {
if (vertex.getValue().get() < message.get()) {
vertex.setValue(message);
changed = true;
}
}
if (getSuperstep() == 0 || changed) {
sendMessageToAllEdges(vertex, vertex.getValue());
}
vertex.voteToHalt();
}
}
内容来源于网络,如有侵权,请联系作者删除!