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, 2009
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
34#ifndef GECODE_DRIVER_HH
35#define GECODE_DRIVER_HH
36
37#include <gecode/minimodel.hh>
38#include <gecode/search.hh>
39#ifdef GECODE_HAS_GIST
40#include <gecode/gist.hh>
41#endif
42
43/*
44 * Configure linking
45 *
46 */
47#if !defined(GECODE_STATIC_LIBS) && \
48 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
49
50#ifdef GECODE_BUILD_DRIVER
51#define GECODE_DRIVER_EXPORT __declspec( dllexport )
52#else
53#define GECODE_DRIVER_EXPORT __declspec( dllimport )
54#endif
55
56#else
57
58#ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
59#define GECODE_DRIVER_EXPORT __attribute__ ((visibility("default")))
60#else
61#define GECODE_DRIVER_EXPORT
62#endif
63
64#endif
65
66// Configure auto-linking
67#ifndef GECODE_BUILD_DRIVER
68#define GECODE_LIBRARY_NAME "Driver"
69#include <gecode/support/auto-link.hpp>
70#endif
71
72/**
73 * \namespace Gecode::Driver
74 * \brief Script commandline driver
75 *
76 * The Gecode::Driver namespace contains support for passing common
77 * commandline options and for scripts that use the commandline
78 * options.
79 *
80 */
81
82namespace Gecode {
83
84
85 /**
86 * \defgroup TaskDriverCmd Commandline options for running scripts
87 * \ingroup TaskDriver
88 */
89
90 /**
91 * \brief Different modes for executing scripts
92 * \ingroup TaskDriverCmd
93 */
94 enum ScriptMode {
95 SM_SOLUTION, ///< Print solution and some statistics
96 SM_TIME, ///< Measure average runtime
97 SM_STAT, ///< Print statistics for script
98 SM_GIST, ///< Run script in Gist
99 };
100
101 /**
102 * \brief Different modes for restart-based search
103 * \ingroup TaskDriverCmd
104 */
105 enum RestartMode {
106 RM_NONE, ///< No restarts
107 RM_CONSTANT, ///< Restart with constant sequence
108 RM_LINEAR, ///< Restart with linear sequence
109 RM_LUBY, ///< Restart with Luby sequence
110 RM_GEOMETRIC ///< Restart with geometric sequence
111 };
112
113 class BaseOptions;
114
115 namespace Driver {
116 /**
117 * \brief Base class for options
118 *
119 */
120 class GECODE_DRIVER_EXPORT BaseOption {
121 friend class Gecode::BaseOptions;
122 protected:
123 const char* eopt; ///< String for option (excluding hyphen)
124 const char* iopt; ///< String for option (including hyphen)
125 const char* exp; ///< Short explanation
126 BaseOption* next; ///< Next option
127 /// Check for option and return its argument
128 char* argument(int argc, char* argv[]) const;
129 public:
130 /// Initialize for option \a o and explanation \a e
131 BaseOption(const char* o, const char* e);
132 /// Parse option at first position and return number of parsed arguments
133 virtual int parse(int argc, char* argv[]) = 0;
134 /// Print help text
135 virtual void help(void) = 0;
136 /// Destructor
137 virtual ~BaseOption(void);
138 /// Create heap-allocated copy of string \a s
139 static char* strdup(const char* s);
140 /// Create heap-allocated copy of string \a s with hyphen added
141 static char* stredup(const char* s);
142 /// Delete heap-allocated copy of string \a s
143 static void strdel(const char* s);
144 };
145
146 /**
147 * \brief String-valued option
148 *
149 */
150 class GECODE_DRIVER_EXPORT StringValueOption : public BaseOption {
151 protected:
152 const char* cur; ///< Current value
153 public:
154 /// Initialize for option \a o and explanation \a e and default value \a v
155 StringValueOption(const char* o, const char* e, const char* v=nullptr);
156 /// Set default value to \a v
157 void value(const char* v);
158 /// Return current option value
159 const char* value(void) const;
160 /// Parse option at first position and return number of parsed arguments
161 virtual int parse(int argc, char* argv[]);
162 /// Print help text
163 virtual void help(void);
164 /// Destructor
165 virtual ~StringValueOption(void);
166 };
167
168
169 /**
170 * \brief String-valued option (integer value defined by strings)
171 *
172 */
173 class GECODE_DRIVER_EXPORT StringOption : public BaseOption {
174 protected:
175 /// Option value
176 class Value {
177 public:
178 int val; ///< Value for an option value
179 const char* opt; ///< String for option value
180 const char* help; ///< Optional help text
181 Value* next; ///< Next option value
182 };
183 int cur; ///< Current value
184 Value* fst; ///< First option value
185 Value* lst; ///< Last option value
186 public:
187 /// Initialize for option \a o and explanation \a e and default value \a v
188 StringOption(const char* o, const char* e, int v=0);
189 /// Set default value to \a v
190 void value(int v);
191 /// Return current option value
192 int value(void) const;
193 /// Add option value for value \a v, string \a o, and help text \a h
194 void add(int v, const char* o, const char* h = nullptr);
195 /// Parse option at first position and return number of parsed arguments
196 virtual int parse(int argc, char* argv[]);
197 /// Print help text
198 virtual void help(void);
199 /// Destructor
200 virtual ~StringOption(void);
201 };
202
203
204 /**
205 * \brief Integer option
206 *
207 */
208 class GECODE_DRIVER_EXPORT IntOption : public BaseOption {
209 protected:
210 int cur; ///< Current value
211 public:
212 /// Initialize for option \a o and explanation \a e and default value \a v
213 IntOption(const char* o, const char* e, int v=0);
214 /// Set default value to \a v
215 void value(int v);
216 /// Return current option value
217 int value(void) const;
218 /// Parse option at first position and return number of parsed arguments
219 virtual int parse(int argc, char* argv[]);
220 /// Print help text
221 virtual void help(void);
222 };
223
224 /**
225 * \brief Unsigned integer option
226 *
227 */
228 class GECODE_DRIVER_EXPORT UnsignedIntOption : public BaseOption {
229 protected:
230 unsigned int cur; ///< Current value
231 public:
232 /// Initialize for option \a o and explanation \a e and default value \a v
233 UnsignedIntOption(const char* o, const char* e, unsigned int v=0);
234 /// Set default value to \a v
235 void value(unsigned int v);
236 /// Return current option value
237 unsigned int value(void) const;
238 /// Parse option at first position and return number of parsed arguments
239 virtual int parse(int argc, char* argv[]);
240 /// Print help text
241 virtual void help(void);
242 };
243
244 /**
245 * \brief Unsigned long long integer option
246 *
247 */
248 class GECODE_DRIVER_EXPORT UnsignedLongLongIntOption : public BaseOption {
249 protected:
250 unsigned long long int cur; ///< Current value
251 public:
252 /// Initialize for option \a o and explanation \a e and default value \a v
253 UnsignedLongLongIntOption(const char* o, const char* e,
254 unsigned long long int v=0);
255 /// Set default value to \a v
256 void value(unsigned long long int v);
257 /// Return current option value
258 unsigned long long int value(void) const;
259 /// Parse option at first position and return number of parsed arguments
260 virtual int parse(int argc, char* argv[]);
261 /// Print help text
262 virtual void help(void);
263 };
264
265 /**
266 * \brief Double option
267 *
268 */
269 class GECODE_DRIVER_EXPORT DoubleOption : public BaseOption {
270 protected:
271 double cur; ///< Current value
272 public:
273 /// Initialize for option \a o and explanation \a e and default value \a v
274 DoubleOption(const char* o, const char* e, double v=0);
275 /// Set default value to \a v
276 void value(double v);
277 /// Return current option value
278 double value(void) const;
279 /// Parse option at first position and return number of parsed arguments
280 virtual int parse(int argc, char* argv[]);
281 /// Print help text
282 virtual void help(void);
283 };
284
285 /**
286 * \brief Boolean option
287 *
288 */
289 class GECODE_DRIVER_EXPORT BoolOption : public BaseOption {
290 protected:
291 bool cur; ///< Current value
292 public:
293 /// Initialize for option \a o and explanation \a e and default value \a v
294 BoolOption(const char* o, const char* e, bool v=false);
295 /// Set default value to \a v
296 void value(bool v);
297 /// Return current option value
298 bool value(void) const;
299 /// Parse option at first position and return number of parsed arguments
300 virtual int parse(int argc, char* argv[]);
301 /// Print help text
302 virtual void help(void);
303 };
304
305 /**
306 * \brief Integer propagation level option
307 *
308 */
309 class GECODE_DRIVER_EXPORT IplOption : public BaseOption {
310 protected:
311 IntPropLevel cur; ///< Current value
312 public:
313 /// Initialize with default value \a ipl
314 IplOption(IntPropLevel ipl=IPL_DEF);
315 /// Set default level to \a l
316 void value(IntPropLevel l);
317 /// Return current option value
318 IntPropLevel value(void) const;
319 /// Parse option at first position and return number of parsed arguments
320 virtual int parse(int argc, char* argv[]);
321 /// Print help text
322 virtual void help(void);
323 };
324
325 /**
326 * \brief Trace flag option
327 *
328 */
329 class GECODE_DRIVER_EXPORT TraceOption : public BaseOption {
330 protected:
331 int cur; ///< Current value
332 public:
333 /// Initialize with no tracing
334 TraceOption(int f=0);
335 /// Set default trace flags to \a f
336 void value(int f);
337 /// Return current option value
338 int value(void) const;
339 /// Parse option at first position and return number of parsed arguments
340 virtual int parse(int argc, char* argv[]);
341 /// Print help text
342 virtual void help(void);
343 };
344
345 /**
346 * \brief Profiler option
347 *
348 */
349 class GECODE_DRIVER_EXPORT ProfilerOption : public BaseOption {
350 protected:
351 unsigned int cur_port; ///< Current port
352 int cur_execution_id; ///< Current execution ID
353 public:
354 /// Initialize for option \a o and explanation \a e and default value \a v
355 ProfilerOption(const char* o, const char* e, unsigned int p = 0, int v = -1);
356 /// Set default port to \a p
357 void port(unsigned int p);
358 /// Return current port
359 unsigned int port(void) const;
360 /// Set default execution ID to \a i
361 void execution_id(int i);
362 /// Return current execution ID
363 int execution_id(void) const;
364 /// Parse option at first position and return number of parsed arguments
365 virtual int parse(int argc, char* argv[]);
366 /// Print help text
367 virtual void help(void);
368 };
369 }
370
371 /**
372 * \brief Base class for script options
373 * \ingroup TaskDriverCmd
374 */
375 class GECODE_DRIVER_EXPORT BaseOptions {
376 protected:
377 Driver::BaseOption* fst; ///< First registered option
378 Driver::BaseOption* lst; ///< Last registered option
379 const char* _name; ///< Script name
380 public:
381 /// Initialize options for script with name \a s
382 BaseOptions(const char* s);
383 /// Print help text
384 virtual void help(void);
385
386 /// Add new option \a o
387 void add(Driver::BaseOption& o);
388 /**
389 * \brief Parse options from arguments \a argv (number is \a argc)
390 *
391 * The options are parsed from position one onwards until no more options
392 * are detected. After parsing, the parsed arguments have been removed.
393 *
394 */
395 void parse(int& argc, char* argv[]);
396
397 /// Return name of script
398 const char* name(void) const;
399 /// Set name of script
400 void name(const char*);
401
402 /// Destructor
403 virtual ~BaseOptions(void);
404 };
405
406 /**
407 * \brief %Options for scripts
408 * \ingroup TaskDriverCmd
409 */
410 class GECODE_DRIVER_EXPORT Options : public BaseOptions {
411 protected:
412 /// \name Model options
413 //@{
414 Driver::StringOption _model; ///< General model options
415 Driver::StringOption _symmetry; ///< General symmetry options
416 Driver::StringOption _propagation; ///< Propagation options
417 Driver::IplOption _ipl; ///< Integer propagation level
418 Driver::StringOption _branching; ///< Branching options
419 Driver::DoubleOption _decay; ///< Decay option
420 Driver::UnsignedIntOption _seed; ///< Seed option
421 Driver::DoubleOption _step; ///< Step option
422 //@}
423
424 /// \name Search options
425 //@{
426 Driver::StringOption _search; ///< Search options
427 Driver::UnsignedLongLongIntOption
428 _solutions; ///< How many solutions
429 Driver::DoubleOption _threads; ///< How many threads to use
430 Driver::UnsignedIntOption _c_d; ///< Copy recomputation distance
431 Driver::UnsignedIntOption _a_d; ///< Adaptive recomputation distance
432 Driver::UnsignedIntOption _d_l; ///< Discrepancy limit for LDS
433 Driver::UnsignedLongLongIntOption
434 _node; ///< Cutoff for number of nodes
435 Driver::UnsignedLongLongIntOption
436 _fail; ///< Cutoff for number of failures
437 Driver::DoubleOption _time; ///< Cutoff for time
438 Driver::UnsignedIntOption _assets; ///< Number of assets in a portfolio
439 Driver::UnsignedIntOption _slice; ///< Size of a portfolio slice
440 Driver::StringOption _restart; ///< Restart method option
441 Driver::DoubleOption _r_base; ///< Restart base
442 Driver::UnsignedIntOption _r_scale; ///< Restart scale factor
443 Driver::BoolOption _nogoods; ///< Whether to use no-goods
444 Driver::UnsignedIntOption _nogoods_limit; ///< Limit for no-good extraction
445 Driver::DoubleOption _relax; ///< Probability to relax variable
446 Driver::BoolOption _interrupt; ///< Whether to catch SIGINT
447 //@}
448
449 /// \name Execution options
450 //@{
451 Driver::StringOption _mode; ///< Script mode to run
452 Driver::UnsignedIntOption _samples; ///< How many samples
453 Driver::UnsignedIntOption _iterations; ///< How many iterations per sample
454 Driver::BoolOption _print_last; ///< Print only last solution found
455 Driver::StringValueOption _out_file; ///< Where to print solutions
456 Driver::StringValueOption _log_file; ///< Where to print statistics
457 Driver::TraceOption _trace; ///< Trace flags for tracing
458
459#ifdef GECODE_HAS_CPPROFILER
460 Driver::ProfilerOption _profiler; ///< Options for the CP Profiler
461#endif
462
463 //@}
464
465 public:
466 /// Initialize options for script with name \a s
467 Options(const char* s);
468
469 /// \name Model options
470 //@{
471 /// Set default model value
472 void model(int v);
473 /// Add model option value for value \a v, string \a o, and help \a h
474 void model(int v, const char* o, const char* h = nullptr);
475 /// Return model value
476 int model(void) const;
477
478 /// Set default symmetry value
479 void symmetry(int v);
480 /// Add symmetry option value for value \a v, string \a o, and help \a h
481 void symmetry(int v, const char* o, const char* h = nullptr);
482 /// Return symmetry value
483 int symmetry(void) const;
484
485 /// Set default propagation value
486 void propagation(int v);
487 /// Add propagation option value for value \a v, string \a o, and help \a h
488 void propagation(int v, const char* o, const char* h = nullptr);
489 /// Return propagation value
490 int propagation(void) const;
491
492 /// Set default integer propagation level
493 void ipl(IntPropLevel i);
494 /// Return integer propagation level
495 IntPropLevel ipl(void) const;
496
497 /// Set default branching value
498 void branching(int v);
499 /// Add branching option value for value \a v, string \a o, and help \a h
500 void branching(int v, const char* o, const char* h = nullptr);
501 /// Return branching value
502 int branching(void) const;
503
504 /// Set default decay factor
505 void decay(double d);
506 /// Return decay factor
507 double decay(void) const;
508
509 /// Set default seed value
510 void seed(unsigned int s);
511 /// Return seed value
512 unsigned int seed(void) const;
513
514 /// Set default step value
515 void step(double s);
516 /// Return step value
517 double step(void) const;
518 //@}
519
520 /// \name Search options
521 //@{
522 /// Set default search value
523 void search(int v);
524 /// Add search option value for value \a v, string \a o, and help \a h
525 void search(int v, const char* o, const char* h = nullptr);
526 /// Return search value
527 int search(void) const;
528
529 /// Set default number of solutions to search for
530 void solutions(unsigned long long int n);
531 /// Return number of solutions to search for
532 unsigned long long int solutions(void) const;
533
534 /// Set number of parallel threads
535 void threads(double n);
536 /// Return number of parallel threads
537 double threads(void) const;
538
539 /// Set default copy recomputation distance
540 void c_d(unsigned int d);
541 /// Return copy recomputation distance
542 unsigned int c_d(void) const;
543
544 /// Set default adaptive recomputation distance
545 void a_d(unsigned int d);
546 /// Return adaptive recomputation distance
547 unsigned int a_d(void) const;
548
549 /// Set default discrepancy limit for LDS
550 void d_l(unsigned int d);
551 /// Return discrepancy limit for LDS
552 unsigned int d_l(void) const;
553
554 /// Set default node cutoff
555 void node(unsigned long long int n);
556 /// Return node cutoff
557 unsigned long long int node(void) const;
558
559 /// Set default failure cutoff
560 void fail(unsigned long long int n);
561 /// Return failure cutoff
562 unsigned long long int fail(void) const;
563
564 /// Set default time cutoff
565 void time(double t);
566 /// Return time cutoff
567 double time(void) const;
568
569 /// Set default number of assets in a portfolio
570 void assets(unsigned int n);
571 /// Return slice size in a portfolio
572 unsigned int assets(void) const;
573
574 /// Set default slice size in a portfolio
575 void slice(unsigned int n);
576 /// Return slice size in a portfolio
577 unsigned int slice(void) const;
578
579 /// Set default restart mode
580 void restart(RestartMode r);
581 /// Return restart mode
582 RestartMode restart(void) const;
583
584 /// Set default restart base
585 void restart_base(double base);
586 /// Return restart base
587 double restart_base(void) const;
588
589 /// Set default restart scale factor
590 void restart_scale(unsigned int scale);
591 /// Return restart scale factor
592 unsigned int restart_scale(void) const;
593
594 /// Set default nogoods posting behavior
595 void nogoods(bool b);
596 /// Return whether nogoods are used
597 bool nogoods(void) const;
598
599 /// Set default nogoods depth limit
600 void nogoods_limit(unsigned int l);
601 /// Return depth limit for nogoods
602 unsigned int nogoods_limit(void) const;
603
604 /// Set default relax probability
605 void relax(double d);
606 /// Return default relax probability
607 double relax(void) const;
608
609 /// Set default interrupt behavior
610 void interrupt(bool b);
611 /// Return interrupt behavior
612 bool interrupt(void) const;
613 //@}
614
615 /// \name Execution options
616 //@{
617 /// Set default mode
618 void mode(ScriptMode em);
619 /// Return mode
620 ScriptMode mode(void) const;
621
622 /// Set default number of samples
623 void samples(unsigned int s);
624 /// Return number of samples
625 unsigned int samples(void) const;
626
627 /// Set default number of iterations
628 void iterations(unsigned int i);
629 /// Return number of iterations
630 unsigned int iterations(void) const;
631
632 /// Set whether to print only last solution found
633 void print_last(bool p);
634 /// Return whether to print only last solution found
635 bool print_last(void) const;
636
637 /// Set default output file name for solutions
638 void out_file(const char* f);
639 /// Get file name for solutions
640 const char* out_file(void) const;
641
642 /// Set default output file name for Gecode stats
643 void log_file(const char* f);
644 /// Get file name for Gecode stats
645 const char* log_file(void) const;
646
647 /// Set trace flags
648 void trace(int f);
649 /// Return trace flags
650 int trace(void) const;
651
652#ifdef GECODE_HAS_CPPROFILER
653 /// Set profiler execution identifier
654 void profiler_id(int i);
655 /// Return profiler execution id
656 int profiler_id(void) const;
657 /// Set profiler port
658 void profiler_port(unsigned int p);
659 /// Return profiler execution id
660 unsigned int profiler_port(void) const;
661#endif
662 //@}
663
664#ifdef GECODE_HAS_GIST
665 /// Helper class storing Gist inspectors
666 class I_ {
667 private:
668 /// The double click inspectors
669 Support::DynamicArray<Gist::Inspector*,Heap> _click;
670 /// Number of double click inspectors
671 unsigned int n_click;
672 /// The solution inspectors
673 Support::DynamicArray<Gist::Inspector*,Heap> _solution;
674 /// Number of solution inspectors
675 unsigned int n_solution;
676 /// The move inspectors
677 Support::DynamicArray<Gist::Inspector*,Heap> _move;
678 /// Number of move inspectors
679 unsigned int n_move;
680 /// The comparators
681 Support::DynamicArray<Gist::Comparator*,Heap> _compare;
682 /// Number of comparators
683 unsigned int n_compare;
684 public:
685 /// Constructor
686 I_(void);
687 /// Add inspector that reacts on node double clicks
688 void click(Gist::Inspector* i);
689 /// Add inspector that reacts on each new solution that is found
690 void solution(Gist::Inspector* i);
691 /// Add inspector that reacts on each move of the cursor
692 void move(Gist::Inspector* i);
693 /// Add comparator
694 void compare(Gist::Comparator* i);
695
696 /// Return click inspector number \a i, or nullptr if it does not exist
697 Gist::Inspector* click(unsigned int i) const;
698 /// Return solution inspector number \a i, or nullptr if it does not exist
699 Gist::Inspector* solution(unsigned int i) const;
700 /// Return move inspector number \a i, or nullptr if it does not exist
701 Gist::Inspector* move(unsigned int i) const;
702 /// Return comparator number \a i, or nullptr if it does not exist
703 Gist::Comparator* compare(unsigned int i) const;
704 } inspect;
705#endif
706 };
707
708}
709
710namespace Gecode {
711
712 /**
713 * \brief %Options for scripts with additional size parameter
714 * \ingroup TaskDriverCmd
715 */
716 class GECODE_DRIVER_EXPORT SizeOptions : public Options {
717 protected:
718 unsigned int _size; ///< Size value
719 public:
720 /// Initialize options for script with name \a s
721 SizeOptions(const char* s);
722 /// Print help text
723 virtual void help(void);
724 /// Parse options from arguments \a argv (number is \a argc)
725 void parse(int& argc, char* argv[]);
726
727 /// Set default size
728 void size(unsigned int s);
729 /// Return size
730 unsigned int size(void) const;
731 };
732
733 /**
734 * \brief %Options for scripts with additional instance parameter
735 * \ingroup TaskDriverCmd
736 */
737 class GECODE_DRIVER_EXPORT InstanceOptions : public Options {
738 protected:
739 const char* _inst; ///< Instance string
740 public:
741 /// Initialize options for script with name \a s
742 InstanceOptions(const char* s);
743 /// Print help text
744 virtual void help(void);
745 /// Parse options from arguments \a argv (number is \a argc)
746 void parse(int& argc, char* argv[]);
747
748 /// Set default instance name
749 void instance(const char* s);
750 /// Return instance name
751 const char* instance(void) const;
752 /// Destructor
753 ~InstanceOptions(void);
754 };
755
756}
757
758#include <gecode/driver/options.hpp>
759
760namespace Gecode { namespace Driver {
761
762 /**
763 * \brief Parametric base-class for scripts
764 *
765 * All scripts must inherit from this class
766 * - adds printing and comparison for Gist to scripts
767 * - run allows to execute scripts
768 */
769 template<class BaseSpace>
770 class ScriptBase : public BaseSpace {
771 public:
772 /// Constructor
773 ScriptBase(const Options& opt);
774 /// Constructor used for cloning
775 ScriptBase(ScriptBase& e);
776 /// Print a solution to \a os
777 virtual void print(std::ostream& os) const;
778 /// Compare with \a s
779 virtual void compare(const Space& home, std::ostream& os) const;
780 /// Choose output stream according to \a sn
781 static std::ostream& select_ostream(const char* sn, std::ofstream& ofs);
782 /** Run script with search engine \a Engine and options \a opt
783 *
784 * In the solution and stat modes, search can be aborted by sending
785 * SIGINT to the process (i.e., pressing Ctrl-C on the command
786 * line).
787 *
788 * In case \a s is different from nullptr, the search engine uses
789 * \a s as root of the search tree.
790 */
791 template<class Script, template<class> class Engine, class Options>
792 static void run(const Options& opt, Script* s=nullptr);
793 private:
794 template<class Script, template<class> class Engine, class Options,
795 template<class, template<class> class> class Meta>
796 static void runMeta(const Options& opt, Script* s);
797 };
798
799#ifdef GECODE_HAS_FLOAT_VARS
800
801 /// Class to extract the step option value
802 template<class BaseSpace>
803 class ExtractStepOption : public BaseSpace {
804 public:
805 /// Constructor that extracts the step value
806 ExtractStepOption(const Options& opt)
807 : BaseSpace(opt.step()) {}
808 /// Constructor used for cloning
809 ExtractStepOption(BaseSpace& e)
810 : BaseSpace(e) {}
811 };
812
813#endif
814
815 /// Class to ignore the step option value
816 template<class BaseSpace>
817 class IgnoreStepOption : public BaseSpace {
818 public:
819 /// Constructor
820 IgnoreStepOption(const Options&) {}
821 /// Constructor used for cloning
822 IgnoreStepOption(BaseSpace& e)
823 : BaseSpace(e) {}
824 };
825
826}}
827
828#include <gecode/driver/script.hpp>
829
830namespace Gecode {
831
832 /**
833 * \defgroup TaskDriverScript Script classes
834 * \ingroup TaskDriver
835 */
836
837 /**
838 * \brief Base-class for scripts
839 * \ingroup TaskDriverScript
840 */
841 typedef Driver::ScriptBase<Driver::IgnoreStepOption<Space> >
842 Script;
843
844 /**
845 * \brief Base-class for scripts for finding solution of lowest integer cost
846 * \ingroup TaskDriverScript
847 */
848 typedef Driver::ScriptBase<Driver::IgnoreStepOption<IntMinimizeSpace> >
849 IntMinimizeScript;
850 /**
851 * \brief Base-class for scripts for finding solution of highest integer cost
852 * \ingroup TaskDriverScript
853 */
854 typedef Driver::ScriptBase<Driver::IgnoreStepOption<IntMaximizeSpace> >
855 IntMaximizeScript;
856
857 /**
858 * \brief Base-class for scripts for finding solution of lexically lowest integer costs
859 * \ingroup TaskDriverScript
860 */
861 typedef Driver::ScriptBase<Driver::IgnoreStepOption<IntLexMinimizeSpace> >
862 IntLexMinimizeScript;
863 /**
864 * \brief Base-class for scripts for finding solution of lexically highest integer costs
865 * \ingroup TaskDriverScript
866 */
867 typedef Driver::ScriptBase<Driver::IgnoreStepOption<IntLexMaximizeSpace> >
868 IntLexMaximizeScript;
869
870#ifdef GECODE_HAS_FLOAT_VARS
871
872 /**
873 * \brief Base-class for scripts for finding solution of lowest float cost
874 * \ingroup TaskDriverScript
875 */
876 typedef Driver::ScriptBase<Driver::ExtractStepOption<FloatMinimizeSpace> >
877 FloatMinimizeScript;
878 /**
879 * \brief Base-class for scripts for finding solution of highest float cost
880 * \ingroup TaskDriverScript
881 */
882 typedef Driver::ScriptBase<Driver::ExtractStepOption<FloatMaximizeSpace> >
883 FloatMaximizeScript;
884
885#endif
886
887}
888
889#endif
890
891// STATISTICS: driver-any