Generated on Mon May 10 06:46:31 2010 for Gecode by doxygen 1.6.3

nodecursor.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2010-03-30 13:35:10 +0200 (Tue, 30 Mar 2010) $ by $Author: tack $
00011  *     $Revision: 10600 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  * Permission is hereby granted, free of charge, to any person obtaining
00018  * a copy of this software and associated documentation files (the
00019  * "Software"), to deal in the Software without restriction, including
00020  * without limitation the rights to use, copy, modify, merge, publish,
00021  * distribute, sublicense, and/or sell copies of the Software, and to
00022  * permit persons to whom the Software is furnished to do so, subject to
00023  * the following conditions:
00024  *
00025  * The above copyright notice and this permission notice shall be
00026  * included in all copies or substantial portions of the Software.
00027  *
00028  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include <gecode/gist/nodecursor.hh>
00039 
00040 namespace Gecode { namespace Gist {
00041 
00042   HideFailedCursor::HideFailedCursor(VisualNode* root)
00043    : NodeCursor<VisualNode>(root) {}
00044 
00045   void
00046   HideFailedCursor::processCurrentNode(void) {
00047     VisualNode* n = node();
00048     if (n->getStatus() == BRANCH &&
00049         !n->hasSolvedChildren() &&
00050         n->getNoOfOpenChildren() == 0) {
00051       n->setHidden(true);
00052       n->setChildrenLayoutDone(false);
00053       n->dirtyUp();
00054     }
00055   }
00056 
00057   UnhideAllCursor::UnhideAllCursor(VisualNode* root)
00058    : NodeCursor<VisualNode>(root) {}
00059 
00060   void
00061   UnhideAllCursor::processCurrentNode(void) {
00062     VisualNode* n = node();
00063     if (n->isHidden()) {
00064       n->setHidden(false);
00065       n->dirtyUp();
00066     }
00067   }
00068 
00069   UnstopAllCursor::UnstopAllCursor(VisualNode* root)
00070    : NodeCursor<VisualNode>(root) {}
00071 
00072   void
00073   UnstopAllCursor::processCurrentNode(void) {
00074     VisualNode* n = node();
00075     if (n->getStatus() == STOP) {
00076       n->setStop(false);
00077       n->dirtyUp();
00078     }
00079   }
00080 
00081   NextSolCursor::NextSolCursor(VisualNode* theNode, bool backwards)
00082    : NodeCursor<VisualNode>(theNode), back(backwards) {}
00083 
00084   void
00085   NextSolCursor::processCurrentNode(void) {}
00086 
00087   bool
00088   NextSolCursor::notOnSol(void) {
00089     return node() == startNode() || node()->getStatus() != SOLVED;
00090   }
00091 
00092   bool
00093   NextSolCursor::mayMoveUpwards(void) {
00094     return notOnSol() && !node()->isRoot();
00095   }
00096 
00097   bool
00098   NextSolCursor::mayMoveDownwards(void) {
00099     return notOnSol() && !(back && node() == startNode())
00100            && node()->hasSolvedChildren()
00101            && NodeCursor<VisualNode>::mayMoveDownwards();
00102   }
00103 
00104   void
00105   NextSolCursor::moveDownwards(void) {
00106     NodeCursor<VisualNode>::moveDownwards();
00107     if (back) {
00108       while (NodeCursor<VisualNode>::mayMoveSidewards())
00109         NodeCursor<VisualNode>::moveSidewards();
00110     }
00111   }
00112 
00113   bool
00114   NextSolCursor::mayMoveSidewards(void) {
00115     if (back) {
00116       return notOnSol() && !node()->isRoot() && alternative() > 0;
00117     } else {
00118       return notOnSol() && !node()->isRoot() &&
00119              (alternative() < node()->getParent()->getNumberOfChildren() - 1);
00120     }
00121   }
00122 
00123   void
00124   NextSolCursor::moveSidewards(void) {
00125     if (back) {
00126       alternative(alternative()-1);
00127       node(node()->getParent()->getChild(alternative()));
00128     } else {
00129       NodeCursor<VisualNode>::moveSidewards();
00130     }
00131   }
00132 
00133   StatCursor::StatCursor(VisualNode* root)
00134    : NodeCursor<VisualNode>(root),
00135      curDepth(0), depth(0), failed(0), solved(0), choice(0), open(0) {}
00136 
00137   void
00138   StatCursor::processCurrentNode(void) {
00139     VisualNode* n = node();
00140     switch (n->getStatus()) {
00141     case SOLVED: solved++; break;
00142     case FAILED: failed++; break;
00143     case BRANCH: choice++; break;
00144     case UNDETERMINED: open++; break;
00145     default: break;
00146     }
00147   }
00148 
00149   void
00150   StatCursor::moveDownwards(void) {
00151     curDepth++;
00152     depth = std::max(depth,curDepth); 
00153     NodeCursor<VisualNode>::moveDownwards();
00154   }
00155 
00156   void
00157   StatCursor::moveUpwards(void) {
00158     curDepth--;
00159     NodeCursor<VisualNode>::moveUpwards();
00160   }
00161 
00162 }}
00163 
00164 // STATISTICS: gist-any