this repo has no description
at develop 3.6 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Copyright: 7 * Christian Schulte, 2009 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34namespace Gecode { namespace Int { namespace Unary { 35 36 template<class ManTaskView> 37 forceinline ExecStatus 38 detectable(Space& home, TaskViewArray<ManTaskView>& t) { 39 sort<ManTaskView,STO_ECT,true>(t); 40 41 Region r; 42 43 OmegaTree<ManTaskView> o(r,t); 44 TaskViewIter<ManTaskView,STO_LST,true> q(r,t); 45 int* est = r.alloc<int>(t.size()); 46 47 for (int i=0; i<t.size(); i++) { 48 while (q() && (t[i].ect() > t[q.task()].lst())) { 49 o.insert(q.task()); ++q; 50 } 51 est[i] = o.ect(i); 52 } 53 54 for (int i=0; i<t.size(); i++) 55 GECODE_ME_CHECK(t[i].est(home,est[i])); 56 57 return ES_OK; 58 } 59 60 template<class ManTask> 61 ExecStatus 62 detectable(Space& home, TaskArray<ManTask>& t) { 63 TaskViewArray<typename TaskTraits<ManTask>::TaskViewFwd> f(t); 64 GECODE_ES_CHECK(detectable(home,f)); 65 TaskViewArray<typename TaskTraits<ManTask>::TaskViewBwd> b(t); 66 return detectable(home,b); 67 } 68 69 70 template<class OptTaskView, class PL> 71 forceinline ExecStatus 72 detectable(Space& home, Propagator& p, TaskViewArray<OptTaskView>& t) { 73 sort<OptTaskView,STO_ECT,true>(t); 74 75 Region r; 76 77 OmegaTree<OptTaskView> o(r,t); 78 ManTaskViewIter<OptTaskView,STO_LST,true> q(r,t); 79 int* est = r.alloc<int>(t.size()); 80 81 for (int i=0; i<t.size(); i++) { 82 while (q() && (t[i].ect() > t[q.task()].lst())) { 83 o.insert(q.task()); ++q; 84 } 85 est[i] = o.ect(i); 86 } 87 88 int n = t.size(); 89 for (int i=n; i--; ) 90 if (t[i].mandatory()) { 91 GECODE_ME_CHECK(t[i].est(home,est[i])); 92 } else if (est[i] > t[i].lst()) { 93 GECODE_ME_CHECK(t[i].excluded(home)); 94 t[i].cancel(home,p,PL::pc); t[i]=t[--n]; 95 } 96 t.size(n); 97 98 return (t.size() < 2) ? home.ES_SUBSUMED(p) : ES_OK; 99 } 100 101 template<class OptTask, class PL> 102 ExecStatus 103 detectable(Space& home, Propagator& p, TaskArray<OptTask>& t) { 104 TaskViewArray<typename TaskTraits<OptTask>::TaskViewFwd> f(t); 105 GECODE_ES_CHECK((detectable<typename TaskTraits<OptTask>::TaskViewFwd,PL> 106 (home,p,f))); 107 TaskViewArray<typename TaskTraits<OptTask>::TaskViewBwd> b(t); 108 return detectable<typename TaskTraits<OptTask>::TaskViewBwd,PL> 109 (home,p,b); 110 } 111 112}}} 113 114// STATISTICS: int-prop