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 *
6 * Copyright:
7 * Christian Schulte, 2012
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 Branch {
35
36 template<class View>
37 forceinline
38 ValSelMin<View>::ValSelMin
39 (Space& home, const ValBranch<typename ValSelMin<View>::Var>& vb)
40 : ValSel<View,int>(home,vb) {}
41 template<class View>
42 forceinline
43 ValSelMin<View>::ValSelMin(Space& home, ValSelMin& vs)
44 : ValSel<View,int>(home,vs) {}
45 template<class View>
46 forceinline int
47 ValSelMin<View>::val(const Space&, View x, int) {
48 return x.min();
49 }
50
51 template<class View>
52 forceinline
53 ValSelMax<View>::ValSelMax
54 (Space& home, const ValBranch<typename ValSelMax<View>::Var>& vb)
55 : ValSel<View,int>(home,vb) {}
56 template<class View>
57 forceinline
58 ValSelMax<View>::ValSelMax(Space& home, ValSelMax& vs)
59 : ValSel<View,int>(home,vs) {}
60 template<class View>
61 forceinline int
62 ValSelMax<View>::val(const Space&, View x, int) {
63 return x.max();
64 }
65
66 template<class View>
67 forceinline
68 ValSelMed<View>::ValSelMed
69 (Space& home, const ValBranch<typename ValSelMed<View>::Var>& vb)
70 : ValSel<View,int>(home,vb) {}
71 template<class View>
72 forceinline
73 ValSelMed<View>::ValSelMed(Space& home, ValSelMed& vs)
74 : ValSel<View,int>(home,vs) {}
75 template<class View>
76 forceinline int
77 ValSelMed<View>::val(const Space&, View x, int) {
78 return x.med();
79 }
80
81 template<class View>
82 forceinline
83 ValSelAvg<View>::ValSelAvg
84 (Space& home, const ValBranch<typename ValSelAvg<View>::Var>& vb)
85 : ValSel<View,int>(home,vb) {}
86 template<class View>
87 forceinline
88 ValSelAvg<View>::ValSelAvg(Space& home, ValSelAvg& vs)
89 : ValSel<View,int>(home,vs) {}
90 template<class View>
91 forceinline int
92 ValSelAvg<View>::val(const Space&, View x, int) {
93 return (x.width() == 2U) ? x.min() : ((x.min()+x.max()) / 2);
94 }
95
96 template<class View>
97 forceinline
98 ValSelRnd<View>::ValSelRnd
99 (Space& home, const ValBranch<typename ValSelRnd<View>::Var>& vb)
100 : ValSel<View,int>(home,vb), r(vb.rnd()) {}
101 template<class View>
102 forceinline
103 ValSelRnd<View>::ValSelRnd(Space& home, ValSelRnd& vs)
104 : ValSel<View,int>(home,vs), r(vs.r) {
105 }
106 template<class View>
107 forceinline int
108 ValSelRnd<View>::val(const Space&, View x, int) {
109 unsigned int p = r(x.size());
110 for (ViewRanges<View> i(x); i(); ++i) {
111 if (i.width() > p)
112 return i.min() + static_cast<int>(p);
113 p -= i.width();
114 }
115 GECODE_NEVER;
116 return 0;
117 }
118 template<class View>
119 forceinline bool
120 ValSelRnd<View>::notice(void) const {
121 return true;
122 }
123 template<class View>
124 forceinline void
125 ValSelRnd<View>::dispose(Space&) {
126 r.~Rnd();
127 }
128
129 forceinline
130 ValSelRangeMin::ValSelRangeMin
131 (Space& home, const ValBranch<IntVar>& vb)
132 : ValSel<IntView,int>(home,vb) {}
133 forceinline
134 ValSelRangeMin::ValSelRangeMin(Space& home, ValSelRangeMin& vs)
135 : ValSel<IntView,int>(home,vs) {}
136 forceinline int
137 ValSelRangeMin::val(const Space&, IntView x, int) {
138 if (x.range()) {
139 return (x.width() == 2) ? x.min() : (x.min() + (x.max()-x.min())/2);
140 } else {
141 ViewRanges<View> r(x);
142 return r.max();
143 }
144 }
145
146 forceinline
147 ValSelRangeMax::ValSelRangeMax(Space& home, const ValBranch<IntVar>& vb)
148 : ValSel<IntView,int>(home,vb) {}
149 forceinline
150 ValSelRangeMax::ValSelRangeMax(Space& home, ValSelRangeMax& vs)
151 : ValSel<IntView,int>(home,vs) {}
152 forceinline int
153 ValSelRangeMax::val(const Space&, IntView x, int) {
154 if (x.range()) {
155 return (x.width() == 2) ? x.max() : (x.max() - (x.max()-x.min())/2);
156 } else {
157 int min;
158 ViewRanges<IntView> r(x);
159 do {
160 min = r.min(); ++r;
161 } while (r());
162 return min;
163 }
164 }
165
166}}}
167
168// STATISTICS: int-branch
169