Search in sources :

Example 1 with PartitionTree

use of IncrementalAnytimeExactBeliefPropagation.PartitionTree in project aic-expresso by aic-sri-international.

the class BFS method next.

@Override
public PartitionTree next() {
    if (first) {
        first = false;
        return this.partitionQuery;
    }
    if (!hasNext())
        throw new NoSuchElementException();
    // removes from front of queue
    FactorNode nextFactor = queue.remove();
    PartitionTree nextFactorPartition = fromNodeToPartition.get(nextFactor);
    for (VariableNode neighborVariable : graph.getAsOfB(nextFactor)) {
        PartitionTree neighborVariablePartition = fromNodeToPartition.get(neighborVariable);
        if (neighborVariablePartition == null) {
            neighborVariablePartition = new PartitionTree(neighborVariable, nextFactorPartition);
            fromNodeToPartition.put(neighborVariable, neighborVariablePartition);
        }
        for (FactorNode neighborFactor : graph.getBsOfA(neighborVariable)) {
            if (!visited.contains(neighborFactor)) {
                PartitionTree neighborFactorPartition = new PartitionTree(neighborFactor, neighborVariablePartition);
                fromNodeToPartition.put(neighborFactor, neighborFactorPartition);
                queue.add(neighborFactor);
                visited.add(neighborFactor);
            }
        }
    }
    return nextFactorPartition;
}
Also used : PartitionTree(IncrementalAnytimeExactBeliefPropagation.PartitionTree) VariableNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode) NoSuchElementException(java.util.NoSuchElementException) FactorNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.FactorNode)

Aggregations

FactorNode (IncrementalAnytimeExactBeliefPropagation.Model.Node.FactorNode)1 VariableNode (IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode)1 PartitionTree (IncrementalAnytimeExactBeliefPropagation.PartitionTree)1 NoSuchElementException (java.util.NoSuchElementException)1