this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Mikael Lagerkvist <lagerkvist@gecode.org> 5 * 6 * Copyright: 7 * Mikael Lagerkvist, 2005 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 34#include <gecode/int/cumulatives.hh> 35 36namespace Gecode { 37 38 using namespace Int; 39 40 namespace { 41 ViewArray<IntView> 42 make_view_array(Space& home, const IntVarArgs& in) { 43 return ViewArray<Int::IntView>(home, in); 44 } 45 46 ViewArray<ConstIntView> 47 make_view_array(Space& home, const IntArgs& in) { 48 ViewArray<Int::ConstIntView> res(home, in.size()); 49 for (int i=0; i<in.size(); i++) { 50 Int::Limits::check(in[i],"Int::cumulatives"); 51 res[i] = Int::ConstIntView(in[i]); 52 } 53 54 return res; 55 } 56 57 template<class In> class ViewType; 58 59 template<> 60 class ViewType<IntArgs> { 61 public: 62 typedef Int::ConstIntView Result; 63 }; 64 65 template<> 66 class ViewType<IntVarArgs> { 67 public: 68 typedef Int::IntView Result; 69 }; 70 71 template<class Machine, class Processing, class Usage> 72 void 73 post_cumulatives(Home home, const Machine& m, 74 const IntVarArgs& s, const Processing& p, 75 const IntVarArgs& e, const Usage& u, 76 const IntArgs& c, bool at_most, 77 IntPropLevel) { 78 if (m.size() != s.size() || 79 s.size() != p.size() || 80 p.size() != e.size() || 81 e.size() != u.size()) 82 throw Int::ArgumentSizeMismatch("Int::cumulatives"); 83 GECODE_POST; 84 85 ViewArray<typename ViewType<Machine>::Result> 86 vm = make_view_array(home, m); 87 ViewArray<typename ViewType<Processing>::Result> 88 vp = make_view_array(home, p); 89 ViewArray<typename ViewType<Usage>::Result> 90 vu = make_view_array(home, u); 91 ViewArray<IntView> 92 vs = make_view_array(home, s), 93 ve = make_view_array(home, e); 94 95 SharedArray<int> c_s(c.size()); 96 for (int i=0; i<c.size(); i++) 97 c_s[i] = c[i]; 98 99 // There is only the value-consistent propagator for this constraint 100 GECODE_ES_FAIL((Int::Cumulatives::Val< 101 typename ViewType<Machine>::Result, 102 typename ViewType<Processing>::Result, 103 typename ViewType<Usage>::Result, 104 IntView>::post(home, vm,vs,vp,ve,vu,c_s,at_most))); 105 106 } 107 } 108 109 void 110 cumulatives(Home home, const IntVarArgs& m, 111 const IntVarArgs& s, const IntVarArgs& p, 112 const IntVarArgs& e, const IntVarArgs& u, 113 const IntArgs& c, bool at_most, 114 IntPropLevel cl) { 115 post_cumulatives(home, m, s, p, e, u, c, at_most, cl); 116 } 117 118 void 119 cumulatives(Home home, const IntArgs& m, 120 const IntVarArgs& s, const IntVarArgs& p, 121 const IntVarArgs& e, const IntVarArgs& u, 122 const IntArgs& c, bool at_most, 123 IntPropLevel cl) { 124 post_cumulatives(home, m, s, p, e, u, c, at_most, cl); 125 } 126 127 void 128 cumulatives(Home home, const IntVarArgs& m, 129 const IntVarArgs& s, const IntArgs& p, 130 const IntVarArgs& e, const IntVarArgs& u, 131 const IntArgs& c, bool at_most, 132 IntPropLevel cl) { 133 post_cumulatives(home, m, s, p, e, u, c, at_most, cl); 134 } 135 136 void 137 cumulatives(Home home, const IntArgs& m, 138 const IntVarArgs& s, const IntArgs& p, 139 const IntVarArgs& e, const IntVarArgs& u, 140 const IntArgs& c, bool at_most, 141 IntPropLevel cl) { 142 post_cumulatives(home, m, s, p, e, u, c, at_most, cl); 143 } 144 145 void 146 cumulatives(Home home, const IntVarArgs& m, 147 const IntVarArgs& s, const IntVarArgs& p, 148 const IntVarArgs& e, const IntArgs& u, 149 const IntArgs& c, bool at_most, 150 IntPropLevel cl) { 151 post_cumulatives(home, m, s, p, e, u, c, at_most, cl); 152 } 153 154 void 155 cumulatives(Home home, const IntArgs& m, 156 const IntVarArgs& s, const IntVarArgs& p, 157 const IntVarArgs& e, const IntArgs& u, 158 const IntArgs& c, bool at_most, 159 IntPropLevel cl) { 160 post_cumulatives(home, m, s, p, e, u, c, at_most, cl); 161 } 162 163 void 164 cumulatives(Home home, const IntVarArgs& m, 165 const IntVarArgs& s, const IntArgs& p, 166 const IntVarArgs& e, const IntArgs& u, 167 const IntArgs& c, bool at_most, 168 IntPropLevel cl) { 169 post_cumulatives(home, m, s, p, e, u, c, at_most, cl); 170 } 171 172 void 173 cumulatives(Home home, const IntArgs& m, 174 const IntVarArgs& s, const IntArgs& p, 175 const IntVarArgs& e, const IntArgs& u, 176 const IntArgs& c, bool at_most, 177 IntPropLevel cl) { 178 post_cumulatives(home, m, s, p, e, u, c, at_most, cl); 179 } 180 181} 182 183// STATISTICS: int-post