use of com.baidu.hugegraph.computer.core.graph.value.Value in project hugegraph-computer by hugegraph.
the class FileGraphPartition method compute1.
private long compute1(ComputationContext context, Computation<M> computation, int superstep) {
Value result = this.context.config().createObject(ComputerOptions.ALGORITHM_RESULT_CLASS);
long activeVertexCount = 0L;
while (this.vertexInput.hasNext()) {
Vertex vertex = this.vertexInput.next();
this.readVertexStatusAndValue(vertex, result);
Iterator<M> messageIter = this.messageInput.iterator(this.vertexInput.idPointer());
if (messageIter.hasNext()) {
vertex.reactivate();
}
/*
* If the vertex is inactive, it's edges will be skipped
* automatically at the next vertex.
*/
if (vertex.active()) {
Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
vertex.edges(edges);
computation.compute(context, vertex, messageIter);
}
// The vertex status may be changed after computation
if (vertex.active()) {
activeVertexCount++;
}
try {
this.saveVertexStatusAndValue(vertex);
} catch (IOException e) {
throw new ComputerException("Error occurred when saveVertex", e);
}
}
return activeVertexCount;
}
use of com.baidu.hugegraph.computer.core.graph.value.Value in project hugegraph-computer by hugegraph.
the class FileGraphPartition method output.
protected PartitionStat output() {
ComputerOutput output = this.context.config().createObject(ComputerOptions.OUTPUT_CLASS);
output.init(this.context.config(), this.partition);
try {
this.beforeOutput();
} catch (IOException e) {
throw new ComputerException("Error occurred when beforeOutput", e);
}
Value result = this.context.config().createObject(ComputerOptions.ALGORITHM_RESULT_CLASS);
while (this.vertexInput.hasNext()) {
Vertex vertex = this.vertexInput.next();
this.readVertexStatusAndValue(vertex, result);
Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
vertex.edges(edges);
output.write(vertex);
}
try {
this.afterOutput();
} catch (IOException e) {
throw new ComputerException("Error occurred when afterOutput", e);
}
output.close();
return new PartitionStat(this.partition, this.vertexCount, this.edgeCount, 0L);
}
use of com.baidu.hugegraph.computer.core.graph.value.Value in project hugegraph-computer by hugegraph.
the class FileGraphPartition method saveVertexStatusAndValue.
private void saveVertexStatusAndValue(Vertex vertex) throws IOException {
this.curStatusOutput.writeBoolean(vertex.active());
Value value = vertex.value();
E.checkNotNull(value, "Vertex's value can't be null");
value.write(this.curValueOutput);
}
use of com.baidu.hugegraph.computer.core.graph.value.Value in project hugegraph-computer by hugegraph.
the class FileGraphPartition method compute1.
private long compute1(ComputationContext context) {
Value result = this.context.config().createObject(ComputerOptions.ALGORITHM_RESULT_CLASS);
long activeVertexCount = 0L;
while (this.vertexInput.hasNext()) {
Vertex vertex = this.vertexInput.next();
this.readVertexStatusAndValue(vertex, result);
Iterator<Value> messageIter = this.messageInput.iterator(this.vertexInput.idPointer());
if (messageIter.hasNext()) {
vertex.reactivate();
}
/*
* If the vertex is inactive, it's edges will be skipped
* automatically at the next vertex.
*/
if (vertex.active()) {
Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
vertex.edges(edges);
this.computation.compute(context, vertex, messageIter);
}
// The vertex status may be changed after computation
if (vertex.active()) {
activeVertexCount++;
}
try {
this.saveVertexStatusAndValue(vertex);
} catch (IOException e) {
throw new ComputerException("Error occurred when saveVertex", e);
}
}
return activeVertexCount;
}
use of com.baidu.hugegraph.computer.core.graph.value.Value in project hugegraph-computer by hugegraph.
the class DefaultProperties method read.
@Override
public void read(RandomAccessInput in) throws IOException {
this.keyValues.clear();
int size = in.readInt();
for (int i = 0; i < size; i++) {
String key = in.readUTF();
ValueType valueType = SerialEnum.fromCode(ValueType.class, in.readByte());
Value value = this.graphFactory.createValue(valueType);
value.read(in);
this.keyValues.put(key, value);
}
}
Aggregations