本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.computer.Messenger.sendMessage方法的典型用法代码示例。如果您正苦于以下问题:Java Messenger.sendMessage方法的具体用法?Java Messenger.sendMessage怎么用?Java Messenger.sendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tinkerpop.gremlin.process.computer.Messenger
的用法示例。
在下文中一共展示了Messenger.sendMessage方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
@Override
public void execute(final Vertex vertex, Messenger<Double> messenger, final Memory memory) {
if (memory.isInitialIteration()) {
messenger.sendMessage(this.countMessageScope, 1.0d);
} else if (1 == memory.getIteration()) {
double initialPageRank = (null == this.initialRankTraversal ?
1.0d :
TraversalUtil.apply(vertex, this.initialRankTraversal.get()).doubleValue()) / this.vertexCountAsDouble;
double edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
vertex.property(VertexProperty.Cardinality.single, this.property, initialPageRank);
vertex.property(VertexProperty.Cardinality.single, EDGE_COUNT, edgeCount);
if (!this.terminate(memory)) // don't send messages if this is the last iteration
messenger.sendMessage(this.incidentMessageScope, initialPageRank / edgeCount);
} else {
double newPageRank = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
newPageRank = (this.alpha * newPageRank) + ((1.0d - this.alpha) / this.vertexCountAsDouble);
vertex.property(VertexProperty.Cardinality.single, this.property, newPageRank);
if (!this.terminate(memory)) // don't send messages if this is the last iteration
messenger.sendMessage(this.incidentMessageScope, newPageRank / vertex.<Double>value(EDGE_COUNT));
}
}
示例2: execute
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
@Override
public void execute(Vertex vertex, Messenger<Double> messenger, Memory memory) {
if (memory.isInitialIteration()) {
messenger.sendMessage(inE, 1D);
} else if (1 == memory.getIteration()) {
double initialPageRank = 1D / vertexCount;
double edgeCount = IteratorUtils.stream(messenger.receiveMessages()).reduce(0D, (a, b) -> a + b);
vertex.property(VertexProperty.Cardinality.single, PAGE_RANK, initialPageRank);
vertex.property(VertexProperty.Cardinality.single, OUTGOING_EDGE_COUNT, edgeCount);
messenger.sendMessage(outE, initialPageRank / edgeCount);
} else {
double newPageRank = IteratorUtils.stream(messenger.receiveMessages()).reduce(0D, (a, b) -> a + b);
newPageRank = (dampingFactor * newPageRank) + ((1D - dampingFactor) / vertexCount);
vertex.property(VertexProperty.Cardinality.single, PAGE_RANK, newPageRank);
messenger.sendMessage(outE, newPageRank / vertex.<Double>value(OUTGOING_EDGE_COUNT));
}
}
示例3: safeExecute
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
@Override
public void safeExecute(final Vertex vertex, Messenger<String> messenger, final Memory memory) {
if (memory.isInitialIteration()) {
String id = vertex.value(Schema.VertexProperty.ID.name());
vertex.property(CLUSTER_LABEL, id);
messenger.sendMessage(messageScopeIn, id);
messenger.sendMessage(messageScopeOut, id);
} else {
updateClusterLabel(vertex, messenger, memory);
}
}
示例4: updateClusterLabel
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
private static void updateClusterLabel(Vertex vertex, Messenger<String> messenger, Memory memory) {
String currentMax = vertex.value(CLUSTER_LABEL);
String max = IteratorUtils.reduce(messenger.receiveMessages(), currentMax,
(a, b) -> a.compareTo(b) > 0 ? a : b);
if (max.compareTo(currentMax) > 0) {
vertex.property(CLUSTER_LABEL, max);
messenger.sendMessage(messageScopeIn, max);
messenger.sendMessage(messageScopeOut, max);
memory.add(VOTE_TO_HALT, false);
}
}
示例5: degreeStatisticsStepResourceOwner
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
static void degreeStatisticsStepResourceOwner(Vertex vertex, Messenger<Long> messenger, Set<LabelId> ofLabelIds) {
LabelId labelId = Utility.getVertexTypeId(vertex);
if (labelId.isValid() && !ofLabelIds.contains(labelId)) {
messenger.sendMessage(messageScopeShortcutIn, 1L);
messenger.sendMessage(messageScopeResourceOut, 1L);
}
}
示例6: degreeStatisticsStepResourceRelation
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
static void degreeStatisticsStepResourceRelation(Vertex vertex, Messenger<Long> messenger, Set<LabelId> ofLabelIds) {
if (messenger.receiveMessages().hasNext()) {
if (vertex.label().equals(Schema.BaseType.RELATIONSHIP.name())) {
messenger.sendMessage(messageScopeOut, 1L);
} else if (ofLabelIds.contains(Utility.getVertexTypeId(vertex))) {
vertex.property(DEGREE, getMessageCount(messenger));
}
}
}
示例7: safeExecute
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
@Override
public void safeExecute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) {
switch (memory.getIteration()) {
case 0:
messenger.sendMessage(messageScopeOut, 1L);
break;
case 1:
if (messenger.receiveMessages().hasNext()) {
vertex.property(EDGE_COUNT, getMessageCount(messenger));
}
break;
default:
throw CommonUtil.unreachableStatement("Exceeded expected maximum number of iterations");
}
}
示例8: execute
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
@Override
public void execute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) {
if (memory.isInitialIteration()) {
if (vertex.id().equals(Long.valueOf(seed).longValue())) {
// The seed sends a single message to start the computation
log.debug("Sent initial message from {}", vertex.id());
// The seed's distance to itself is zero
vertex.property(VertexProperty.Cardinality.single, DISTANCE, 0L);
messenger.sendMessage(incidentMessageScope, 0L);
}
} else {
Iterator<Long> distances = messenger.receiveMessages();
// Find minimum distance among all incoming messages, or null if no messages came in
Long shortestDistanceSeenOnThisIteration =
IteratorUtils.stream(distances).reduce((a, b) -> Math.min(a, b)).orElse(null);
if (null == shortestDistanceSeenOnThisIteration)
return; // no messages to process or forward on this superstep
VertexProperty<Long> currentShortestVP = vertex.property(DISTANCE);
if (!currentShortestVP.isPresent() ||
currentShortestVP.value() > shortestDistanceSeenOnThisIteration) {
// First/shortest distance seen by this vertex: store it and forward to neighbors
vertex.property(VertexProperty.Cardinality.single, DISTANCE, shortestDistanceSeenOnThisIteration);
messenger.sendMessage(incidentMessageScope, shortestDistanceSeenOnThisIteration);
}
// else: no new winner, ergo no reason to send message to neighbors
}
}
示例9: execute
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
@Override
public void execute(final Vertex vertex, Messenger<Double> messenger, final Memory memory) {
if (memory.isInitialIteration()) {
messenger.sendMessage(this.countMessageScope, 1.0d);
memory.add(VERTEX_COUNT, 1.0d);
} else {
final double vertexCount = memory.<Double>get(VERTEX_COUNT);
final double edgeCount;
double pageRank;
if (1 == memory.getIteration()) {
edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
vertex.property(VertexProperty.Cardinality.single, EDGE_COUNT, edgeCount);
pageRank = null == this.initialRankTraversal ?
0.0d :
TraversalUtil.apply(vertex, this.initialRankTraversal.get()).doubleValue();
} else {
edgeCount = vertex.value(EDGE_COUNT);
pageRank = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
}
//////////////////////////
final double teleporationEnergy = memory.get(TELEPORTATION_ENERGY);
if (teleporationEnergy > 0.0d) {
final double localTerminalEnergy = teleporationEnergy / vertexCount;
pageRank = pageRank + localTerminalEnergy;
memory.add(TELEPORTATION_ENERGY, -localTerminalEnergy);
}
final double previousPageRank = vertex.<Double>property(this.property).orElse(0.0d);
memory.add(CONVERGENCE_ERROR, Math.abs(pageRank - previousPageRank));
vertex.property(VertexProperty.Cardinality.single, this.property, pageRank);
memory.add(TELEPORTATION_ENERGY, (1.0d - this.alpha) * pageRank);
pageRank = this.alpha * pageRank;
if (edgeCount > 0.0d)
messenger.sendMessage(this.incidentMessageScope, pageRank / edgeCount);
else
memory.add(TELEPORTATION_ENERGY, pageRank);
}
}
示例10: sendMessage
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
private static void sendMessage(Messenger<PathMessage> messenger, PathMessage message) {
messenger.sendMessage(messageScopeIn, message);
messenger.sendMessage(messageScopeOut, message);
}
示例11: sendMessage
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
private static void sendMessage(Messenger<String> messenger, String message) {
messenger.sendMessage(messageScopeIn, message);
messenger.sendMessage(messageScopeOut, message);
}
示例12: degreeMessagePassing
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
private void degreeMessagePassing(Messenger<Long> messenger) {
messenger.sendMessage(messageScopeIn, 1L);
messenger.sendMessage(messageScopeOut, 1L);
}
示例13: update
import org.apache.tinkerpop.gremlin.process.computer.Messenger; //导入方法依赖的package包/类
private static void update(Vertex vertex, Messenger<Boolean> messenger, Memory memory, String label) {
messenger.sendMessage(messageScopeIn, MESSAGE);
messenger.sendMessage(messageScopeOut, MESSAGE);
vertex.property(CLUSTER_LABEL, label);
memory.add(VOTE_TO_HALT, false);
}