Search in sources :

Example 11 with IdList

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);
        }
    }
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Example 12 with IdList

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);
        }
    }
}
Also used : Random(java.util.Random) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Example 13 with IdList

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);
}
Also used : MessageRecvManager(com.baidu.hugegraph.computer.core.receiver.MessageRecvManager) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) NetworkBuffer(com.baidu.hugegraph.computer.core.network.buffer.NetworkBuffer) ArrayList(java.util.ArrayList) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) List(java.util.List) IdListList(com.baidu.hugegraph.computer.core.graph.value.IdListList) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) Test(org.junit.Test)

Example 14 with IdList

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);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) File(java.io.File) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) Test(org.junit.Test)

Example 15 with IdList

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");
}
Also used : IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Aggregations

IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)20 Id (com.baidu.hugegraph.computer.core.graph.id.Id)18 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)14 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)7 ConnectionId (com.baidu.hugegraph.computer.core.network.ConnectionId)7 Test (org.junit.Test)5 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)4 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)4 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)4 File (java.io.File)4 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)3 Random (java.util.Random)3 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)2 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)2 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)2 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)2 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)2 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2