Generated on Fri Oct 19 11:24:47 2018 for Gecode by doxygen 1.6.3

all-interval.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2006
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <gecode/driver.hh>
00035 #include <gecode/int.hh>
00036 #include <gecode/minimodel.hh>
00037 
00038 #include <cstdlib>
00039 
00040 using namespace Gecode;
00041 
00062 class AllInterval : public Script {
00063 private:
00065   IntVarArray x;
00067   IntVarArray d;
00068 public:
00070   AllInterval(const SizeOptions& opt) :
00071     Script(opt),
00072     x(*this, opt.size(), 0, opt.size()-1),
00073     d(*this, opt.size()-1, 1, opt.size()-1) {
00074     const int n = x.size();
00075 
00076     // Set up variables for distance
00077     for (int i=0; i<n-1; i++)
00078       rel(*this, d[i] == abs(x[i+1]-x[i]), opt.ipl());
00079 
00080     distinct(*this, x, opt.ipl());
00081     distinct(*this, d, opt.ipl());
00082 
00083     // Break mirror symmetry
00084     rel(*this, x[0], IRT_LE, x[1]);
00085     // Break symmetry of dual solution
00086     rel(*this, d[0], IRT_GR, d[n-2]);
00087 
00088     branch(*this, x, INT_VAR_SIZE_MIN(), INT_VAL_SPLIT_MIN());
00089   }
00091   AllInterval(AllInterval& s)
00092     : Script(s) {
00093     x.update(*this, s.x);
00094     d.update(*this, s.d);
00095   }
00097   virtual Space*
00098   copy(void) {
00099     return new AllInterval(*this);
00100   }
00102   virtual void
00103   print(std::ostream& os) const {
00104     const int n = x.size();
00105     os << "\tx[" << n << "] = {";
00106     for (int i = 0; i < n-1; i++)
00107       os << x[i] << "(" << d[i] << "),";
00108     os << x[n-1] << "}" << std::endl;
00109   }
00110 };
00111 
00112 
00116 int
00117 main(int argc, char* argv[]){
00118   SizeOptions opt("AllInterval");
00119   opt.size(1000);
00120   opt.iterations(5);
00121   opt.ipl(IPL_BND);
00122   opt.parse(argc, argv);
00123   if (opt.size() < 2) {
00124     std::cerr << "size must be at least 2!" << std::endl;
00125     return -1;
00126   }
00127   Script::run<AllInterval,DFS,SizeOptions>(opt);
00128   return 0;
00129 }
00130 
00131 // STATISTICS: example-any
00132