use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.
the class ComputeManagerTest method addMessages.
private static void addMessages(Consumer<NetworkBuffer> consumer) throws IOException {
for (long i = 0L; i < 200L; i++) {
int count = RANDOM.nextInt(5);
for (int j = 0; j < count; j++) {
Id id = BytesId.of(i);
IdList message = new IdList();
message.add(id);
ReceiverUtil.consumeBuffer(ReceiverUtil.writeMessage(id, message), consumer);
}
}
}
use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.
the class MessageInputTest method addMessages.
private static void addMessages(Consumer<NetworkBuffer> consumer) throws IOException {
Random random = new Random(1);
for (long i = 0L; i < 200L; i++) {
int count = random.nextInt(5);
for (int j = 0; j < count; j++) {
Id id = BytesId.of(random.nextInt(200));
IdList message = new IdList();
message.add(id);
ReceiverUtil.consumeBuffer(ReceiverUtil.writeMessage(id, message), consumer);
}
}
}
use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.
the class MessageInputTest method testMessageInput.
@Test
public void testMessageInput() throws IOException {
MessageRecvManager receiveManager = this.managers.get(MessageRecvManager.NAME);
receiveManager.onStarted(this.connectionId);
// Superstep 0
receiveManager.beforeSuperstep(this.config, 0);
receiveManager.onStarted(this.connectionId);
addMessages((NetworkBuffer buffer) -> {
receiveManager.handle(MessageType.MSG, 0, buffer);
});
receiveManager.onFinished(this.connectionId);
PeekableIterator<KvEntry> it = receiveManager.messagePartitions().get(0);
MessageInput<IdList> input = new MessageInput<>(context(), it);
Map<Id, List<IdList>> expectedMessages = expectedMessages();
checkMessages(expectedMessages, input);
}
use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.
the class JsonStructGraphOutputTest method testWriteReadVertexWithEdges.
@Test
public void testWriteReadVertexWithEdges() throws IOException {
UnitTestBase.updateOptions(ComputerOptions.OUTPUT_WITH_ADJACENT_EDGES, "true", ComputerOptions.OUTPUT_WITH_VERTEX_PROPERTIES, "false", ComputerOptions.OUTPUT_WITH_EDGE_PROPERTIES, "false", ComputerOptions.OUTPUT_RESULT_NAME, "rank");
ComputerContext context = context();
GraphFactory factory = context.graphFactory();
Id longId = BytesId.of(100L);
IdList idList = new IdList();
idList.add(BytesId.of(998L));
idList.add(BytesId.of(999L));
Vertex vertex = factory.createVertex(longId, idList);
vertex.addEdge(factory.createEdge("knows", BytesId.of(200)));
vertex.addEdge(factory.createEdge("watch", "1111", BytesId.of(300)));
String fileName = "output.json";
File file = new File(fileName);
try {
BufferedFileOutput dos = new BufferedFileOutput(file);
StructGraphOutput output = (StructGraphOutput) IOFactory.createGraphOutput(context, OutputFormat.JSON, dos);
output.writeVertex(vertex);
dos.close();
@SuppressWarnings("deprecation") String json = FileUtils.readFileToString(file);
Assert.assertEquals("{\"id\":100,\"rank\":[998,999]," + "\"adjacent_edges\":[{\"target_id\":200," + "\"label\":\"knows\",\"name\":\"\"}," + "{\"target_id\":300,\"label\":\"watch\"," + "\"name\":\"1111\"}]}" + System.lineSeparator(), json);
} finally {
FileUtils.deleteQuietly(file);
}
}
use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.
the class BetweennessCentrality method compute0.
@Override
public void compute0(ComputationContext context, Vertex vertex) {
// First superstep is special, we just send vertex id to its neighbors
BetweennessValue initialValue = new BetweennessValue(0.0D);
initialValue.arrivedVertices().add(vertex.id());
vertex.value(initialValue);
if (vertex.numEdges() == 0) {
return;
}
IdList sequence = new IdList();
sequence.add(vertex.id());
context.sendMessageToAllEdges(vertex, new BetweennessMessage(sequence));
LOG.info("Finished compute-0 step");
}
Aggregations