use of ai.grakn.graql.internal.gremlin.spanningtree.graph.Node in project grakn by graknlabs.
the class ChuLiuEdmondsTest method testNegativeWeightWithNodeObject.
@Test
public void testNegativeWeightWithNodeObject() {
Map<NodeId, Node> nodes = new HashMap<>();
Node node0 = Node.addIfAbsent(NodeId.NodeType.VAR, var("0"), nodes);
Node node1 = Node.addIfAbsent(NodeId.NodeType.VAR, var("1"), nodes);
Node node2 = Node.addIfAbsent(NodeId.NodeType.VAR, var("2"), nodes);
final WeightedGraph<Node> Isa = SparseWeightedGraph.from(ImmutableList.of(weighted(DirectedEdge.from(node0).to(node1), -0.69), weighted(DirectedEdge.from(node1).to(node2), 0), weighted(DirectedEdge.from(node2).to(node1), -4.62), weighted(DirectedEdge.from(node1).to(node0), 0)));
Weighted<Arborescence<Node>> weightedSpanningTree = ChuLiuEdmonds.getMaxArborescence(Isa, node2);
assertEquals(-4.62, weightedSpanningTree.weight, DELTA);
ImmutableMap<Node, Node> edges = weightedSpanningTree.val.getParents();
assertEquals(2, edges.size());
assertEquals(node2, edges.get(node1));
assertEquals(node1, edges.get(node0));
}
use of ai.grakn.graql.internal.gremlin.spanningtree.graph.Node in project grakn by graknlabs.
the class GreedyTraversalPlan method processFragmentWithFixedCost.
private static void processFragmentWithFixedCost(List<Fragment> plan, Map<NodeId, Node> allNodes, Set<Node> connectedNodes, Map<Node, Double> nodesWithFixedCost, EmbeddedGraknTx<?> tx, Fragment fragment) {
Node start = Node.addIfAbsent(NodeId.NodeType.VAR, fragment.start(), allNodes);
connectedNodes.add(start);
if (fragment.hasFixedFragmentCost()) {
// fragments that should be done right away
plan.add(fragment);
double logInstanceCount = -1D;
Optional<Long> shardCount = fragment.getShardCount(tx);
if (shardCount.isPresent() && shardCount.get() > 0) {
logInstanceCount = Math.log(shardCount.get() - 1D + SHARD_LOAD_FACTOR) + Math.log(tx.shardingThreshold());
}
nodesWithFixedCost.put(start, logInstanceCount);
start.setFixedFragmentCost(fragment.fragmentCost());
} else if (fragment.dependencies().isEmpty()) {
// fragments that should be done when a node has been visited
start.getFragmentsWithoutDependency().add(fragment);
}
}
Aggregations