Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: superstep not take effect #237

Merged
merged 5 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.hugegraph.computer.core.common.exception.ComputerException;
import org.apache.hugegraph.computer.core.config.ComputerOptions;
import org.apache.hugegraph.computer.core.config.Config;
import org.apache.hugegraph.computer.core.receiver.MessageStat;
import org.apache.hugegraph.util.InsertionOrderUtil;

public class MessageSendBuffers {
Expand Down Expand Up @@ -67,6 +68,13 @@ public Map<Integer, MessageSendPartition> all() {
return all;
}

public MessageStat messageStat(int partitionId) {
if (partitionId < 0 || partitionId >= this.buffers.length) {
throw new ComputerException("Invalid partition id %s", partitionId);
}
return this.buffers[partitionId].messageWritten();
}

public void clear() {
for (MessageSendPartition partition : this.buffers) {
partition.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void finishSend(MessageType type) {
}

public MessageStat messageStat(int partitionId) {
return this.buffers.get(partitionId).messageWritten();
return this.buffers.messageStat(partitionId);
}

public void clearBuffer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,128 @@
package org.apache.hugegraph.computer.algorithm.community.lpa;

import org.apache.hugegraph.computer.algorithm.AlgorithmTestBase;
import org.apache.hugegraph.computer.core.config.ComputerOptions;
import org.apache.hugegraph.computer.core.output.hg.HugeGraphStringOutput;
import org.apache.hugegraph.driver.GraphManager;
import org.apache.hugegraph.driver.SchemaManager;
import org.apache.hugegraph.structure.constant.T;
import org.apache.hugegraph.structure.graph.Vertex;
import org.apache.hugegraph.testutil.Assert;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.HashSet;

public class LpaTest extends AlgorithmTestBase {

private static final String VERTX_LABEL = "tc_user";
private static final String EDGE_LABEL = "tc_know";
private static final String PROPERTY_KEY = "tc_weight";
protected static HashSet<String> communitySet = new HashSet<>();

@BeforeClass
public static void setup() {
clearAll();

SchemaManager schema = client().schema();

schema.propertyKey(PROPERTY_KEY).asText().ifNotExist().create();

schema.vertexLabel(VERTX_LABEL)
.properties(PROPERTY_KEY)
.enableLabelIndex(false)
.useCustomizeStringId()
.ifNotExist()
.create();


schema.edgeLabel(EDGE_LABEL)
.sourceLabel(VERTX_LABEL)
.targetLabel(VERTX_LABEL)
.properties(PROPERTY_KEY)
.enableLabelIndex(false)
.ifNotExist()
.create();

GraphManager graph = client().graph();
Vertex v0 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "0",
PROPERTY_KEY, "0");
Vertex v1 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "1",
PROPERTY_KEY, "1");
Vertex v2 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "2",
PROPERTY_KEY, "2");
Vertex v3 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "3",
PROPERTY_KEY, "3");
Vertex v4 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "4",
PROPERTY_KEY, "4");
Vertex v5 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "5",
PROPERTY_KEY, "5");
Vertex v6 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "6",
PROPERTY_KEY, "6");
Vertex v7 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "7",
PROPERTY_KEY, "7");
Vertex v8 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "8",
PROPERTY_KEY, "8");
Vertex v9 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "9",
PROPERTY_KEY, "9");
Vertex v10 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "10",
PROPERTY_KEY, "10");
Vertex v11 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "11",
PROPERTY_KEY, "11");
Vertex v12 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "12",
PROPERTY_KEY, "12");
Vertex v13 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "13",
PROPERTY_KEY, "13");
Vertex v14 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "14",
PROPERTY_KEY, "14");
Vertex v15 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "15",
PROPERTY_KEY, "15");
Vertex v16 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "16",
PROPERTY_KEY, "16");
Vertex v17 = graph.addVertex(T.LABEL, VERTX_LABEL, T.ID, "17",
PROPERTY_KEY, "17");

v0.addEdge(EDGE_LABEL, v4, PROPERTY_KEY, "1");
v0.addEdge(EDGE_LABEL, v7, PROPERTY_KEY, "1");
v0.addEdge(EDGE_LABEL, v10, PROPERTY_KEY, "1");
v0.addEdge(EDGE_LABEL, v11, PROPERTY_KEY, "1");
v0.addEdge(EDGE_LABEL, v14, PROPERTY_KEY, "1");
v0.addEdge(EDGE_LABEL, v16, PROPERTY_KEY, "1");
v1.addEdge(EDGE_LABEL, v17, PROPERTY_KEY, "1");
v2.addEdge(EDGE_LABEL, v5, PROPERTY_KEY, "1");
v2.addEdge(EDGE_LABEL, v6, PROPERTY_KEY, "1");
v2.addEdge(EDGE_LABEL, v8, PROPERTY_KEY, "1");
v2.addEdge(EDGE_LABEL, v12, PROPERTY_KEY, "1");
v3.addEdge(EDGE_LABEL, v9, PROPERTY_KEY, "1");
v3.addEdge(EDGE_LABEL, v13, PROPERTY_KEY, "1");
v9.addEdge(EDGE_LABEL, v15, PROPERTY_KEY, "1");
v16.addEdge(EDGE_LABEL, v5, PROPERTY_KEY, "1");
}

@AfterClass
public static void teardown() {
clearAll();
}

@Test
public void testRunAlgorithm() throws InterruptedException {
runAlgorithm(LpaParams.class.getName());
runAlgorithm(LpaParams.class.getName(),
ComputerOptions.OUTPUT_CLASS.name(),
LpaTest.LpaIntOutputTest.class.getName());

// check lpa result
Assert.assertEquals(4, communitySet.size());
}


public static class LpaIntOutputTest extends HugeGraphStringOutput {

@Override
JackyYangPassion marked this conversation as resolved.
Show resolved Hide resolved
public String value(org.apache.hugegraph.computer.core.graph.vertex.Vertex vertex) {
String value = super.value(vertex);
communitySet.add(value);
return value;
}
}
}