Generated on Thu Mar 22 10:39:40 2012 for Gecode by doxygen 1.6.3

man.hpp

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, 2011
00008  *
00009  *  Last modified:
00010  *     $Date: 2011-07-08 16:08:27 +0200 (Fri, 08 Jul 2011) $ by $Author: schulte $
00011  *     $Revision: 12168 $
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 Int { namespace NoOverlap {
00039 
00040   template<class Dim, int d>
00041   forceinline
00042   ManProp<Dim,d>::ManProp(Home home, ManBox<Dim,d>* b, int n)
00043     : Base<ManBox<Dim,d> >(home, b, n) {}
00044 
00045   template<class Dim, int d>
00046   inline ExecStatus
00047   ManProp<Dim,d>::post(Home home, ManBox<Dim,d>* b, int n) {
00048     if (n > 1)
00049       (void) new (home) ManProp<Dim,d>(home,b,n);
00050     return ES_OK;
00051   }
00052 
00053   template<class Dim, int d>
00054   forceinline size_t 
00055   ManProp<Dim,d>::dispose(Space& home) {
00056     (void) Base<ManBox<Dim,d> >::dispose(home);
00057     return sizeof(*this);
00058   }
00059 
00060 
00061   template<class Dim, int d>
00062   forceinline
00063   ManProp<Dim,d>::ManProp(Space& home, bool shared, ManProp<Dim,d>& p) 
00064     : Base<ManBox<Dim,d> >(home, shared, p, p.n) {}
00065 
00066   template<class Dim, int d>
00067   Actor* 
00068   ManProp<Dim,d>::copy(Space& home, bool share) {
00069     return new (home) ManProp<Dim,d>(home,share,*this);
00070   }
00071 
00072   template<class Dim, int d>
00073   ExecStatus 
00074   ManProp<Dim,d>::propagate(Space& home, const ModEventDelta&) {
00075     Region r(home);
00076 
00077     // Number of disjoint boxes
00078     int* db = r.alloc<int>(n);
00079     for (int i=n; i--; )
00080       db[i] = n-1;
00081 
00082     // Number of boxes to be eliminated
00083     int e = 0;
00084 
00085     for (int i=n; i--; )
00086       for (int j=i; j--; ) 
00087         if (b[i].nooverlap(b[j])) {
00088           assert(db[i] > 0); assert(db[j] > 0);
00089           if (--db[i] == 0) e++;
00090           if (--db[j] == 0) e++;
00091           continue;
00092         } else {
00093           GECODE_ES_CHECK(b[i].nooverlap(home,b[j]));
00094         }
00095 
00096     if (e == n)
00097       return home.ES_SUBSUMED(*this);
00098 
00099     {
00100       int i = n-1;
00101       while (e > 0) {
00102         // Eliminate boxes that do not overlap
00103         while (db[i] > 0)
00104           i--;
00105         b[i].cancel(home, *this);
00106         b[i] = b[--n];
00107         e--; i--;
00108       }
00109       if (n < 2)
00110         return home.ES_SUBSUMED(*this);
00111     }
00112 
00113     return ES_NOFIX;
00114   }
00115 
00116 }}}
00117 
00118 // STATISTICS: int-prop
00119