// statistics for debugging:
boolean debuggingMode=false;
int checkedBlocks=0;
int invalidBlocks=0;
TableauMonitor monitor=m_tableau.getTableauMonitor();
if (monitor!=null)
monitor.blockingValidationStarted();
Node node;
node=m_lastValidatedUnchangedNode==null ? m_tableau.getFirstTableauNode() : m_lastValidatedUnchangedNode;
Node firstValidatedNode=node;
while (node!=null) {
m_currentBlockersCache.removeNode(node);
node=node.getNextTableauNode();
}
node=firstValidatedNode;
if (debuggingMode)
System.out.print("Model size: "+(m_tableau.getNumberOfNodesInTableau()-m_tableau.getNumberOfMergedOrPrunedNodes())+" Current ID:");
Node firstInvalidlyBlockedNode=null;
while (node!=null) {
if (node.isActive()) {
if (node.isBlocked() && node.hasUnprocessedExistentials()) {
checkedBlocks++;
// check whether the block is a correct one
if ((node.isDirectlyBlocked() && (m_directBlockingChecker.hasChangedSinceValidation(node) || m_directBlockingChecker.hasChangedSinceValidation(node.getParent()) || m_directBlockingChecker.hasChangedSinceValidation(node.getBlocker()))) || !node.getParent().isBlocked()) {
Node validBlocker=null;
Node currentBlocker=node.getBlocker();
if (node.isDirectlyBlocked() && currentBlocker!=null) {
// try the old blocker fist
if (isBlockValid(node))
validBlocker=currentBlocker;
}
if (validBlocker==null) {
for (Node possibleBlocker : m_currentBlockersCache.getPossibleBlockers(node)) {
if (possibleBlocker!=currentBlocker) {
node.setBlocked(possibleBlocker,true);
m_permanentBlockingValidator.blockerChanged(node); // invalidate cache
if (m_additionalBlockingValidator!=null)
m_additionalBlockingValidator.blockerChanged(node);
if (isBlockValid(node)) {
validBlocker=possibleBlocker;
break;
}
}
}
}
if (validBlocker==null && node.hasUnprocessedExistentials()) {
invalidBlocks++;
if (firstInvalidlyBlockedNode==null)
firstInvalidlyBlockedNode=node;
}
node.setBlocked(validBlocker,validBlocker!=null);
}
}
m_lastValidatedUnchangedNode=node;
if (!node.isBlocked() && m_directBlockingChecker.canBeBlocker(node))
m_currentBlockersCache.addNode(node);
}
node=node.getNextTableauNode();
}
node=firstValidatedNode;
while (node!=null) {
if (node.isActive()) {
m_directBlockingChecker.setHasChangedSinceValidation(node,false);
ValidatedBlockingObject blockingObject=(ValidatedBlockingObject)node.getBlockingObject();
blockingObject.setBlockViolatesParentConstraints(false);
blockingObject.setHasAlreadyBeenChecked(false);
}
node=node.getNextTableauNode();
}
// if set to some node, then computePreblocking will be asked to check from that node onwards in case of invalid blocks
m_firstChangedNode=firstInvalidlyBlockedNode;
if (monitor!=null)
monitor.blockingValidationFinished(invalidBlocks);
if (debuggingMode) {
System.out.println("");
System.out.println("Checked "+checkedBlocks+" blocked nodes of which "+invalidBlocks+" were invalid.");
}