main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
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: 2015-09-11 16:29:45 +0200 (Fri, 11 Sep 2015) $ by $Author: schulte $
11
* $Revision: 14672 $
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
;
71
IntVarArray
d
;
72
public
:
74
AllInterval
(
const
SizeOptions
&
opt
) :
75
Script
(
opt
),
76
x
(*this,
opt
.
size
(), 0,
opt
.
size
()-1),
77
d
(*this,
opt
.
size
()-1, 1,
opt
.
size
()-1) {
78
const
int
n
=
x
.size();
79
80
// Set up variables for distance
81
for
(
int
i
=0;
i
<
n
-1;
i
++)
82
rel
(*
this
,
d
[
i
] ==
abs
(
x
[
i
+1]-
x
[
i
]),
opt
.ipl());
83
84
distinct
(*
this
,
x
,
opt
.ipl());
85
distinct
(*
this
,
d
,
opt
.ipl());
86
87
// Break mirror symmetry
88
rel
(*
this
,
x
[0],
IRT_LE
,
x
[1]);
89
// Break symmetry of dual solution
90
rel
(*
this
,
d
[0],
IRT_GR
,
d
[
n
-2]);
91
92
branch
(*
this
,
x
,
INT_VAR_SIZE_MIN
(),
INT_VAL_SPLIT_MIN
());
93
}
95
AllInterval
(
bool
share,
AllInterval
& s)
96
:
Script
(share, s) {
97
x
.
update
(*
this
, share, s.x);
98
d
.
update
(*
this
, share, s.d);
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
] <<
"("
<<
d
[
i
] <<
"),"
;
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
.
ipl
(
IPL_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
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
minimodel.hh
AllInterval::main
int main(int argc, char *argv[])
Main-function.
Definition:
all-interval.cpp:121
int.hh
AllInterval::print
virtual void print(std::ostream &os) const
Print solution.
Definition:
all-interval.cpp:107
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:78
Gecode::IRT_LE
@ IRT_LE
Less ( )
Definition:
int.hh:910
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Options::ipl
void ipl(IntPropLevel i)
Set default integer propagation level.
Definition:
options.hpp:220
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::branch
void branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.
Definition:
branch.cpp:43
Gecode::Options::iterations
void iterations(unsigned int i)
Set default number of iterations.
Definition:
options.hpp:465
AllInterval::AllInterval
AllInterval(bool share, AllInterval &s)
Constructor for cloning e.
Definition:
all-interval.cpp:95
Gecode::VarImpVar::update
void update(Space &home, bool share, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
Definition:
var.hpp:128
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:744
driver.hh
Gecode
Gecode toplevel namespace
Test::opt
Options opt
The options.
Definition:
test.cpp:101
Gecode::Driver::ScriptBase
Parametric base-class for scripts.
Definition:
driver.hh:703
Gecode::SharedHandle::update
void update(Space &home, bool share, SharedHandle &sh)
Updating during cloning.
Definition:
core.hpp:3127
Gecode::BaseOptions::parse
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Definition:
options.cpp:510
AllInterval
Example: All-interval series
Definition:
all-interval.cpp:66
Gecode::IPL_BND
@ IPL_BND
Bounds propagation.
Definition:
int.hh:959
Gecode::abs
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
arithmetic.cpp:45
Gecode::INT_VAR_SIZE_MIN
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
Definition:
var.hpp:210
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition:
rel.cpp:47
Test::Int::Distinct::d
Gecode::IntSet d(v, 7)
AllInterval::AllInterval
AllInterval(const SizeOptions &opt)
Actual model.
Definition:
all-interval.cpp:74
Gecode::distinct
void distinct(Home home, const IntVarArgs &x, IntPropLevel ipl)
Post propagator for for all .
Definition:
distinct.cpp:50
Gecode::INT_VAL_SPLIT_MIN
IntValBranch INT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
Definition:
val.hpp:79
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
AllInterval::copy
virtual Space * copy(bool share)
Copy during cloning.
Definition:
all-interval.cpp:102
Gecode::IRT_GR
@ IRT_GR
Greater ( )
Definition:
int.hh:912
Gecode::SizeOptions
Options for scripts with additional size parameter
Definition:
driver.hh:649