Generated on Thu Nov 2 14:49:35 2006 for Gecode/J by doxygen 1.5.0

DFS.java

Go to the documentation of this file.
00001 /* -*- indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Marco Kuhlmann <kuhlmann@ps.uni-sb.de>
00005  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Contributing authors:
00008  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00009  *
00010  *  Copyright:
00011  *     Marco Kuhlmann, 2005
00012  *     Guido Tack, 2006
00013  *
00014  *  Last modified:
00015  *     $Date: 2006-10-26 11:31:58 +0200 (Thu, 26 Oct 2006) $ by $Author: tack $
00016  *     $Revision: 3796 $
00017  *
00018  *  This file is part of Gecode, the generic constraint
00019  *  development environment:
00020  *     http://www.gecode.org
00021  *
00022  *  See the file "LICENSE" for information on usage and
00023  *  redistribution of this file, and for a
00024  *     DISCLAIMER OF ALL WARRANTIES.
00025  *
00026  */
00027 
00028 package org.gecode.gist;
00029 
00030 import java.util.*;
00031 
00032 public class DFS implements SearchEngineInterface {
00033     private Stack<SpaceNode> stack;
00034 
00035     public DFS() {
00036         stack = new Stack<SpaceNode>();
00037     }
00038 
00039     public void setup(SpaceNode root) {
00040         stack.clear();
00041         stack.push(root);
00042     }
00043 
00044     public boolean step() {
00045         if (stack.empty())
00046             return true;
00047         SpaceNode node = stack.pop();
00048         Iterator childrenIterator = node.reversedChildrenIterator();
00049         while (childrenIterator.hasNext()) {
00050             SpaceNode nextChild = (SpaceNode) childrenIterator.next();
00051             if (nextChild.isOpen())
00052                 stack.push(nextChild);
00053         }
00054         return stack.empty();
00055     }
00056 
00057 }