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 * Contributing authors:
7 * Gabor Szokoli <szokoli@gecode.org>
8 * Guido Tack <tack@gecode.org>
9 *
10 * Copyright:
11 * Christian Schulte, 2012
12 * Gabor Szokoli, 2004
13 * Guido Tack, 2004
14 *
15 * This file is part of Gecode, the generic constraint
16 * development environment:
17 * http://www.gecode.org
18 *
19 * Permission is hereby granted, free of charge, to any person obtaining
20 * a copy of this software and associated documentation files (the
21 * "Software"), to deal in the Software without restriction, including
22 * without limitation the rights to use, copy, modify, merge, publish,
23 * distribute, sublicense, and/or sell copies of the Software, and to
24 * permit persons to whom the Software is furnished to do so, subject to
25 * the following conditions:
26 *
27 * The above copyright notice and this permission notice shall be
28 * included in all copies or substantial portions of the Software.
29 *
30 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 *
38 */
39
40namespace Gecode { namespace Set { namespace Branch {
41
42 // Minimum merit
43 forceinline
44 MeritMin::MeritMin(Space& home, const VarBranch<Var>& vb)
45 : MeritBase<SetView,int>(home,vb) {}
46 forceinline
47 MeritMin::MeritMin(Space& home, MeritMin& m)
48 : MeritBase<SetView,int>(home,m) {}
49 forceinline int
50 MeritMin::operator ()(const Space&, SetView x, int) {
51 UnknownRanges<SetView> u(x);
52 return u.min();
53 }
54
55 // Maximum merit
56 forceinline
57 MeritMax::MeritMax(Space& home, const VarBranch<Var>& vb)
58 : MeritBase<SetView,int>(home,vb) {}
59 forceinline
60 MeritMax::MeritMax(Space& home, MeritMax& m)
61 : MeritBase<SetView,int>(home,m) {}
62 forceinline int
63 MeritMax::operator ()(const Space&, SetView x, int) {
64 int max = Limits::max;
65 for (UnknownRanges<SetView> u(x); u(); ++u)
66 max = u.max();
67 return max;
68 }
69
70 // Size merit
71 forceinline
72 MeritSize::MeritSize(Space& home, const VarBranch<Var>& vb)
73 : MeritBase<SetView,unsigned int>(home,vb) {}
74 forceinline
75 MeritSize::MeritSize(Space& home, MeritSize& m)
76 : MeritBase<SetView,unsigned int>(home,m) {}
77 forceinline unsigned int
78 MeritSize::operator ()(const Space&, SetView x, int) {
79 return x.unknownSize();
80 }
81
82 // Degree over size merit
83 forceinline
84 MeritDegreeSize::MeritDegreeSize(Space& home, const VarBranch<Var>& vb)
85 : MeritBase<SetView,double>(home,vb) {}
86 forceinline
87 MeritDegreeSize::MeritDegreeSize(Space& home, MeritDegreeSize& m)
88 : MeritBase<SetView,double>(home,m) {}
89 forceinline double
90 MeritDegreeSize::operator ()(const Space&, SetView x, int) {
91 return static_cast<double>(x.unknownSize()) /
92 static_cast<double>(x.degree());
93 }
94
95 // AFC over size merit
96 forceinline
97 MeritAFCSize::MeritAFCSize(Space& home, const VarBranch<Var>& vb)
98 : MeritBase<SetView,double>(home,vb), afc(vb.afc()) {}
99 forceinline
100 MeritAFCSize::MeritAFCSize(Space& home, MeritAFCSize& m)
101 : MeritBase<SetView,double>(home,m), afc(m.afc) {}
102 forceinline double
103 MeritAFCSize::operator ()(const Space&, SetView x, int) {
104 return x.afc() / static_cast<double>(x.unknownSize());
105 }
106 forceinline bool
107 MeritAFCSize::notice(void) const {
108 return false;
109 }
110 forceinline void
111 MeritAFCSize::dispose(Space&) {
112 // Not really needed
113 afc.~AFC();
114 }
115
116 // Action over size merit
117 forceinline
118 MeritActionSize::MeritActionSize(Space& home, const VarBranch<Var>& vb)
119 : MeritBase<SetView,double>(home,vb), action(vb.action()) {}
120 forceinline
121 MeritActionSize::MeritActionSize(Space& home, MeritActionSize& m)
122 : MeritBase<SetView,double>(home,m), action(m.action) {}
123 forceinline double
124 MeritActionSize::operator ()(const Space&, SetView x, int i) {
125 return action[i] / static_cast<double>(x.unknownSize());
126 }
127 forceinline bool
128 MeritActionSize::notice(void) const {
129 return true;
130 }
131 forceinline void
132 MeritActionSize::dispose(Space&) {
133 action.~Action();
134 }
135
136
137 // CHB Q-score over size merit
138 forceinline
139 MeritCHBSize::MeritCHBSize(Space& home, const VarBranch<Var>& vb)
140 : MeritBase<SetView,double>(home,vb), chb(vb.chb()) {}
141 forceinline
142 MeritCHBSize::MeritCHBSize(Space& home, MeritCHBSize& m)
143 : MeritBase<SetView,double>(home,m), chb(m.chb) {}
144 forceinline double
145 MeritCHBSize::operator ()(const Space&, SetView x, int i) {
146 return chb[i] / static_cast<double>(x.unknownSize());
147 }
148 forceinline bool
149 MeritCHBSize::notice(void) const {
150 return true;
151 }
152 forceinline void
153 MeritCHBSize::dispose(Space&) {
154 chb.~CHB();
155 }
156
157}}}
158
159// STATISTICS: set-branch