main page
modules
namespaces
classes
files
Gecode home
Generated on Sat May 25 2013 18:00:32 for Gecode by
doxygen
1.8.3.1
gecode
driver.hh
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, 2009
8
*
9
* Last modified:
10
* $Date: 2013-02-26 14:40:29 +0100 (Tue, 26 Feb 2013) $ by $Author: schulte $
11
* $Revision: 13419 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
#ifndef __GECODE_DRIVER_HH__
39
#define __GECODE_DRIVER_HH__
40
41
#include <
gecode/minimodel.hh
>
42
#include <
gecode/search.hh
>
43
#ifdef GECODE_HAS_GIST
44
#include <
gecode/gist.hh
>
45
#endif
46
47
/*
48
* Configure linking
49
*
50
*/
51
#if !defined(GECODE_STATIC_LIBS) && \
52
(defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
53
54
#ifdef GECODE_BUILD_DRIVER
55
#define GECODE_DRIVER_EXPORT __declspec( dllexport )
56
#else
57
#define GECODE_DRIVER_EXPORT __declspec( dllimport )
58
#endif
59
60
#else
61
62
#ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
63
#define GECODE_DRIVER_EXPORT __attribute__ ((visibility("default")))
64
#else
65
#define GECODE_DRIVER_EXPORT
66
#endif
67
68
#endif
69
70
// Configure auto-linking
71
#ifndef GECODE_BUILD_DRIVER
72
#define GECODE_LIBRARY_NAME "Driver"
73
#include <
gecode/support/auto-link.hpp
>
74
#endif
75
86
namespace
Gecode {
87
88
98
enum
ScriptMode
{
99
SM_SOLUTION
,
100
SM_TIME
,
101
SM_STAT
,
102
SM_GIST
103
};
104
109
enum
RestartMode
{
110
RM_NONE
,
111
RM_CONSTANT
,
112
RM_LINEAR
,
113
RM_LUBY
,
114
RM_GEOMETRIC
115
};
116
117
class
BaseOptions;
118
119
namespace
Driver {
124
class
GECODE_DRIVER_EXPORT
BaseOption
{
125
friend
class
Gecode::BaseOptions
;
126
protected
:
127
const
char
*
opt
;
128
const
char
*
exp
;
129
BaseOption
* next;
130
131
char
* argument(
int
argc,
char
* argv[])
const
;
132
public
:
134
BaseOption
(
const
char
* o,
const
char
* e);
136
virtual
int
parse
(
int
argc,
char
* argv[]) = 0;
138
virtual
void
help
(
void
) = 0;
140
virtual
~
BaseOption
(
void
);
142
static
char
* strdup(
const
char
* s);
144
static
void
strdel(
const
char
* s);
145
};
146
151
class
GECODE_DRIVER_EXPORT
StringValueOption
:
public
BaseOption
{
152
protected
:
153
const
char
*
cur
;
154
public
:
156
StringValueOption
(
const
char
* o,
const
char
* e,
const
char
*
v
=NULL);
158
void
value(
const
char
*
v
);
160
const
char
* value(
void
)
const
;
162
virtual
int
parse
(
int
argc,
char
* argv[]);
164
virtual
void
help(
void
);
166
virtual
~
StringValueOption
(
void
);
167
};
168
169
174
class
GECODE_DRIVER_EXPORT
StringOption
:
public
BaseOption
{
175
protected
:
177
class
Value
{
178
public
:
179
int
val
;
180
const
char
*
opt
;
181
const
char
*
help
;
182
Value
*
next
;
183
};
184
int
cur
;
185
Value
*
fst
;
186
Value
*
lst
;
187
public
:
189
StringOption
(
const
char
* o,
const
char
* e,
int
v
=0);
191
void
value(
int
v
);
193
int
value(
void
)
const
;
195
void
add(
int
v
,
const
char
* o,
const
char
* h = NULL);
197
virtual
int
parse
(
int
argc,
char
* argv[]);
199
virtual
void
help(
void
);
201
virtual
~
StringOption
(
void
);
202
};
203
204
209
class
GECODE_DRIVER_EXPORT
IntOption
:
public
BaseOption
{
210
protected
:
211
int
cur
;
212
public
:
214
IntOption
(
const
char
* o,
const
char
* e,
int
v
=0);
216
void
value(
int
v
);
218
int
value(
void
)
const
;
220
virtual
int
parse
(
int
argc,
char
* argv[]);
222
virtual
void
help(
void
);
223
};
224
229
class
GECODE_DRIVER_EXPORT
UnsignedIntOption
:
public
BaseOption
{
230
protected
:
231
unsigned
int
cur
;
232
public
:
234
UnsignedIntOption
(
const
char
* o,
const
char
* e,
unsigned
int
v
=0);
236
void
value(
unsigned
int
v
);
238
unsigned
int
value(
void
)
const
;
240
virtual
int
parse
(
int
argc,
char
* argv[]);
242
virtual
void
help(
void
);
243
};
244
249
class
GECODE_DRIVER_EXPORT
DoubleOption
:
public
BaseOption
{
250
protected
:
251
double
cur
;
252
public
:
254
DoubleOption
(
const
char
* o,
const
char
* e,
double
v
=0);
256
void
value(
double
v
);
258
double
value(
void
)
const
;
260
virtual
int
parse
(
int
argc,
char
* argv[]);
262
virtual
void
help(
void
);
263
};
264
269
class
GECODE_DRIVER_EXPORT
BoolOption
:
public
BaseOption
{
270
protected
:
271
bool
cur
;
272
public
:
274
BoolOption
(
const
char
* o,
const
char
* e,
bool
v
=
false
);
276
void
value(
bool
v
);
278
bool
value(
void
)
const
;
280
virtual
int
parse
(
int
argc,
char
* argv[]);
282
virtual
void
help(
void
);
283
};
284
285
}
286
291
class
GECODE_DRIVER_EXPORT
BaseOptions
{
292
protected
:
293
Driver::BaseOption
*
fst
;
294
Driver::BaseOption
*
lst
;
295
const
char
*
_name
;
296
public
:
298
BaseOptions
(
const
char
* s);
300
virtual
void
help(
void
);
301
303
void
add(
Driver::BaseOption
& o);
311
void
parse
(
int
& argc,
char
* argv[]);
312
314
const
char
* name(
void
)
const
;
316
void
name(
const
char
*);
317
319
virtual
~
BaseOptions
(
void
);
320
};
321
326
class
GECODE_DRIVER_EXPORT
Options
:
public
BaseOptions
{
327
protected
:
329
330
Driver::StringOption
_model
;
331
Driver::StringOption
_symmetry
;
332
Driver::StringOption
_propagation
;
333
Driver::StringOption
_icl
;
334
Driver::StringOption
_branching
;
335
Driver::DoubleOption
_decay
;
336
337
339
340
Driver::StringOption
_search
;
341
Driver::UnsignedIntOption
_solutions
;
342
Driver::DoubleOption
_threads
;
343
Driver::UnsignedIntOption
_c_d
;
344
Driver::UnsignedIntOption
_a_d
;
345
Driver::UnsignedIntOption
_node
;
346
Driver::UnsignedIntOption
_fail
;
347
Driver::UnsignedIntOption
_time
;
348
Driver::StringOption
_restart
;
349
Driver::DoubleOption
_r_base
;
350
Driver::UnsignedIntOption
_r_scale
;
351
Driver::BoolOption
_interrupt
;
352
353
355
356
Driver::StringOption
_mode
;
357
Driver::UnsignedIntOption
_samples
;
358
Driver::UnsignedIntOption
_iterations
;
359
Driver::BoolOption
_print_last
;
360
Driver::StringValueOption
_out_file
;
361
Driver::StringValueOption
_log_file
;
362
363
364
public
:
366
Options
(
const
char
* s);
367
369
370
371
void
model(
int
v
);
373
void
model(
int
v
,
const
char
* o,
const
char
* h = NULL);
375
int
model(
void
)
const
;
376
378
void
symmetry(
int
v
);
380
void
symmetry(
int
v
,
const
char
* o,
const
char
* h = NULL);
382
int
symmetry(
void
)
const
;
383
385
void
propagation(
int
v
);
387
void
propagation(
int
v
,
const
char
* o,
const
char
* h = NULL);
389
int
propagation(
void
)
const
;
390
392
void
icl(
IntConLevel
i
);
394
IntConLevel
icl(
void
)
const
;
395
397
void
branching(
int
v
);
399
void
branching(
int
v
,
const
char
* o,
const
char
* h = NULL);
401
int
branching(
void
)
const
;
402
404
void
decay(
double
d
);
406
double
decay(
void
)
const
;
408
410
411
412
void
search(
int
v
);
414
void
search(
int
v
,
const
char
* o,
const
char
* h = NULL);
416
int
search(
void
)
const
;
417
419
void
solutions
(
unsigned
int
n
);
421
unsigned
int
solutions
(
void
)
const
;
422
424
void
threads
(
double
n
);
426
double
threads
(
void
)
const
;
427
429
void
c_d
(
unsigned
int
d
);
431
unsigned
int
c_d
(
void
)
const
;
432
434
void
a_d
(
unsigned
int
d
);
436
unsigned
int
a_d
(
void
)
const
;
437
439
void
node(
unsigned
int
n
);
441
unsigned
int
node(
void
)
const
;
442
444
void
fail(
unsigned
int
n
);
446
unsigned
int
fail(
void
)
const
;
447
449
void
time(
unsigned
int
t
);
451
unsigned
int
time(
void
)
const
;
452
454
void
restart(
RestartMode
r
);
456
RestartMode
restart(
void
)
const
;
457
459
void
restart_base(
double
base);
461
double
restart_base(
void
)
const
;
462
464
void
restart_scale(
unsigned
int
scale);
466
unsigned
int
restart_scale(
void
)
const
;
467
469
void
interrupt(
bool
b
);
471
bool
interrupt(
void
)
const
;
473
475
476
477
void
mode(
ScriptMode
em);
479
ScriptMode
mode(
void
)
const
;
480
482
void
samples(
unsigned
int
s);
484
unsigned
int
samples(
void
)
const
;
485
487
void
iterations(
unsigned
int
i
);
489
unsigned
int
iterations(
void
)
const
;
490
492
void
print_last(
bool
p
);
494
bool
print_last(
void
)
const
;
495
497
void
out_file(
const
char
* f);
499
const
char
* out_file(
void
)
const
;
500
502
void
log_file(
const
char
* f);
504
const
char
* log_file(
void
)
const
;
506
507
#ifdef GECODE_HAS_GIST
508
509
class
_I {
510
private
:
512
Support::DynamicArray<Gist::Inspector*,Heap>
_click;
514
unsigned
int
n_click;
516
Support::DynamicArray<Gist::Inspector*,Heap>
_solution;
518
unsigned
int
n_solution;
520
Support::DynamicArray<Gist::Inspector*,Heap>
_move;
522
unsigned
int
n_move;
524
Support::DynamicArray<Gist::Comparator*,Heap>
_compare;
526
unsigned
int
n_compare;
527
public
:
529
_I(
void
);
531
void
click(
Gist::Inspector
*
i
);
533
void
solution(
Gist::Inspector
*
i
);
535
void
move(
Gist::Inspector
*
i
);
537
void
compare
(
Gist::Comparator
*
i
);
538
540
Gist::Inspector
* click(
unsigned
int
i
)
const
;
542
Gist::Inspector
* solution(
unsigned
int
i
)
const
;
544
Gist::Inspector
* move(
unsigned
int
i
)
const
;
546
Gist::Comparator
*
compare
(
unsigned
int
i
)
const
;
547
} inspect;
548
#endif
549
};
550
555
class
GECODE_DRIVER_EXPORT
SizeOptions
:
public
Options
{
556
protected
:
557
unsigned
int
_size
;
558
public
:
560
SizeOptions
(
const
char
* s);
562
virtual
void
help(
void
);
564
void
parse
(
int
& argc,
char
* argv[]);
565
567
void
size
(
unsigned
int
s);
569
unsigned
int
size
(
void
)
const
;
570
};
571
576
class
GECODE_DRIVER_EXPORT
InstanceOptions
:
public
Options
{
577
protected
:
578
const
char
*
_inst
;
579
public
:
581
InstanceOptions
(
const
char
* s);
583
virtual
void
help(
void
);
585
void
parse
(
int
& argc,
char
* argv[]);
586
588
void
instance(
const
char
* s);
590
const
char
* instance(
void
)
const
;
592
~
InstanceOptions
(
void
);
593
};
594
595
}
596
597
#include <
gecode/driver/options.hpp
>
598
599
namespace
Gecode {
600
601
namespace
Driver {
609
template
<
class
BaseSpace>
610
class
ScriptBase
:
public
BaseSpace {
611
public
:
613
ScriptBase
(
void
) {}
615
ScriptBase
(
bool
share,
ScriptBase
& e) : BaseSpace(share,e) {}
617
virtual
void
print
(std::ostream& os)
const
{ (void) os; }
619
virtual
void
compare
(
const
Space
&, std::ostream& os)
const
{
620
(void) os;
621
}
623
static
std::ostream&
select_ostream
(
const
char
* name, std::ofstream& ofs);
633
template
<
class
Script,
template
<
class
>
class
Engine,
class
Options
>
634
static
void
run
(
const
Options
&
opt
,
Script
* s=NULL);
635
private
:
636
template
<
class
Script,
template
<
class
>
class
Engine,
class
Options
,
637
template
<
template
<
class
>
class
,
class
>
class
Meta>
638
static void runMeta(const
Options
&
opt
,
Script
* s);
640
explicit
ScriptBase
(
ScriptBase
& e);
641
};
642
}
643
653
typedef
Driver::ScriptBase<Space>
Script
;
658
typedef
Driver::ScriptBase<MinimizeSpace>
MinimizeScript
;
663
typedef
Driver::ScriptBase<MaximizeSpace>
MaximizeScript
;
664
665
}
666
667
#include <
gecode/driver/script.hpp
>
668
669
#endif
670
671
// STATISTICS: driver-any