Generated on Wed Nov 5 2014 05:18:31 for Gecode by doxygen 1.7.6.1
rbs.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, 2012
00008  *
00009  *  Last modified:
00010  *     $Date: 2013-10-30 15:42:34 +0100 (Wed, 30 Oct 2013) $ by $Author: schulte $
00011  *     $Revision: 14037 $
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 
00039 #include <gecode/search/meta/rbs.hh>
00040 
00041 namespace Gecode { namespace Search { namespace Meta {
00042 
00043   Space*
00044   RBS::next(void) {
00045     while (true) {
00046       Space* n = e->next();
00047       unsigned long int i = stop->m_stat.restart;
00048       if (n != NULL) {
00049         NoGoods& ng = e->nogoods();
00050         ng.ng(0);
00051         master->constrain(*n);
00052         master->master(i,n,ng);
00053         stop->m_stat.nogood += ng.ng();
00054         stop->update(e->statistics());
00055         if (master->status(stop->m_stat) == SS_FAILED) {
00056           delete master;
00057           master = NULL;
00058           e->reset(NULL);
00059         } else {
00060           Space* slave = master;
00061           master = master->clone(shared);
00062           slave->slave(i,n);
00063           e->reset(slave);
00064         }
00065         return n;
00066       } else if (e->stopped() && stop->enginestopped()) {
00067         NoGoods& ng = e->nogoods();
00068         ng.ng(0);
00069         master->master(i,NULL,ng);
00070         stop->m_stat.nogood += ng.ng();
00071         long unsigned int nl = (*co)();
00072         stop->limit(e->statistics(),nl);
00073         if (master->status(stop->m_stat) == SS_FAILED)
00074           return NULL;
00075         Space* slave = master;
00076         master = master->clone(shared);
00077         slave->slave(i,n);
00078         e->reset(slave);
00079       } else {
00080         return NULL;
00081       }
00082     }
00083     GECODE_NEVER;
00084     return NULL;
00085   }
00086   
00087   Search::Statistics
00088   RBS::statistics(void) const {
00089     return stop->metastatistics()+e->statistics();
00090   }
00091   
00092   bool
00093   RBS::stopped(void) const {
00094     /*
00095      * What might happen during parallel search is that the
00096      * engine has been stopped but the meta engine has not, so
00097      * the meta engine does not perform a restart. However the
00098      * invocation of next will do so and no restart will be
00099      * missed.
00100      */
00101     return e->stopped(); 
00102   }
00103   
00104   void
00105   RBS::reset(Space*) { 
00106   }
00107   
00108   NoGoods RBS::eng;
00109 
00110   NoGoods&
00111   RBS::nogoods(void) {
00112     return eng;
00113   }
00114   
00115   RBS::~RBS(void) {
00116     // Deleting e also deletes stop
00117     delete e;
00118     delete master;
00119     delete co;
00120   }
00121 
00122 }}}
00123 
00124 // STATISTICS: search-other