JACK: JASE example
// Performs depth-first exploration of a search tree
public class SDepthFirstExploration implements SExploration
{
private ObjectContainer stack = new ObjectContainer();
private SChoice rootChoice; // for reset()
private SMarkedConstraintSystem rootSystem; // for reset
public SDepthFirstExploration(ConstraintSystem system,SChoice choice)
{
rootChoice=choice;
reset(system);
}
// Reset everything
public void reset(ConstraintSystem system)
{
// restore the constraint system and re-initialise the root choice
rootSystem=system.createMarkedSystem();
rootChoice.reset();
// Push the root node onto the stack
stack.removeAll();
stack.add(new SNode(rootSystem,rootChoice));
}
// Returns null when finished
public SNode performOneStep()
{
int stackSize=stack.size();
if (stackSize==0) return null;
// Pop the current element from the stack
SNode node=(SNode)(stack.get(stackSize-1));
stack.remove(stackSize-1);
// If this is one of the special nodes, return it
// (it has no children)
if (node.isSuccess() || node.isFailure())
return node;
// Create the child
SNode nextNode=node.createNextChild();
// Push the same node again, if this wasn't the last child
if (node.hasMoreChildren())
stack.add(node);
// Push the child
stack.add(nextNode);
return nextNode;
}
}
Last modified: Mon Apr 9 11:59:25 CEST 2001