abox.getCompletionQueue().add( qElement, NodeSelector.MAX_NUMBER );
abox.getCompletionQueue().add( qElement, NodeSelector.CHOOSE );
}
DependencySet ds = getTermDepends();
for(; getTryNext() < getTryCount(); tryNext++) {
this.abox.getKB().timers.mainTimer.check();
if(PelletOptions.USE_SEMANTIC_BRANCHING) {
for(int m = 0; m < getTryNext(); m++) {
NodeMerge nm = mergePairs.get(m);
Node y = abox.getNode(nm.getSource()).getSame();
Node z = abox.getNode(nm.getTarget()).getSame();
y.setDifferent( z, prevDS[m]);
//strategy.addType( y, ATermUtils.makeNot( ATermUtils.makeValue( z.getName() ) ), prevDS[m] );
}
}
NodeMerge nm = mergePairs.get(getTryNext());
Node y = abox.getNode(nm.getSource()).getSame();
Node z = abox.getNode(nm.getTarget()).getSame();
if( log.isLoggable( Level.FINE ) )
log.fine(
"MAX : (" + (getTryNext()+1) + "/" + mergePairs.size() +
") at branch (" + getBranch() + ") to " + ind +
" for prop " + r + " qualification " + qualification +
" merge " + y + " -> " + z + " " + ds);
ds = ds.union(new DependencySet(getBranch()), abox.doExplanation());
// max cardinality merge also depends on all the edges
// between the individual that has the cardinality and
// nodes that are going to be merged
EdgeList rNeighbors = ind.getRNeighborEdges(r);
boolean yEdge = false, zEdge = false;
for( Edge edge : rNeighbors ) {
Node neighbor = edge.getNeighbor( ind );
if( neighbor.equals( y ) ) {
ds = ds.union( edge.getDepends(), abox.doExplanation() );
yEdge = true;
}
else if( neighbor.equals( z ) ) {
ds = ds.union( edge.getDepends(), abox.doExplanation() );
zEdge = true;
}
}
// if there is no edge coming into the node that is
// going to be merged then it is not possible that
// they are affected by the cardinality restriction
// just die instead of possibly unsound results
if(!yEdge || !zEdge)
throw new InternalReasonerException(
"An error occurred related to the max cardinality restriction about " + r);
// if the neighbor nodes did not have the qualification
// in their type list they would have not been affected
// by the cardinality restriction. so this merges depends
// on their types
ds = ds.union( y.getDepends( qualification ), abox.doExplanation() );
ds = ds.union( z.getDepends( qualification ), abox.doExplanation() );
// if there were other merges based on the exact same cardinality
// restriction then this merge depends on them, too (we wouldn't
// have to merge these two nodes if the previous merge did not
// eliminate some other possibilities)
for( int b = abox.getBranches().size() -2; b >=0; b-- ) {
Branch branch = abox.getBranches().get( b );
if( branch instanceof MaxBranch ) {
MaxBranch prevBranch = (MaxBranch) branch;
if( prevBranch.ind.equals( ind )
&& prevBranch.r.equals( r )
&& prevBranch.qualification.equals( qualification ) ) {
ds.add( prevBranch.getBranch() );
}
else {
break;
}
}
else
break;
}
strategy.mergeTo(y, z, ds);
// abox.validate();
boolean earlyClash = abox.isClosed();
if(earlyClash) {
if( log.isLoggable( Level.FINE ) )
log.fine("CLASH: Branch " + getBranch() + " " + abox.getClash() + "!");
DependencySet clashDepends = abox.getClash().getDepends();
if(clashDepends.contains(getBranch())) {
// we need a global restore here because the merge operation modified three
// different nodes and possibly other global variables
strategy.restore(this);
// global restore sets the branch number to previous value so we need to