~ubuntu-branches/ubuntu/natty/gecode/natty

« back to all changes in this revision

Viewing changes to int/branch/select-view.icc

  • Committer: Bazaar Package Importer
  • Author(s): Kari Pahula
  • Date: 2005-12-24 07:51:25 UTC
  • Revision ID: james.westby@ubuntu.com-20051224075125-klkiqofvbfvusfvt
Tags: upstream-1.0.0.dfsg.1
ImportĀ upstreamĀ versionĀ 1.0.0.dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Main authors:
 
3
 *     Christian Schulte <schulte@gecode.org>
 
4
 *
 
5
 *  Copyright:
 
6
 *     Christian Schulte, 2002
 
7
 *
 
8
 *  Last modified:
 
9
 *     $Date: 2005-07-28 22:52:19 +0200 (Thu, 28 Jul 2005) $ by $Author: schulte $
 
10
 *     $Revision: 2072 $
 
11
 *
 
12
 *  This file is part of Gecode, the generic constraint
 
13
 *  development environment:
 
14
 *     http://www.gecode.org
 
15
 *
 
16
 *  See the file "LICENSE" for information on usage and
 
17
 *  redistribution of this file, and for a
 
18
 *     DISCLAIMER OF ALL WARRANTIES.
 
19
 *
 
20
 */
 
21
 
 
22
namespace Gecode { namespace Int { namespace Branch {
 
23
 
 
24
  // Select first variable
 
25
  forceinline ViewSelStatus
 
26
  ByNone::init(IntView) {
 
27
    return VSS_COMMIT;
 
28
  }
 
29
  forceinline ViewSelStatus
 
30
  ByNone::select(IntView) {
 
31
    assert(false);
 
32
    return VSS_NONE;
 
33
  }
 
34
 
 
35
  // Select variable with smallest min
 
36
  forceinline ViewSelStatus
 
37
  ByMinMin::init(IntView x) {
 
38
    min = x.min();
 
39
    return VSS_SELECT;
 
40
  }
 
41
  forceinline ViewSelStatus
 
42
  ByMinMin::select(IntView x) {
 
43
    if (x.min() < min) {
 
44
      min = x.min(); return VSS_SELECT;
 
45
    }
 
46
    return VSS_NONE;
 
47
  }
 
48
 
 
49
  // Select variable with largest min
 
50
  forceinline ViewSelStatus
 
51
  ByMinMax::init(IntView x) { 
 
52
    min = x.min();
 
53
    return VSS_SELECT;
 
54
  }
 
55
  forceinline ViewSelStatus
 
56
  ByMinMax::select(IntView x) {
 
57
    if (x.min() > min) {
 
58
      min = x.min(); return VSS_SELECT;
 
59
    }
 
60
    return VSS_NONE;
 
61
  }
 
62
 
 
63
  // Select variable with smallest max
 
64
  forceinline ViewSelStatus
 
65
  ByMaxMin::init(IntView x) { 
 
66
    max = x.max();
 
67
    return VSS_SELECT;
 
68
  }
 
69
  forceinline ViewSelStatus
 
70
  ByMaxMin::select(IntView x) {
 
71
    if (x.max() < max) {
 
72
      max = x.max(); return VSS_SELECT;
 
73
    }
 
74
    return VSS_NONE;
 
75
  }
 
76
 
 
77
  // Select variable with largest max
 
78
  forceinline ViewSelStatus
 
79
  ByMaxMax::init(IntView x) {
 
80
    max = x.max();
 
81
    return VSS_SELECT;
 
82
  }
 
83
  forceinline ViewSelStatus
 
84
  ByMaxMax::select(IntView x) {
 
85
    if (x.max() > max) {
 
86
      max = x.max(); return VSS_SELECT;
 
87
    }
 
88
    return VSS_NONE;
 
89
  }
 
90
 
 
91
  // Select variable with smallest size
 
92
  forceinline ViewSelStatus
 
93
  BySizeMin::init(IntView x) { 
 
94
    size = x.size();
 
95
    return (size == 2) ? VSS_COMMIT : VSS_SELECT;
 
96
  }
 
97
  forceinline ViewSelStatus
 
98
  BySizeMin::select(IntView x) {
 
99
    if (x.size() < size) {
 
100
      size = x.size(); 
 
101
      return (size == 2) ? VSS_COMMIT : VSS_SELECT;
 
102
    }
 
103
    return VSS_NONE;
 
104
  }
 
105
 
 
106
  // Select variable with largest size
 
107
  forceinline ViewSelStatus
 
108
  BySizeMax::init(IntView x) { 
 
109
    size = x.size();
 
110
    return VSS_SELECT;
 
111
  }
 
112
  forceinline ViewSelStatus
 
113
  BySizeMax::select(IntView x) {
 
114
    if (x.size() > size) {
 
115
      size = x.size(); return VSS_SELECT;
 
116
    }
 
117
    return VSS_NONE;
 
118
  }
 
119
 
 
120
  // Select variable with smallest degree (and smallest size in case of ties)
 
121
  forceinline ViewSelStatus
 
122
  ByDegreeMin::init(IntView x) { 
 
123
    degree = x.degree(); size = x.size();
 
124
    return VSS_SELECT;
 
125
  }
 
126
  forceinline ViewSelStatus
 
127
  ByDegreeMin::select(IntView x) {
 
128
    if (x.degree() < degree) {
 
129
      degree = x.degree();
 
130
      size   = x.size();
 
131
      return VSS_SELECT;
 
132
    } else if ((x.degree() == degree) && (x.size() < size)) {
 
133
      size = x.size();
 
134
      return VSS_SELECT;
 
135
    }
 
136
    return VSS_NONE;
 
137
  }
 
138
 
 
139
  // Select variable with smallest degree (and smallest size in case of ties)
 
140
  forceinline ViewSelStatus
 
141
  ByDegreeMax::init(IntView x) { 
 
142
    degree = x.degree(); size = x.size();
 
143
    return VSS_SELECT;
 
144
  }
 
145
  forceinline ViewSelStatus
 
146
  ByDegreeMax::select(IntView x) {
 
147
    if (x.degree() > degree) {
 
148
      degree = x.degree();
 
149
      size   = x.size();
 
150
      return VSS_SELECT;
 
151
    } else if ((x.degree() == degree) && (x.size() < size)) {
 
152
      size = x.size();
 
153
      return VSS_SELECT;
 
154
    }
 
155
    return VSS_NONE;
 
156
  }
 
157
 
 
158
  // Select variable with smallest min-regret
 
159
  forceinline ViewSelStatus
 
160
  ByRegretMinMin::init(IntView x) { 
 
161
    regret = x.regret_min();
 
162
    return (regret == 1) ? VSS_COMMIT : VSS_SELECT;
 
163
  }
 
164
  forceinline ViewSelStatus
 
165
  ByRegretMinMin::select(IntView x) {
 
166
    if (x.regret_min() < regret) {
 
167
      regret = x.regret_min();
 
168
      return (regret == 1) ? VSS_COMMIT : VSS_SELECT;
 
169
    }
 
170
    return VSS_NONE;
 
171
  }
 
172
 
 
173
  // Select variable with largest min-regret
 
174
  forceinline ViewSelStatus
 
175
  ByRegretMinMax::init(IntView x) { 
 
176
    regret = x.regret_min();
 
177
    return VSS_SELECT;
 
178
  }
 
179
  forceinline ViewSelStatus
 
180
  ByRegretMinMax::select(IntView x) {
 
181
    if (x.regret_min() > regret) {
 
182
      regret = x.regret_min(); return VSS_SELECT;
 
183
    }
 
184
    return VSS_NONE;
 
185
  }
 
186
 
 
187
  // Select variable with smallest max-regret
 
188
  forceinline ViewSelStatus
 
189
  ByRegretMaxMin::init(IntView x) { 
 
190
    regret = x.regret_max();
 
191
    return (regret == 1) ? VSS_COMMIT : VSS_SELECT;
 
192
  }
 
193
  forceinline ViewSelStatus
 
194
  ByRegretMaxMin::select(IntView x) {
 
195
    if (x.regret_max() < regret) {
 
196
      regret = x.regret_max();
 
197
      return (regret == 1) ? VSS_COMMIT : VSS_SELECT;
 
198
    }
 
199
    return VSS_NONE;
 
200
  }
 
201
 
 
202
  // Select variable with smallest min-regret
 
203
  forceinline ViewSelStatus
 
204
  ByRegretMaxMax::init(IntView x) { 
 
205
    regret = x.regret_max();
 
206
    return VSS_SELECT;
 
207
  }
 
208
  forceinline ViewSelStatus
 
209
  ByRegretMaxMax::select(IntView x) {
 
210
    if (x.regret_max() > regret) {
 
211
      regret = x.regret_max(); return VSS_SELECT;
 
212
    }
 
213
    return VSS_NONE;
 
214
  }
 
215
 
 
216
}}}
 
217
 
 
218
// STATISTICS: int-branch
 
219