Generated on Mon Aug 25 11:35:40 2008 for Gecode by doxygen 1.5.6

engine-ctrl.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2004
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-02-05 15:32:41 +0100 (Tue, 05 Feb 2008) $ by $Author: schulte $
00011  *     $Revision: 6062 $
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 namespace Gecode { namespace Search {
00039 
00040   forceinline
00041   EngineCtrl::EngineCtrl(Stop* st0, size_t sz)
00042     : st(st0), _stopped(false), mem_space(sz), mem_cur(0), mem_total(0) {
00043     memory = 0;
00044   }
00045 
00046   forceinline void
00047   EngineCtrl::start(void) {
00048     _stopped = false;
00049   }
00050 
00051   forceinline bool
00052   EngineCtrl::stop(size_t sz) {
00053     if (st == NULL)
00054       return false;
00055     memory += sz;
00056     _stopped |= st->stop(*this);
00057     memory -= sz;
00058     return _stopped;
00059   }
00060 
00061   forceinline bool
00062   EngineCtrl::stopped(void) const {
00063     return _stopped;
00064   }
00065 
00066   forceinline void
00067   EngineCtrl::push(const Space* s, const BranchingDesc* d) {
00068     if (s != NULL)
00069       mem_total += mem_space + s->allocated();
00070     mem_total += d->size();
00071     if (mem_total > memory)
00072       memory = mem_total;
00073   }
00074 
00075   forceinline void
00076   EngineCtrl::adapt(const Space* s) {
00077     mem_total += mem_space + s->allocated();
00078     if (mem_total > memory)
00079       memory = mem_total;
00080   }
00081 
00082   forceinline void
00083   EngineCtrl::constrained(const Space* s1, const Space* s2) {
00084     mem_total -= s1->allocated();
00085     mem_total += s2->allocated();
00086     if (mem_total > memory)
00087       memory = mem_total;
00088   }
00089 
00090   forceinline void
00091   EngineCtrl::lao(const Space* s) {
00092     mem_total -= mem_space + s->allocated();
00093   }
00094 
00095   forceinline void
00096   EngineCtrl::pop(const Space* s, const BranchingDesc* d) {
00097     if (s != NULL)
00098       mem_total -= mem_space + s->allocated();
00099     mem_total -= d->size();
00100   }
00101 
00102   forceinline void
00103   EngineCtrl::current(const Space* s) {
00104     if (s == NULL) {
00105       mem_total -= mem_cur;
00106       mem_cur = 0;
00107     } else {
00108       mem_cur = mem_space + s->allocated();
00109       mem_total += mem_cur;
00110       if (mem_total > memory)
00111         memory = mem_total;
00112     }
00113   }
00114 
00115   forceinline void
00116   EngineCtrl::reset(const Space* s) {
00117     mem_cur   = mem_space + s->allocated();
00118     mem_total = mem_cur;
00119     if (mem_total > memory)
00120       memory = mem_total;
00121   }
00122 
00123   forceinline void
00124   EngineCtrl::reset(void) {
00125     mem_cur   = 0;
00126     mem_total = 0;
00127   }
00128 
00129 }}
00130 
00131 // STATISTICS: search-any