Inconsistency between the lists variablesToEliminate and nodesToEliminate in EliminationHeuristic

Create issue
Issue #227 resolved
Miguel Ángel Artaso Landa created an issue

In the class EliminationHeuristic there is an slight inconsistency between the creation of the lists of lists variablesToEliminate and nodesToEliminate. It may not affect the heuristics, but I think we should create both lists in the same way.

In the 'for' clause that starts in line number 60, the code is as follows:

List<Variable> listOfVariables = new ArrayList<Variable>(list.size());
for(Variable variable : list)
{
    if(probNet.containsVariable(variable))
        listOfVariables.add(variable);
}
this.variablesToEliminate.add(listOfVariables);

So it may happen that a list is created empty.

Then, in the creation of nodesToEliminate, we find the following code

List<Node> nodes = new ArrayList<>(variables.size());
for(Variable variable : variables)
{
    nodes.add(probNet.getNode(variable));
}
    if (nodes.size()>0){
        this.nodesToEliminate.add(nodes);
}

So the list of nodes to eliminate is only added to the list of lists if it is not empty.

Similarly, in the undoableEditHappened class, we find this piece of code:

if (listIndex >= 0) {
    variablesToEliminate.get(listOfListsIndex).remove(listIndex);
}
if(variablesToEliminate.get(listOfListsIndex).isEmpty()) {
    variablesToEliminate.remove(listOfListsIndex);
}
if (listIndex >= 0) {
    nodesToEliminate.get(listOfListsIndex).remove(listIndex);
    if (nodesToEliminate.get(listOfListsIndex).isEmpty()) {
        nodesToEliminate.remove(listOfListsIndex);
    }
}

Where the items in the lists of lists are not removed exactly in the same conditions.

As stated at the beginning of the issue, it may not affect the heuristics as it is related to the network. But maybe there appears a network which inference might fail.

Comments (2)

  1. Miguel Ángel Artaso Landa reporter

    EliminationHeuristic class has been adapted so now both lists are created consistently one with each other

  2. Log in to comment