Generated on Fri Oct 19 11:25:09 2018 for Gecode by doxygen 1.6.3

detectable.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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode { namespace Int { namespace Unary {
00035 
00036   template<class ManTaskView>
00037   forceinline ExecStatus
00038   detectable(Space& home, TaskViewArray<ManTaskView>& t) {
00039     sort<ManTaskView,STO_ECT,true>(t);
00040 
00041     Region r;
00042 
00043     OmegaTree<ManTaskView> o(r,t);
00044     TaskViewIter<ManTaskView,STO_LST,true> q(r,t);
00045     int* est = r.alloc<int>(t.size());
00046 
00047     for (int i=0; i<t.size(); i++) {
00048       while (q() && (t[i].ect() > t[q.task()].lst())) {
00049         o.insert(q.task()); ++q;
00050       }
00051       est[i] = o.ect(i);
00052     }
00053 
00054     for (int i=0; i<t.size(); i++)
00055       GECODE_ME_CHECK(t[i].est(home,est[i]));
00056 
00057     return ES_OK;
00058   }
00059 
00060   template<class ManTask>
00061   ExecStatus
00062   detectable(Space& home, TaskArray<ManTask>& t) {
00063     TaskViewArray<typename TaskTraits<ManTask>::TaskViewFwd> f(t);
00064     GECODE_ES_CHECK(detectable(home,f));
00065     TaskViewArray<typename TaskTraits<ManTask>::TaskViewBwd> b(t);
00066     return detectable(home,b);
00067   }
00068 
00069 
00070   template<class OptTaskView, class PL>
00071   forceinline ExecStatus
00072   detectable(Space& home, Propagator& p, TaskViewArray<OptTaskView>& t) {
00073     sort<OptTaskView,STO_ECT,true>(t);
00074 
00075     Region r;
00076 
00077     OmegaTree<OptTaskView> o(r,t);
00078     ManTaskViewIter<OptTaskView,STO_LST,true> q(r,t);
00079     int* est = r.alloc<int>(t.size());
00080 
00081     for (int i=0; i<t.size(); i++) {
00082       while (q() && (t[i].ect() > t[q.task()].lst())) {
00083         o.insert(q.task()); ++q;
00084       }
00085       est[i] = o.ect(i);
00086     }
00087 
00088     int n = t.size();
00089     for (int i=n; i--; )
00090       if (t[i].mandatory()) {
00091         GECODE_ME_CHECK(t[i].est(home,est[i]));
00092       } else if (est[i] > t[i].lst()) {
00093         GECODE_ME_CHECK(t[i].excluded(home));
00094         t[i].cancel(home,p,PL::pc); t[i]=t[--n];
00095       }
00096     t.size(n);
00097 
00098     return (t.size() < 2) ? home.ES_SUBSUMED(p) : ES_OK;
00099   }
00100 
00101   template<class OptTask, class PL>
00102   ExecStatus
00103   detectable(Space& home, Propagator& p, TaskArray<OptTask>& t) {
00104     TaskViewArray<typename TaskTraits<OptTask>::TaskViewFwd> f(t);
00105     GECODE_ES_CHECK((detectable<typename TaskTraits<OptTask>::TaskViewFwd,PL>
00106                      (home,p,f)));
00107     TaskViewArray<typename TaskTraits<OptTask>::TaskViewBwd> b(t);
00108     return detectable<typename TaskTraits<OptTask>::TaskViewBwd,PL>
00109       (home,p,b);
00110   }
00111 
00112 }}}
00113 
00114 // STATISTICS: int-prop