Generated on Wed Sep 5 2012 18:51:38 for Gecode by doxygen 1.8.1.1
options.hpp
Go to the documentation of this file.
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, 2004
8  *
9  * Last modified:
10  * $Date: 2011-02-22 23:52:12 +1100 (Tue, 22 Feb 2011) $ by $Author: schulte $
11  * $Revision: 11766 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  *
18  * Permission is hereby granted, free of charge, to any person obtaining
19  * a copy of this software and associated documentation files (the
20  * "Software"), to deal in the Software without restriction, including
21  * without limitation the rights to use, copy, modify, merge, publish,
22  * distribute, sublicense, and/or sell copies of the Software, and to
23  * permit persons to whom the Software is furnished to do so, subject to
24  * the following conditions:
25  *
26  * The above copyright notice and this permission notice shall be
27  * included in all copies or substantial portions of the Software.
28  *
29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36  *
37  */
38 
39 #include <cstring>
40 
41 namespace Gecode {
42 
43  namespace Driver {
44  /*
45  * String option
46  *
47  */
48  inline
49  StringValueOption::StringValueOption(const char* o, const char* e,
50  const char* v)
51  : BaseOption(o,e), cur(strdup(v)) {}
52  inline void
53  StringValueOption::value(const char* v) {
54  strdel(cur);
55  cur = strdup(v);
56  }
57  inline const char*
59  return cur;
60  }
61 
62  /*
63  * String option
64  *
65  */
66  inline
67  StringOption::StringOption(const char* o, const char* e, int v)
68  : BaseOption(o,e), cur(v), fst(NULL), lst(NULL) {}
69  inline void
71  cur = v;
72  }
73  inline int
74  StringOption::value(void) const {
75  return cur;
76  }
77 
78  /*
79  * Integer option
80  *
81  */
82  inline
83  IntOption::IntOption(const char* o, const char* e, int v)
84  : BaseOption(o,e), cur(v) {}
85  inline void
87  cur = v;
88  }
89  inline int
90  IntOption::value(void) const {
91  return cur;
92  }
93 
94  /*
95  * Unsigned integer option
96  *
97  */
98  inline
99  UnsignedIntOption::UnsignedIntOption(const char* o, const char* e,
100  unsigned int v)
101  : BaseOption(o,e), cur(v) {}
102  inline void
103  UnsignedIntOption::value(unsigned int v) {
104  cur = v;
105  }
106  inline unsigned int
108  return cur;
109  }
110 
111  /*
112  * Double option
113  *
114  */
115  inline
116  DoubleOption::DoubleOption(const char* o, const char* e,
117  unsigned int v)
118  : BaseOption(o,e), cur(v) {}
119  inline void
121  cur = v;
122  }
123  inline double
124  DoubleOption::value(void) const {
125  return cur;
126  }
127 
128  /*
129  * Bool option
130  *
131  */
132  inline
133  BoolOption::BoolOption(const char* o, const char* e)
134  : BaseOption(o,e), cur(false) {}
135  inline void
137  cur = v;
138  }
139  inline bool
140  BoolOption::value(void) const {
141  return cur;
142  }
143 
144 
145  }
146 
147  /*
148  * Options
149  *
150  */
151  inline void
153  o.next = NULL;
154  if (fst == NULL) {
155  fst=&o;
156  } else {
157  lst->next=&o;
158  }
159  lst=&o;
160  }
161  inline const char*
162  BaseOptions::name(void) const {
163  return _name;
164  }
165 
166 
167 
168  /*
169  * Model options
170  *
171  */
172  inline void
174  _model.value(v);
175  }
176  inline void
177  Options::model(int v, const char* o, const char* h) {
178  _model.add(v,o,h);
179  }
180  inline int
181  Options::model(void) const {
182  return _model.value();
183  }
184 
185  inline void
187  _symmetry.value(v);
188  }
189  inline void
190  Options::symmetry(int v, const char* o, const char* h) {
191  _symmetry.add(v,o,h);
192  }
193  inline int
194  Options::symmetry(void) const {
195  return _symmetry.value();
196  }
197 
198  inline void
200  _propagation.value(v);
201  }
202  inline void
203  Options::propagation(int v, const char* o, const char* h) {
204  _propagation.add(v,o,h);
205  }
206  inline int
207  Options::propagation(void) const {
208  return _propagation.value();
209  }
210 
211  inline void
213  _icl.value(i);
214  }
215  inline IntConLevel
216  Options::icl(void) const {
217  return static_cast<IntConLevel>(_icl.value());
218  }
219 
220  inline void
222  _branching.value(v);
223  }
224  inline void
225  Options::branching(int v, const char* o, const char* h) {
226  _branching.add(v,o,h);
227  }
228  inline int
229  Options::branching(void) const {
230  return _branching.value();
231  }
232 
233  /*
234  * Search options
235  *
236  */
237  inline void
239  _search.value(v);
240  }
241  inline void
242  Options::search(int v, const char* o, const char* h) {
243  _search.add(v,o,h);
244  }
245  inline int
246  Options::search(void) const {
247  return _search.value();
248  }
249 
250  inline void
251  Options::solutions(unsigned int n) {
252  _solutions.value(n);
253  }
254  inline unsigned int
255  Options::solutions(void) const {
256  return _solutions.value();
257  }
258 
259  inline void
260  Options::threads(double n) {
261  _threads.value(n);
262  }
263  inline double
264  Options::threads(void) const {
265  return _threads.value();
266  }
267 
268  inline void
269  Options::c_d(unsigned int d) {
270  _c_d.value(d);
271  }
272  inline unsigned int
273  Options::c_d(void) const {
274  return _c_d.value();
275  }
276 
277  inline void
278  Options::a_d(unsigned int d) {
279  _a_d.value(d);
280  }
281  inline unsigned int
282  Options::a_d(void) const {
283  return _a_d.value();
284  }
285 
286  inline void
287  Options::node(unsigned int n) {
288  _node.value(n);
289  }
290  inline unsigned int
291  Options::node(void) const {
292  return _node.value();
293  }
294 
295  inline void
296  Options::fail(unsigned int n) {
297  _fail.value(n);
298  }
299  inline unsigned int
300  Options::fail(void) const {
301  return _fail.value();
302  }
303 
304  inline void
305  Options::time(unsigned int t) {
306  _time.value(t);
307  }
308  inline unsigned int
309  Options::time(void) const {
310  return _time.value();
311  }
312 
313  inline void
315  _interrupt.value(b);
316  }
317  inline bool
318  Options::interrupt(void) const {
319  return static_cast<bool>(_interrupt.value());
320  }
321 
322 
323  /*
324  * Execution options
325  *
326  */
327  inline void
329  _mode.value(sm);
330  }
331  inline ScriptMode
332  Options::mode(void) const {
333  return static_cast<ScriptMode>(_mode.value());
334  }
335 
336  inline void
337  Options::iterations(unsigned int i) {
338  _iterations.value(i);
339  }
340  inline unsigned int
341  Options::iterations(void) const {
342  return _iterations.value();
343  }
344 
345  inline void
346  Options::samples(unsigned int s) {
347  _samples.value(s);
348  }
349  inline unsigned int
350  Options::samples(void) const {
351  return _samples.value();
352  }
353 
354 #ifdef GECODE_HAS_GIST
356  Options::_I::_I(void) : _click(heap,1), n_click(0),
357  _solution(heap,1), n_solution(0), _move(heap,1), n_move(0),
358  _compare(heap,1), n_compare(0) {}
359 
360  forceinline void
361  Options::_I::click(Gist::Inspector* i) {
362  _click[static_cast<int>(n_click++)] = i;
363  }
364  forceinline void
365  Options::_I::solution(Gist::Inspector* i) {
366  _solution[static_cast<int>(n_solution++)] = i;
367  }
368  forceinline void
369  Options::_I::move(Gist::Inspector* i) {
370  _move[static_cast<int>(n_move++)] = i;
371  }
372  forceinline void
373  Options::_I::compare(Gist::Comparator* i) {
374  _compare[static_cast<int>(n_compare++)] = i;
375  }
376  forceinline Gist::Inspector*
377  Options::_I::click(unsigned int i) const {
378  return (i < n_click) ? _click[i] : NULL;
379  }
380  forceinline Gist::Inspector*
381  Options::_I::solution(unsigned int i) const {
382  return (i < n_solution) ? _solution[i] : NULL;
383  }
384  forceinline Gist::Inspector*
385  Options::_I::move(unsigned int i) const {
386  return (i < n_move) ? _move[i] : NULL;
387  }
388  forceinline Gist::Comparator*
389  Options::_I::compare(unsigned int i) const {
390  return (i < n_compare) ? _compare[i] : NULL;
391  }
392 #endif
393 
394  /*
395  * Options with additional size argument
396  *
397  */
398  inline void
399  SizeOptions::size(unsigned int s) {
400  _size = s;
401  }
402  inline unsigned int
403  SizeOptions::size(void) const {
404  return _size;
405  }
406 
407  /*
408  * Options with additional string argument
409  *
410  */
411  inline const char*
413  return _inst;
414  }
415 
416 }
417 
418 // STATISTICS: driver-any