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;
}
Aggregations