Search in sources :

Example 1 with LongValue

use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.

the class EdgesInputTest method addEdgeBuffer.

private static void addEdgeBuffer(Consumer<ManagedBuffer> consumer, EdgeFrequency freq) throws IOException {
    for (long i = 0L; i < 200L; i++) {
        Vertex vertex = graphFactory().createVertex();
        vertex.id(BytesId.of(i));
        int count = (int) i;
        if (count == 0) {
            continue;
        }
        Edges edges = graphFactory().createEdges(count);
        for (long j = 0; j < count; j++) {
            Edge edge = graphFactory().createEdge();
            switch(freq) {
                case SINGLE:
                    edge.targetId(BytesId.of(j));
                    break;
                case SINGLE_PER_LABEL:
                    edge.label(String.valueOf(j));
                    edge.targetId(BytesId.of(j));
                    break;
                case MULTIPLE:
                    edge.name(String.valueOf(j));
                    edge.label(String.valueOf(j));
                    edge.targetId(BytesId.of(j));
                    break;
                default:
                    throw new ComputerException("Illegal edge frequency %s", freq);
            }
            Properties properties = graphFactory().createProperties();
            properties.put("p1", new LongValue(i));
            edge.properties(properties);
            edges.add(edge);
        }
        vertex.edges(edges);
        ReceiverUtil.consumeBuffer(writeEdges(vertex, freq), consumer);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 2 with LongValue

use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.

the class MockMasterComputation2 method assertStep0Aggregators.

@Override
protected void assertStep0Aggregators(MasterComputationContext context) {
    Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
    Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
    Assert.assertEquals(new FloatValue(6.28f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
    Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
    Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
    Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
    Assert.assertEquals(new LongValue(10L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
    Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
    Assert.assertEquals(new FloatValue(20.8f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
    Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
    Assert.assertEquals(new DoubleValue(20.8), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
    Assert.assertEquals(new DoubleValue(-10.0), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 3 with LongValue

use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.

the class MockComputation method createAndRunAggregators.

protected void createAndRunAggregators(WorkerContext context) {
    // AGGR_CUSTOM_INT
    this.aggrCustomInt = context.createAggregator(MockMasterComputation.AGGR_CUSTOM_INT);
    Assert.assertEquals(new IntValue(0), this.aggrCustomInt.aggregatedValue());
    this.aggrCustomInt.aggregateValue(1);
    Assert.assertEquals(new IntValue(1), this.aggrCustomInt.aggregatedValue());
    this.aggrCustomInt.aggregateValue(new IntValue(1));
    Assert.assertEquals(new IntValue(2), this.aggrCustomInt.aggregatedValue());
    this.aggrCustomInt.aggregateValue(3);
    Assert.assertEquals(new IntValue(5), this.aggrCustomInt.aggregatedValue());
    // AGGR_CUSTOM_FLOAT
    this.aggrCustomFloat = context.createAggregator(MockMasterComputation.AGGR_CUSTOM_FLOAT);
    Assert.assertEquals(new FloatValue(0f), this.aggrCustomFloat.aggregatedValue());
    this.aggrCustomFloat.aggregateValue(1f);
    Assert.assertEquals(new FloatValue(1f), this.aggrCustomFloat.aggregatedValue());
    this.aggrCustomFloat.aggregateValue(new FloatValue(1f));
    Assert.assertEquals(new FloatValue(2f), this.aggrCustomFloat.aggregatedValue());
    this.aggrCustomFloat.aggregateValue(3.2f);
    Assert.assertEquals(new FloatValue(5.2f), this.aggrCustomFloat.aggregatedValue());
    // AGGR_INT_SUM
    this.aggrIntSum = context.createAggregator(MockMasterComputation.AGGR_INT_SUM);
    Assert.assertEquals(new IntValue(0), this.aggrIntSum.aggregatedValue());
    this.aggrIntSum.aggregateValue(1);
    Assert.assertEquals(new IntValue(1), this.aggrIntSum.aggregatedValue());
    this.aggrIntSum.aggregateValue(new IntValue(1));
    Assert.assertEquals(new IntValue(2), this.aggrIntSum.aggregatedValue());
    this.aggrIntSum.aggregateValue(3);
    Assert.assertEquals(new IntValue(5), this.aggrIntSum.aggregatedValue());
    // AGGR_INT_MAX
    this.aggrIntMax = context.createAggregator(MockMasterComputation.AGGR_INT_MAX);
    Assert.assertEquals(new IntValue(0), this.aggrIntMax.aggregatedValue());
    this.aggrIntMax.aggregateValue(1);
    Assert.assertEquals(new IntValue(1), this.aggrIntMax.aggregatedValue());
    this.aggrIntMax.aggregateValue(8);
    Assert.assertEquals(new IntValue(8), this.aggrIntMax.aggregatedValue());
    this.aggrIntMax.aggregateValue(3);
    Assert.assertEquals(new IntValue(8), this.aggrIntMax.aggregatedValue());
    // AGGR_LONG_SUM
    this.aggrLongSum = context.createAggregator(MockMasterComputation.AGGR_LONG_SUM);
    Assert.assertEquals(new LongValue(0L), this.aggrLongSum.aggregatedValue());
    this.aggrLongSum.aggregateValue(1L);
    Assert.assertEquals(new LongValue(1L), this.aggrLongSum.aggregatedValue());
    this.aggrLongSum.aggregateValue(new LongValue(1L));
    Assert.assertEquals(new LongValue(2L), this.aggrLongSum.aggregatedValue());
    this.aggrLongSum.aggregateValue(3L);
    Assert.assertEquals(new LongValue(5L), this.aggrLongSum.aggregatedValue());
    // AGGR_LONG_MAX
    this.aggrLongMax = context.createAggregator(MockMasterComputation.AGGR_LONG_MAX);
    Assert.assertEquals(new LongValue(0L), this.aggrLongMax.aggregatedValue());
    this.aggrLongMax.aggregateValue(1L);
    Assert.assertEquals(new LongValue(1L), this.aggrLongMax.aggregatedValue());
    this.aggrLongMax.aggregateValue(8L);
    Assert.assertEquals(new LongValue(8L), this.aggrLongMax.aggregatedValue());
    this.aggrLongMax.aggregateValue(3L);
    Assert.assertEquals(new LongValue(8L), this.aggrLongMax.aggregatedValue());
    // AGGR_FLOAT_SUM
    this.aggrFloatSum = context.createAggregator(MockMasterComputation.AGGR_FLOAT_SUM);
    Assert.assertEquals(new FloatValue(0.0f), this.aggrFloatSum.aggregatedValue());
    this.aggrFloatSum.aggregateValue(1.1f);
    Assert.assertEquals(new FloatValue(1.1f), this.aggrFloatSum.aggregatedValue());
    this.aggrFloatSum.aggregateValue(2.3f);
    Assert.assertEquals(new FloatValue(3.4f), this.aggrFloatSum.aggregatedValue());
    this.aggrFloatSum.aggregateValue(7.0f);
    Assert.assertEquals(new FloatValue(10.4f), this.aggrFloatSum.aggregatedValue());
    // AGGR_FLOAT_MIN
    this.aggrFloatMin = context.createAggregator(MockMasterComputation.AGGR_FLOAT_MIN);
    Assert.assertEquals(new FloatValue(0.0f), this.aggrFloatMin.aggregatedValue());
    this.aggrFloatMin.aggregateValue(1.1f);
    Assert.assertEquals(new FloatValue(0.0f), this.aggrFloatMin.aggregatedValue());
    this.aggrFloatMin.aggregateValue(-10.0f);
    Assert.assertEquals(new FloatValue(-10.0f), this.aggrFloatMin.aggregatedValue());
    this.aggrFloatMin.aggregateValue(-4.0f);
    Assert.assertEquals(new FloatValue(-10.0f), this.aggrFloatMin.aggregatedValue());
    // AGGR_DOUBLE_SUM
    this.aggrDoubleSum = context.createAggregator(MockMasterComputation.AGGR_DOUBLE_SUM);
    Assert.assertEquals(new DoubleValue(0.0), this.aggrDoubleSum.aggregatedValue());
    this.aggrDoubleSum.aggregateValue(1.1);
    Assert.assertEquals(new DoubleValue(1.1), this.aggrDoubleSum.aggregatedValue());
    this.aggrDoubleSum.aggregateValue(2.3);
    Assert.assertEquals(new DoubleValue(3.4), this.aggrDoubleSum.aggregatedValue());
    this.aggrDoubleSum.aggregateValue(7.0);
    Assert.assertEquals(new DoubleValue(10.4), this.aggrDoubleSum.aggregatedValue());
    // AGGR_DOUBLE_MIN
    this.aggrDoubleMin = context.createAggregator(MockMasterComputation.AGGR_DOUBLE_MIN);
    Assert.assertEquals(new DoubleValue(0.0), this.aggrDoubleMin.aggregatedValue());
    this.aggrDoubleMin.aggregateValue(1.1);
    Assert.assertEquals(new DoubleValue(0.0), this.aggrDoubleMin.aggregatedValue());
    this.aggrDoubleMin.aggregateValue(-10.0);
    Assert.assertEquals(new DoubleValue(-10.0), this.aggrDoubleMin.aggregatedValue());
    this.aggrDoubleMin.aggregateValue(-4.0);
    Assert.assertEquals(new DoubleValue(-10.0), this.aggrDoubleMin.aggregatedValue());
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 4 with LongValue

use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.

the class MockComputation method assertStep0Aggregators.

protected void assertStep0Aggregators(WorkerContext context) {
    Assert.assertEquals(new IntValue(0), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
    Assert.assertEquals(new FloatValue(0f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
    Assert.assertEquals(new FloatValue(0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
    Assert.assertEquals(new IntValue(Integer.MAX_VALUE), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
    Assert.assertEquals(new IntValue(0), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
    Assert.assertEquals(new IntValue(0), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
    Assert.assertEquals(new LongValue(0L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
    Assert.assertEquals(new LongValue(0L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
    Assert.assertEquals(new FloatValue(0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
    Assert.assertEquals(new FloatValue(0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
    Assert.assertEquals(new DoubleValue(0d), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
    Assert.assertEquals(new DoubleValue(0d), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 5 with LongValue

use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.

the class MockComputation2 method assertStep1Aggregators.

@Override
protected void assertStep1Aggregators(WorkerContext context) {
    Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
    Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
    Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
    Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
    Assert.assertEquals(new LongValue(10L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
    Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
    Assert.assertEquals(new FloatValue(20.8f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
    Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
    Assert.assertEquals(new DoubleValue(20.8), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
    Assert.assertEquals(new DoubleValue(-10.0), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Aggregations

LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)48 Test (org.junit.Test)25 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)21 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)19 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)16 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)13 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)13 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)9 Id (com.baidu.hugegraph.computer.core.graph.id.Id)9 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)8 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)8 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)7 DefaultProperties (com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties)7 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)5 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 Value (com.baidu.hugegraph.computer.core.graph.value.Value)3 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)3 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)3 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)2 Config (com.baidu.hugegraph.computer.core.config.Config)2