Generated on Sat Feb 7 2015 02:01:10 for Gecode by doxygen 1.8.9.1
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: 2013-07-08 14:22:40 +0200 (Mon, 08 Jul 2013) $ by $Author: schulte $
11  * $Revision: 13820 $
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:
75  x(*this, opt.size(), 0, opt.size()-1),
76  d(*this, opt.size()-1, 1, opt.size()-1) {
77  const int n = x.size();
78 
79  // Set up variables for distance
80  for (int i=0; i<n-1; i++)
81  rel(*this, d[i] == abs(x[i+1]-x[i]), opt.icl());
82 
83  distinct(*this, x, opt.icl());
84  distinct(*this, d, opt.icl());
85 
86  // Break mirror symmetry
87  rel(*this, x[0], IRT_LE, x[1]);
88  // Break symmetry of dual solution
89  rel(*this, d[0], IRT_GR, d[n-2]);
90 
92  }
94  AllInterval(bool share, AllInterval& s)
95  : Script(share, s) {
96  x.update(*this, share, s.x);
97  d.update(*this, share, s.d);
98  }
100  virtual Space*
101  copy(bool share) {
102  return new AllInterval(share, *this);
103  }
105  virtual void
106  print(std::ostream& os) const {
107  const int n = x.size();
108  os << "\tx[" << n << "] = {";
109  for (int i = 0; i < n-1; i++)
110  os << x[i] << "(" << d[i] << "),";
111  os << x[n-1] << "}" << std::endl;
112  }
113 };
114 
115 
119 int
120 main(int argc, char* argv[]){
121  SizeOptions opt("AllInterval");
122  opt.size(1000);
123  opt.iterations(5);
124  opt.icl(ICL_BND);
125  opt.parse(argc, argv);
126  if (opt.size() < 2) {
127  std::cerr << "size must be at least 2!" << std::endl;
128  return -1;
129  }
130  Script::run<AllInterval,DFS,SizeOptions>(opt);
131  return 0;
132 }
133 
134 // STATISTICS: example-any
135 
void size(unsigned int s)
Set default size.
Definition: options.hpp:467
Options for scripts with additional size parameter
Definition: driver.hh:567
virtual Space * copy(bool share)
Copy during cloning.
AllInterval(bool share, AllInterval &s)
Constructor for cloning e.
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition: arithmetic.cpp:49
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Definition: options.cpp:435
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
Definition: var.hpp:212
Integer variable array.
Definition: int.hh:741
int main(int argc, char *argv[])
Main-function.
Greater ( )
Definition: int.hh:909
Computation spaces.
Definition: core.hpp:1362
Parametric base-class for scripts.
Definition: driver.hh:622
void iterations(unsigned int i)
Set default number of iterations.
Definition: options.hpp:385
Gecode::IntSet d(v, 7)
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
Definition: array.hpp:1072
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Options opt
The options.
Definition: test.cpp:101
unsigned int size(I &i)
Size of all ranges of range iterator i.
Less ( )
Definition: int.hh:907
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
void distinct(Home home, const IntVarArgs &x, IntConLevel icl)
Post propagator for for all .
Definition: distinct.cpp:47
Bounds propagation or consistency.
Definition: int.hh:939
IntValBranch INT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
Definition: val.hpp:88
Gecode toplevel namespace
Example: All-interval series
BrancherHandle 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
AllInterval(const SizeOptions &opt)
Actual model.
virtual void print(std::ostream &os) const
Print solution.
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:985
void icl(IntConLevel i)
Set default integer consistency level.
Definition: options.hpp:194