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

not-first-not-last.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, 2009
00008  *
00009  *  Last modified:
00010  *     $Date: 2011-05-25 16:56:41 +0200 (Wed, 25 May 2011) $ by $Author: schulte $
00011  *     $Revision: 12022 $
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 <algorithm>
00039 
00040 namespace Gecode { namespace Int { namespace Unary {
00041 
00042   template<class ManTaskView>
00043   forceinline ExecStatus
00044   notlast(Space& home, TaskViewArray<ManTaskView>& t) {
00045     sort<ManTaskView,STO_LCT,true>(t);
00046 
00047     Region r(home);
00048 
00049     OmegaTree<ManTaskView> o(r,t);
00050     TaskViewIter<ManTaskView,STO_LST,true> q(r,t);
00051     int* lct = r.alloc<int>(t.size());
00052 
00053     for (int i=t.size(); i--; )
00054       lct[i] = t[i].lct();
00055 
00056     for (int i=0; i<t.size(); i++) {
00057       int j = -1;
00058       while (q() && (t[i].lct() > t[q.task()].lst())) {
00059         if ((j >= 0) && (o.ect() > t[q.task()].lst()))
00060           lct[q.task()] = std::min(lct[q.task()],t[j].lst());
00061         j = q.task();
00062         o.insert(j); ++q;
00063       }
00064       if ((j >= 0) && (o.ect(i) > t[i].lst()))
00065         lct[i] = std::min(lct[i],t[j].lst());
00066     }
00067 
00068     for (int i=t.size(); i--; )
00069       GECODE_ME_CHECK(t[i].lct(home,lct[i]));
00070       
00071     return ES_OK;
00072   }
00073 
00074   template<class ManTask>
00075   ExecStatus
00076   notfirstnotlast(Space& home, TaskArray<ManTask>& t) {
00077     TaskViewArray<typename TaskTraits<ManTask>::TaskViewFwd> f(t);
00078     GECODE_ES_CHECK(notlast(home,f));
00079     TaskViewArray<typename TaskTraits<ManTask>::TaskViewBwd> b(t);
00080     return notlast(home,b);
00081   }
00082   
00083   template<class OptTaskView>
00084   forceinline ExecStatus
00085   notlast(Space& home, Propagator& p, TaskViewArray<OptTaskView>& t) {
00086     sort<OptTaskView,STO_LCT,true>(t);
00087 
00088     Region r(home);
00089 
00090     OmegaTree<OptTaskView> o(r,t);
00091     ManTaskViewIter<OptTaskView,STO_LST,true> q(r,t);
00092     int* lct = r.alloc<int>(t.size());
00093 
00094     for (int i=t.size(); i--; )
00095       lct[i] = t[i].lct();
00096 
00097     for (int i=0; i<t.size(); i++) {
00098       int j = -1;
00099       while (q() && (t[i].lct() > t[q.task()].lst())) {
00100         if ((j >= 0) && (o.ect() > t[q.task()].lst()))
00101           lct[q.task()] = std::min(lct[q.task()],t[j].lst());
00102         j = q.task();
00103         o.insert(j); ++q;
00104       }
00105       if ((j >= 0) && (o.ect(i) > t[i].lst()))
00106         lct[i] = std::min(lct[i],t[j].lst());
00107     }
00108 
00109     int n = t.size();
00110     for (int i=n; i--; )
00111       if (t[i].mandatory()) {
00112         GECODE_ME_CHECK(t[i].lct(home,lct[i]));
00113       } else if (lct[i] < t[i].ect()) {
00114         //        GECODE_ME_CHECK(t[i].excluded(home));
00115         //        t[i].cancel(home,p); t[i]=t[--n];
00116       }
00117     t.size(n);
00118 
00119     return (t.size() < 2) ? home.ES_SUBSUMED(p) : ES_OK;
00120   }
00121 
00122   template<class OptTask>
00123   ExecStatus
00124   notfirstnotlast(Space& home, Propagator& p, TaskArray<OptTask>& t) {
00125     TaskViewArray<typename TaskTraits<OptTask>::TaskViewFwd> f(t);
00126     GECODE_ES_CHECK(notlast(home,p,f));
00127     TaskViewArray<typename TaskTraits<OptTask>::TaskViewBwd> b(t);
00128     return notlast(home,p,b);
00129   }
00130   
00131 }}}
00132 
00133 // STATISTICS: int-prop