Search in sources :

Example 31 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class Wcc method compute.

@Override
public void compute(ComputationContext context, Vertex vertex, Iterator<Id> messages) {
    Id message = Combiner.combineAll(context.combiner(), messages);
    Id value = vertex.value();
    if (value.compareTo(message) > 0) {
        vertex.value(message);
        context.sendMessageToAllEdges(vertex, message);
    }
    vertex.inactivate();
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id)

Example 32 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id 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();
    }
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) IdListList(com.baidu.hugegraph.computer.core.graph.value.IdListList)

Example 33 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class BetweennessMessage method compareTo.

@Override
public int compareTo(Value value) {
    E.checkArgument(value instanceof BetweennessMessage, "The BetweennessMessage can't compare with class '%s'", value.getClass());
    BetweennessMessage other = (BetweennessMessage) value;
    E.checkArgument(this.sequence.size() != 0, "Sequence can't be empty");
    E.checkArgument(other.sequence.size() != 0, "Sequence can't be empty");
    Id selfSourceId = this.sequence.get(0);
    Id otherSourceId = other.sequence.get(0);
    return selfSourceId.compareTo(otherSourceId);
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id)

Example 34 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class ClosenessCentrality method compute0.

@Override
public void compute0(ComputationContext context, Vertex vertex) {
    // Set empty map as initial value
    vertex.value(new ClosenessValue());
    // Send messages to adjacent edges
    for (Edge edge : vertex.edges()) {
        Id senderId = vertex.id();
        // Get property value
        double value = this.weightValue(edge.property(this.weightProp));
        DoubleValue distance = new DoubleValue(value);
        ClosenessMessage message = new ClosenessMessage(senderId, senderId, distance);
        context.sendMessage(edge.targetId(), message);
    }
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 35 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class BetweennessCentrality method sendMessage.

private void sendMessage(ComputationContext context) {
    for (SeqCount seqCount : this.seqTable.values()) {
        for (Map.Entry<Id, Integer> entry : seqCount.idCount.entrySet()) {
            double vote = (double) entry.getValue() / seqCount.totalCount;
            BetweennessMessage voteMessage = new BetweennessMessage(new DoubleValue(vote));
            context.sendMessage(entry.getKey(), voteMessage);
        }
    }
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Id (com.baidu.hugegraph.computer.core.graph.id.Id)74 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)51 Test (org.junit.Test)29 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)18 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)12 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)12 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)12 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)12 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)11 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)10 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)9 ConnectionId (com.baidu.hugegraph.computer.core.network.ConnectionId)8 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)7 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)6 File (java.io.File)6 Value (com.baidu.hugegraph.computer.core.graph.value.Value)5 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)5 Config (com.baidu.hugegraph.computer.core.config.Config)4 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)4