use of com.baidu.hugegraph.computer.core.graph.value.IdListList in project hugegraph-computer by hugegraph.
the class MockComputation method compute0.
@Override
public void compute0(ComputationContext context, Vertex vertex) {
IdListList value = new IdListList();
vertex.value(value);
Edges edges = vertex.edges();
checkEdgesSize(edges);
checkEdgesSize(edges);
if (RANDOM.nextInt() % 10 == 0) {
vertex.inactivate();
}
}
use of com.baidu.hugegraph.computer.core.graph.value.IdListList in project hugegraph-computer by hugegraph.
the class RingsDetection method compute.
@Override
public void compute(ComputationContext context, Vertex vertex, Iterator<IdList> messages) {
Id id = vertex.id();
boolean halt = true;
while (messages.hasNext()) {
halt = false;
IdList sequence = messages.next();
if (id.equals(sequence.get(0))) {
// Use the smallest vertex record ring
boolean isMin = true;
for (int i = 1; i < sequence.size(); i++) {
Id pathVertexValue = sequence.get(i);
if (id.compareTo(pathVertexValue) > 0) {
isMin = false;
break;
}
}
if (isMin) {
sequence.add(id);
IdListList sequences = vertex.value();
sequences.add(sequence);
}
} else {
boolean contains = false;
// Drop sequence if path contains this vertex
for (int i = 0; i < sequence.size(); i++) {
Id pathVertexValue = sequence.get(i);
if (pathVertexValue.equals(vertex.id())) {
contains = true;
break;
}
}
// Field ringId is smallest vertex id in path
Id ringId = sequence.get(0);
if (!contains) {
sequence.add(vertex.id());
for (Edge edge : vertex.edges()) {
if (ringId.compareTo(edge.targetId()) <= 0) {
context.sendMessage(edge.targetId(), sequence);
}
}
}
}
}
if (halt) {
vertex.inactivate();
}
}
use of com.baidu.hugegraph.computer.core.graph.value.IdListList in project hugegraph-computer by hugegraph.
the class RingsDetectionOutput method value.
@Override
protected List<String> value(Vertex vertex) {
IdListList value = vertex.value();
List<String> propValues = new ArrayList<>();
for (int i = 0; i < value.size(); i++) {
propValues.add(value.get(i).toString());
}
return propValues;
}
use of com.baidu.hugegraph.computer.core.graph.value.IdListList in project hugegraph-computer by hugegraph.
the class JsonStructGraphOutputTest method testWriteReadVertexWithProperties.
@Test
public void testWriteReadVertexWithProperties() throws IOException {
UnitTestBase.updateOptions(ComputerOptions.OUTPUT_WITH_ADJACENT_EDGES, "false", ComputerOptions.OUTPUT_WITH_VERTEX_PROPERTIES, "true", ComputerOptions.OUTPUT_WITH_EDGE_PROPERTIES, "false", ComputerOptions.OUTPUT_RESULT_NAME, "rank");
ComputerContext context = context();
GraphFactory factory = context.graphFactory();
Id longId = BytesId.of(100L);
IdListList idListList = new IdListList();
IdList idList1 = new IdList();
idList1.add(BytesId.of(66L));
IdList idList2 = new IdList();
idList2.add(BytesId.of(998L));
idList2.add(BytesId.of(999L));
idListList.add(idList1);
idListList.add(idList2);
Vertex vertex = factory.createVertex(longId, idListList);
vertex.properties().put("boolean", new BooleanValue(true));
vertex.properties().put("byte", new IntValue(127));
vertex.properties().put("short", new IntValue(16383));
vertex.properties().put("int", new IntValue(1000000));
vertex.properties().put("long", new LongValue(10000000000L));
vertex.properties().put("float", new FloatValue(0.1F));
vertex.properties().put("double", new DoubleValue(-0.01D));
vertex.properties().put("idvalue", longId);
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\":[[66],[998,999]]," + "\"properties\":{\"boolean\":true," + "\"byte\":127,\"double\":-0.01," + "\"short\":16383,\"idvalue\":100," + "\"float\":0.1,\"int\":1000000," + "\"long\":10000000000}}" + System.lineSeparator(), json);
} finally {
FileUtils.deleteQuietly(file);
}
}
use of com.baidu.hugegraph.computer.core.graph.value.IdListList in project hugegraph-computer by hugegraph.
the class CsvStructGraphOutputTest method testWriteReadVertexWithProperties.
@Test
public void testWriteReadVertexWithProperties() throws IOException {
UnitTestBase.updateOptions(ComputerOptions.OUTPUT_WITH_ADJACENT_EDGES, "false", ComputerOptions.OUTPUT_WITH_VERTEX_PROPERTIES, "true", ComputerOptions.OUTPUT_WITH_EDGE_PROPERTIES, "false");
ComputerContext context = context();
GraphFactory factory = context.graphFactory();
Id longId = BytesId.of(100L);
IdListList idListList = new IdListList();
IdList idList1 = new IdList();
idList1.add(BytesId.of(66L));
IdList idList2 = new IdList();
idList2.add(BytesId.of(998L));
idList2.add(BytesId.of(999L));
idListList.add(idList1);
idListList.add(idList2);
Vertex vertex = factory.createVertex(longId, idListList);
vertex.properties().put("boolean", new BooleanValue(true));
vertex.properties().put("byte", new IntValue(127));
vertex.properties().put("short", new IntValue(16383));
vertex.properties().put("int", new IntValue(1000000));
vertex.properties().put("long", new LongValue(10000000000L));
vertex.properties().put("float", new FloatValue(0.1F));
vertex.properties().put("double", new DoubleValue(-0.01D));
vertex.properties().put("idvalue", longId);
String fileName = "output3.csv";
File file = new File(fileName);
try {
BufferedFileOutput dos = new BufferedFileOutput(file);
StructGraphOutput output = (StructGraphOutput) IOFactory.createGraphOutput(context, OutputFormat.CSV, dos);
output.writeVertex(vertex);
dos.close();
@SuppressWarnings("deprecation") String text = FileUtils.readFileToString(file);
Assert.assertEquals("100,[[66],[998,999]],{true,127,-0.01,16383," + "100,0.1,1000000,10000000000}" + System.lineSeparator(), text);
} finally {
FileUtils.deleteQuietly(file);
}
}
Aggregations