main page
modules
namespaces
classes
files
Gecode home
Generated on Thu Feb 14 2013 20:59:21 for Gecode by
doxygen
1.8.3.1
examples
all-interval.cpp
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, 2006
8
*
9
* Last modified:
10
* $Date: 2010-10-07 20:52:01 +1100 (Thu, 07 Oct 2010) $ by $Author: schulte $
11
* $Revision: 11473 $
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
#include <
gecode/driver.hh
>
39
#include <
gecode/int.hh
>
40
#include <
gecode/minimodel.hh
>
41
42
#include <cstdlib>
43
44
using namespace
Gecode;
45
66
class
AllInterval
:
public
Script
{
67
private
:
69
IntVarArray
x;
70
public
:
72
AllInterval
(
const
SizeOptions
&
opt
) :
73
x(*this, opt.
size
(), 0, opt.
size
() - 1) {
74
const
int
n = x.size();
75
76
IntVarArgs
d
(n-1);
77
78
// Set up variables for distance
79
for
(
int
i
=0;
i
<n-1;
i
++)
80
d[
i
] =
expr
(*
this
,
abs
(x[
i
+1]-x[
i
]), opt.
icl
());
81
82
// Constrain them to be between 1 and n-1
83
dom
(*
this
, d, 1, n-1);
84
85
distinct
(*
this
, x, opt.
icl
());
86
distinct
(*
this
, d, opt.
icl
());
87
88
// Break mirror symmetry
89
rel
(*
this
, x[0],
IRT_LE
, x[1]);
90
// Break symmetry of dual solution
91
rel
(*
this
, d[0],
IRT_GR
, d[n-2]);
92
93
branch
(*
this
, x,
INT_VAR_SIZE_MIN
,
INT_VAL_SPLIT_MIN
);
94
}
96
AllInterval
(
bool
share,
AllInterval
& e)
97
:
Script
(share, e) {
98
x.update(*
this
, share, e.x);
99
}
101
virtual
Space
*
102
copy
(
bool
share) {
103
return
new
AllInterval
(share, *
this
);
104
}
106
virtual
void
107
print
(std::ostream& os)
const
{
108
const
int
n = x.size();
109
os <<
"\tx["
<< n <<
"] = {"
;
110
for
(
int
i
= 0;
i
< n-1;
i
++)
111
os << x[
i
] <<
"("
<<
abs
(x[
i
+1].val()-x[
i
].val()) <<
"),"
;
112
os << x[n-1] <<
"}"
<< std::endl;
113
}
114
};
115
116
120
int
121
main
(
int
argc,
char
* argv[]){
122
SizeOptions
opt
(
"AllInterval"
);
123
opt.
size
(1000);
124
opt.
iterations
(5);
125
opt.
icl
(
ICL_BND
);
126
opt.
parse
(argc, argv);
127
if
(opt.
size
() < 2) {
128
std::cerr <<
"size must be at least 2!"
<< std::endl;
129
return
-1;
130
}
131
Script::run<AllInterval,DFS,SizeOptions>(
opt
);
132
return
0;
133
}
134
135
// STATISTICS: example-any
136