this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * Guido Tack <tack@gecode.org> 6 * 7 * Copyright: 8 * Christian Schulte, 2009 9 * Guido Tack, 2010 10 * 11 * This file is part of Gecode, the generic constraint 12 * development environment: 13 * http://www.gecode.org 14 * 15 * Permission is hereby granted, free of charge, to any person obtaining 16 * a copy of this software and associated documentation files (the 17 * "Software"), to deal in the Software without restriction, including 18 * without limitation the rights to use, copy, modify, merge, publish, 19 * distribute, sublicense, and/or sell copies of the Software, and to 20 * permit persons to whom the Software is furnished to do so, subject to 21 * the following conditions: 22 * 23 * The above copyright notice and this permission notice shall be 24 * included in all copies or substantial portions of the Software. 25 * 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 * 34 */ 35 36namespace Gecode { namespace Int { namespace Cumulative { 37 38 template<class ManTask, class Cap, class PL> 39 forceinline 40 ManProp<ManTask,Cap,PL>::ManProp(Home home, Cap c0, TaskArray<ManTask>& t) 41 : TaskProp<ManTask,PL>(home,t), c(c0) { 42 c.subscribe(home,*this,PC_INT_BND); 43 } 44 45 template<class ManTask, class Cap, class PL> 46 forceinline 47 ManProp<ManTask,Cap,PL>::ManProp(Space& home, ManProp<ManTask,Cap,PL>& p) 48 : TaskProp<ManTask,PL>(home,p) { 49 c.update(home,p.c); 50 } 51 52 template<class ManTask, class Cap, class PL> 53 ExecStatus 54 ManProp<ManTask,Cap,PL>::post(Home home, Cap c, TaskArray<ManTask>& t) { 55 // Capacity must be nonnegative 56 GECODE_ME_CHECK(c.gq(home, 0)); 57 // Check that tasks do not overload resource 58 for (int i=0; i<t.size(); i++) 59 if (t[i].c() > c.max()) 60 return ES_FAILED; 61 if (t.size() == 1) 62 GECODE_ME_CHECK(c.gq(home, t[0].c())); 63 if (t.size() > 1) { 64 if (c.assigned() && c.val()==1) { 65 TaskArray<typename TaskTraits<ManTask>::UnaryTask> mt(home,t.size()); 66 for (int i=0; i<t.size(); i++) 67 mt[i]=t[i]; 68 return Unary::ManProp<typename TaskTraits<ManTask>::UnaryTask,PL> 69 ::post(home,mt); 70 } else { 71 (void) new (home) ManProp<ManTask,Cap,PL>(home,c,t); 72 } 73 } 74 return ES_OK; 75 } 76 77 template<class ManTask, class Cap, class PL> 78 Actor* 79 ManProp<ManTask,Cap,PL>::copy(Space& home) { 80 return new (home) ManProp<ManTask,Cap,PL>(home,*this); 81 } 82 83 template<class ManTask, class Cap, class PL> 84 forceinline size_t 85 ManProp<ManTask,Cap,PL>::dispose(Space& home) { 86 (void) TaskProp<ManTask,PL>::dispose(home); 87 c.cancel(home,*this,PC_INT_BND); 88 return sizeof(*this); 89 } 90 91 template<class ManTask, class Cap, class PL> 92 ExecStatus 93 ManProp<ManTask,Cap,PL>::propagate(Space& home, const ModEventDelta& med) { 94 // Only bounds changes? 95 if (IntView::me(med) != ME_INT_DOM) 96 GECODE_ES_CHECK(overload(home,c.max(),t)); 97 98 if (PL::advanced) 99 GECODE_ES_CHECK(edgefinding(home,c.max(),t)); 100 101 if (PL::basic) 102 GECODE_ES_CHECK(timetabling(home,*this,c,t)); 103 104 if (Cap::varderived() && c.assigned() && (c.val() == 1)) { 105 // Check that tasks do not overload resource 106 for (int i=0; i<t.size(); i++) 107 if (t[i].c() > 1) 108 return ES_FAILED; 109 // Rewrite to unary resource constraint 110 TaskArray<typename TaskTraits<ManTask>::UnaryTask> ut(home,t.size()); 111 for (int i=0; i<t.size(); i++) 112 ut[i]=t[i]; 113 GECODE_REWRITE(*this, 114 (Unary::ManProp<typename TaskTraits<ManTask>::UnaryTask,PL> 115 ::post(home(*this),ut))); 116 } 117 118 if (!PL::basic && c.assigned()) 119 GECODE_ES_CHECK(subsumed(home,*this,c.val(),t)); 120 121 return ES_NOFIX; 122 } 123 124}}} 125 126// STATISTICS: int-prop