Generated on Tue Apr 18 10:22:00 2017 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  *  Last modified:
00010  *     $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00011  *     $Revision: 14967 $
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 Unary {
00039 
00040   template<class ManTaskView>
00041   forceinline ExecStatus
00042   detectable(Space& home, TaskViewArray<ManTaskView>& t) {
00043     sort<ManTaskView,STO_ECT,true>(t);
00044 
00045     Region r(home);
00046 
00047     OmegaTree<ManTaskView> o(r,t);
00048     TaskViewIter<ManTaskView,STO_LST,true> q(r,t);
00049     int* est = r.alloc<int>(t.size());
00050 
00051     for (int i=0; i<t.size(); i++) {
00052       while (q() && (t[i].ect() > t[q.task()].lst())) {
00053         o.insert(q.task()); ++q;
00054       }
00055       est[i] = o.ect(i);
00056     }
00057 
00058     for (int i=t.size(); i--; )
00059       GECODE_ME_CHECK(t[i].est(home,est[i]));
00060 
00061     return ES_OK;
00062   }
00063 
00064   template<class ManTask>
00065   ExecStatus
00066   detectable(Space& home, TaskArray<ManTask>& t) {
00067     TaskViewArray<typename TaskTraits<ManTask>::TaskViewFwd> f(t);
00068     GECODE_ES_CHECK(detectable(home,f));
00069     TaskViewArray<typename TaskTraits<ManTask>::TaskViewBwd> b(t);
00070     return detectable(home,b);
00071   }
00072 
00073 
00074   template<class OptTaskView, class PL>
00075   forceinline ExecStatus
00076   detectable(Space& home, Propagator& p, TaskViewArray<OptTaskView>& t) {
00077     sort<OptTaskView,STO_ECT,true>(t);
00078 
00079     Region r(home);
00080 
00081     OmegaTree<OptTaskView> o(r,t);
00082     ManTaskViewIter<OptTaskView,STO_LST,true> q(r,t);
00083     int* est = r.alloc<int>(t.size());
00084 
00085     for (int i=0; i<t.size(); i++) {
00086       while (q() && (t[i].ect() > t[q.task()].lst())) {
00087         o.insert(q.task()); ++q;
00088       }
00089       est[i] = o.ect(i);
00090     }
00091 
00092     int n = t.size();
00093     for (int i=n; i--; )
00094       if (t[i].mandatory()) {
00095         GECODE_ME_CHECK(t[i].est(home,est[i]));
00096       } else if (est[i] > t[i].lst()) {
00097         GECODE_ME_CHECK(t[i].excluded(home));
00098         t[i].cancel(home,p,PL::pc); t[i]=t[--n];
00099       }
00100     t.size(n);
00101 
00102     return (t.size() < 2) ? home.ES_SUBSUMED(p) : ES_OK;
00103   }
00104 
00105   template<class OptTask, class PL>
00106   ExecStatus
00107   detectable(Space& home, Propagator& p, TaskArray<OptTask>& t) {
00108     TaskViewArray<typename TaskTraits<OptTask>::TaskViewFwd> f(t);
00109     GECODE_ES_CHECK((detectable<typename TaskTraits<OptTask>::TaskViewFwd,PL>
00110                      (home,p,f)));
00111     TaskViewArray<typename TaskTraits<OptTask>::TaskViewBwd> b(t);
00112     return detectable<typename TaskTraits<OptTask>::TaskViewBwd,PL>
00113       (home,p,b);
00114   }
00115 
00116 }}}
00117 
00118 // STATISTICS: int-prop