/usr/include/gecode/driver.hh is in libgecode-dev 3.7.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2009
*
* Last modified:
* $Date: 2010-10-06 22:44:30 +0200 (Wed, 06 Oct 2010) $ by $Author: schulte $
* $Revision: 11465 $
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __GECODE_DRIVER_HH__
#define __GECODE_DRIVER_HH__
#include <gecode/minimodel.hh>
#include <gecode/search.hh>
#ifdef GECODE_HAS_GIST
#include <gecode/gist.hh>
#endif
/*
* Configure linking
*
*/
#if !defined(GECODE_STATIC_LIBS) && \
(defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
#ifdef GECODE_BUILD_DRIVER
#define GECODE_DRIVER_EXPORT __declspec( dllexport )
#else
#define GECODE_DRIVER_EXPORT __declspec( dllimport )
#endif
#else
#ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
#define GECODE_DRIVER_EXPORT __attribute__ ((visibility("default")))
#else
#define GECODE_DRIVER_EXPORT
#endif
#endif
// Configure auto-linking
#ifndef GECODE_BUILD_DRIVER
#define GECODE_LIBRARY_NAME "Driver"
#include <gecode/support/auto-link.hpp>
#endif
/**
* \namespace Gecode::Driver
* \brief Script commandline driver
*
* The Gecode::Driver namespace contains support for passing common
* commandline options and for scripts that use the commandline
* options.
*
*/
namespace Gecode {
/**
* \defgroup TaskDriverCmd Commandline options for running scripts
* \ingroup TaskDriver
*/
/**
* \brief Different modes for executing scripts
* \ingroup TaskDriverCmd
*/
enum ScriptMode {
SM_SOLUTION, ///< Print solution and some statistics
SM_TIME, ///< Measure average runtime
SM_STAT, ///< Print statistics for script
SM_GIST ///< Run script in Gist
};
class BaseOptions;
namespace Driver {
/**
* \brief Base class for options
*
*/
class GECODE_DRIVER_EXPORT BaseOption {
friend class Gecode::BaseOptions;
protected:
const char* opt; ///< String for option (including hyphen)
const char* exp; ///< Short explanation
BaseOption* next; ///< Next option
public:
/// Initialize for option \a o and explanation \a e
BaseOption(const char* o, const char* e);
/// Parse option at first position and possibly delete
virtual bool parse(int& argc, char* argv[]) = 0;
/// Print help text
virtual void help(void) = 0;
/// Destructor
virtual ~BaseOption(void);
/// Create heap-allocated copy of string \a s
static char* strdup(const char* s);
/// Delete heap-allocated copy of string \a s
static void strdel(const char* s);
};
/**
* \brief String-valued option
*
*/
class GECODE_DRIVER_EXPORT StringValueOption : public BaseOption {
protected:
const char* cur; ///< Current value
public:
/// Initialize for option \a o and explanation \a e and default value \a v
StringValueOption(const char* o, const char* e, const char* v=NULL);
/// Set default value to \a v
void value(const char* v);
/// Return current option value
const char* value(void) const;
/// Parse option at first position
virtual bool parse(int& argc, char* argv[]);
/// Print help text
virtual void help(void);
/// Destructor
virtual ~StringValueOption(void);
};
/**
* \brief String-valued option (integer value defined by strings)
*
*/
class GECODE_DRIVER_EXPORT StringOption : public BaseOption {
protected:
/// Option value
class Value {
public:
int val; ///< Value for an option value
const char* opt; ///< String for option value
const char* help; ///< Optional help text
Value* next; ///< Next option value
};
int cur; ///< Current value
Value* fst; ///< First option value
Value* lst; ///< Last option value
public:
/// Initialize for option \a o and explanation \a e and default value \a v
StringOption(const char* o, const char* e, int v=0);
/// Set default value to \a v
void value(int v);
/// Return current option value
int value(void) const;
/// Add option value for value \a v, string \a o, and help text \a h
void add(int v, const char* o, const char* h = NULL);
/// Parse option at first position
virtual bool parse(int& argc, char* argv[]);
/// Print help text
virtual void help(void);
/// Destructor
virtual ~StringOption(void);
};
/**
* \brief Integer option
*
*/
class GECODE_DRIVER_EXPORT IntOption : public BaseOption {
protected:
int cur; ///< Current value
public:
/// Initialize for option \a o and explanation \a e and default value \a v
IntOption(const char* o, const char* e, int v=0);
/// Set default value to \a v
void value(int v);
/// Return current option value
int value(void) const;
/// Parse option at first position
virtual bool parse(int& argc, char* argv[]);
/// Print help text
virtual void help(void);
};
/**
* \brief Unsigned integer option
*
*/
class GECODE_DRIVER_EXPORT UnsignedIntOption : public BaseOption {
protected:
unsigned int cur; ///< Current value
public:
/// Initialize for option \a o and explanation \a e and default value \a v
UnsignedIntOption(const char* o, const char* e, unsigned int v=0);
/// Set default value to \a v
void value(unsigned int v);
/// Return current option value
unsigned int value(void) const;
/// Parse option at first position
virtual bool parse(int& argc, char* argv[]);
/// Print help text
virtual void help(void);
};
/**
* \brief Double option
*
*/
class GECODE_DRIVER_EXPORT DoubleOption : public BaseOption {
protected:
double cur; ///< Current value
public:
/// Initialize for option \a o and explanation \a e and default value \a v
DoubleOption(const char* o, const char* e, unsigned int v=0);
/// Set default value to \a v
void value(double v);
/// Return current option value
double value(void) const;
/// Parse option at first position
virtual bool parse(int& argc, char* argv[]);
/// Print help text
virtual void help(void);
};
/**
* \brief Boolean option
*
*/
class GECODE_DRIVER_EXPORT BoolOption : public BaseOption {
protected:
bool cur; ///< Current value
public:
/// Initialize for option \a o and explanation \a e and default false
BoolOption(const char* o, const char* e);
/// Set default value to \a v
void value(bool v);
/// Return current option value
bool value(void) const;
/// Parse option at first position
virtual bool parse(int& argc, char* argv[]);
/// Print help text
virtual void help(void);
};
}
/**
* \brief Base class for script options
* \ingroup TaskDriverCmd
*/
class GECODE_DRIVER_EXPORT BaseOptions {
protected:
Driver::BaseOption* fst; ///< First registered option
Driver::BaseOption* lst; ///< Last registered option
const char* _name; ///< Script name
public:
/// Initialize options for script with name \a s
BaseOptions(const char* s);
/// Print help text
virtual void help(void);
/// Add new option \a o
void add(Driver::BaseOption& o);
/// Parse options from arguments \a argv (number is \a argc)
void parse(int& argc, char* argv[]);
/// Return name of script
const char* name(void) const;
/// Set name of script
void name(const char*);
/// Destructor
virtual ~BaseOptions(void);
};
/**
* \brief %Options for scripts
* \ingroup TaskDriverCmd
*/
class GECODE_DRIVER_EXPORT Options : public BaseOptions {
protected:
/// \name Model options
//@{
Driver::StringOption _model; ///< General model options
Driver::StringOption _symmetry; ///< General symmetry options
Driver::StringOption _propagation; ///< Propagation options
Driver::StringOption _icl; ///< Integer consistency level
Driver::StringOption _branching; ///< Branching options
//@}
/// \name Search options
//@{
Driver::StringOption _search; ///< Search options
Driver::UnsignedIntOption _solutions; ///< How many solutions
Driver::DoubleOption _threads; ///< How many threads to use
Driver::UnsignedIntOption _c_d; ///< Copy recomputation distance
Driver::UnsignedIntOption _a_d; ///< Adaptive recomputation distance
Driver::UnsignedIntOption _node; ///< Cutoff for number of nodes
Driver::UnsignedIntOption _fail; ///< Cutoff for number of failures
Driver::UnsignedIntOption _time; ///< Cutoff for time
Driver::StringOption _interrupt; ///< Whether to catch SIGINT
//@}
/// \name Execution options
//@{
Driver::StringOption _mode; ///< Script mode to run
Driver::UnsignedIntOption _samples; ///< How many samples
Driver::UnsignedIntOption _iterations; ///< How many iterations per sample
//@}
public:
/// Initialize options for script with name \a s
Options(const char* s);
/// \name Model options
//@{
/// Set default model value
void model(int v);
/// Add model option value for value \a v, string \a o, and help \a h
void model(int v, const char* o, const char* h = NULL);
/// Return model value
int model(void) const;
/// Set default symmetry value
void symmetry(int v);
/// Add symmetry option value for value \a v, string \a o, and help \a h
void symmetry(int v, const char* o, const char* h = NULL);
/// Return symmetry value
int symmetry(void) const;
/// Set default propagation value
void propagation(int v);
/// Add propagation option value for value \a v, string \a o, and help \a h
void propagation(int v, const char* o, const char* h = NULL);
/// Return propagation value
int propagation(void) const;
/// Set default integer consistency level
void icl(IntConLevel i);
/// Return integer consistency level
IntConLevel icl(void) const;
/// Set default branching value
void branching(int v);
/// Add branching option value for value \a v, string \a o, and help \a h
void branching(int v, const char* o, const char* h = NULL);
/// Return branching value
int branching(void) const;
//@}
/// \name Search options
//@{
/// Set default search value
void search(int v);
/// Add search option value for value \a v, string \a o, and help \a h
void search(int v, const char* o, const char* h = NULL);
/// Return search value
int search(void) const;
/// Set default number of solutions to search for
void solutions(unsigned int n);
/// Return number of solutions to search for
unsigned int solutions(void) const;
/// Set number of parallel threads
void threads(double n);
/// Return number of parallel threads
double threads(void) const;
/// Set default copy recomputation distance
void c_d(unsigned int d);
/// Return copy recomputation distance
unsigned int c_d(void) const;
/// Set default adaptive recomputation distance
void a_d(unsigned int d);
/// Return adaptive recomputation distance
unsigned int a_d(void) const;
/// Set default node cutoff
void node(unsigned int n);
/// Return node cutoff
unsigned int node(void) const;
/// Set default failure cutoff
void fail(unsigned int n);
/// Return failure cutoff
unsigned int fail(void) const;
/// Set default time cutoff
void time(unsigned int t);
/// Return time cutoff
unsigned int time(void) const;
/// Set default interrupt behavior
void interrupt(bool b);
/// Return interrupt behavior
bool interrupt(void) const;
//@}
/// \name Execution options
//@{
/// Set default mode
void mode(ScriptMode em);
/// Return mode
ScriptMode mode(void) const;
/// Set default number of iterations
void iterations(unsigned int i);
/// Return number of iterations
unsigned int iterations(void) const;
/// Set default number of samples
void samples(unsigned int s);
/// Return number of samples
unsigned int samples(void) const;
//@}
#ifdef GECODE_HAS_GIST
/// Helper class storing Gist inspectors
class _I {
private:
/// The double click inspectors
Support::DynamicArray<Gist::Inspector*,Heap> _click;
/// Number of double click inspectors
unsigned int n_click;
/// The solution inspectors
Support::DynamicArray<Gist::Inspector*,Heap> _solution;
/// Number of solution inspectors
unsigned int n_solution;
/// The move inspectors
Support::DynamicArray<Gist::Inspector*,Heap> _move;
/// Number of move inspectors
unsigned int n_move;
/// The comparators
Support::DynamicArray<Gist::Comparator*,Heap> _compare;
/// Number of comparators
unsigned int n_compare;
public:
/// Constructor
_I(void);
/// Add inspector that reacts on node double clicks
void click(Gist::Inspector* i);
/// Add inspector that reacts on each new solution that is found
void solution(Gist::Inspector* i);
/// Add inspector that reacts on each move of the cursor
void move(Gist::Inspector* i);
/// Add comparator
void compare(Gist::Comparator* i);
/// Return click inspector number \a i, or NULL if it does not exist
Gist::Inspector* click(unsigned int i) const;
/// Return solution inspector number \a i, or NULL if it does not exist
Gist::Inspector* solution(unsigned int i) const;
/// Return move inspector number \a i, or NULL if it does not exist
Gist::Inspector* move(unsigned int i) const;
/// Return comparator number \a i, or NULL if it does not exist
Gist::Comparator* compare(unsigned int i) const;
} inspect;
#endif
};
/**
* \brief %Options for scripts with additional size parameter
* \ingroup TaskDriverCmd
*/
class GECODE_DRIVER_EXPORT SizeOptions : public Options {
protected:
unsigned int _size; ///< Size value
public:
/// Initialize options for script with name \a s
SizeOptions(const char* s);
/// Print help text
virtual void help(void);
/// Parse options from arguments \a argv (number is \a argc)
void parse(int& argc, char* argv[]);
/// Set default size
void size(unsigned int s);
/// Return size
unsigned int size(void) const;
};
/**
* \brief %Options for scripts with additional instance parameter
* \ingroup TaskDriverCmd
*/
class GECODE_DRIVER_EXPORT InstanceOptions : public Options {
protected:
const char* _inst; ///< Instance string
public:
/// Initialize options for script with name \a s
InstanceOptions(const char* s);
/// Print help text
virtual void help(void);
/// Parse options from arguments \a argv (number is \a argc)
void parse(int& argc, char* argv[]);
/// Set default instance name
void instance(const char* s);
/// Return instance name
const char* instance(void) const;
/// Destructor
~InstanceOptions(void);
};
}
#include <gecode/driver/options.hpp>
namespace Gecode {
namespace Driver {
/**
* \brief Parametric base-class for scripts
*
* All scripts must inherit from this class
* - adds printing and comparison for Gist to scripts
* - run allows to execute scripts
*/
template<class BaseSpace>
class ScriptBase : public BaseSpace {
public:
/// Default constructor
ScriptBase(void) {}
/// Constructor used for cloning
ScriptBase(bool share, ScriptBase& e) : BaseSpace(share,e) {}
/// Print a solution to \a os
virtual void print(std::ostream& os) const { (void) os; }
/// Compare with \a s
virtual void compare(const Space&, std::ostream& os) const {
(void) os;
}
/** Run script with search engine \a Engine and options \a opt
*
* In the solution and stat modes, search can be aborted by sending
* SIGINT to the process (i.e., pressing Ctrl-C on the command
* line).
*
*/
template<class Script, template<class> class Engine, class Options>
static void run(const Options& opt);
private:
/// Catch wrong definitions of copy constructor
explicit ScriptBase(ScriptBase& e);
};
}
/**
* \defgroup TaskDriverScript Script classes
* \ingroup TaskDriver
*/
/**
* \brief Base-class for scripts
* \ingroup TaskDriverScript
*/
typedef Driver::ScriptBase<Space> Script;
/**
* \brief Base-class for scripts for finding solution of lowest cost
* \ingroup TaskDriverScript
*/
typedef Driver::ScriptBase<MinimizeSpace> MinimizeScript;
/**
* \brief Base-class for scripts for finding solution of highest cost
* \ingroup TaskDriverScript
*/
typedef Driver::ScriptBase<MaximizeSpace> MaximizeScript;
}
#include <gecode/driver/script.hpp>
#endif
// STATISTICS: driver-any
|