Generated on Mon May 10 06:46:32 2010 for Gecode by doxygen 1.6.3

int.hh

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  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2005
00009  *     Mikael Lagerkvist, 2006
00010  *
00011  *  Last modified:
00012  *     $Date: 2010-04-08 12:35:31 +0200 (Thu, 08 Apr 2010) $ by $Author: schulte $
00013  *     $Revision: 10684 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 #ifndef __GECODE_TEST_INT_HH__
00041 #define __GECODE_TEST_INT_HH__
00042 
00043 #include "test/test.hh"
00044 
00045 #include <gecode/int.hh>
00046 
00047 namespace Test {
00048 
00050   namespace Int {
00051 
00062 
00063     class Assignment {
00064     protected:
00065       int n;            
00066       Gecode::IntSet d; 
00067     public:
00069       Assignment(int n0, const Gecode::IntSet& d0);
00071       virtual bool operator()(void) const = 0;
00073       virtual void operator++(void) = 0;
00075       virtual int operator[](int i) const = 0;
00077       int size(void) const;
00079       virtual ~Assignment(void);
00080     };
00081 
00083     class CpltAssignment : public Assignment {
00084     protected:
00085       Gecode::IntSetValues* dsv; 
00086     public:
00088       CpltAssignment(int n, const Gecode::IntSet& d);
00090       virtual bool operator()(void) const;
00092       virtual void operator++(void);
00094       virtual int operator[](int i) const;
00096       virtual ~CpltAssignment(void);
00097     };
00098 
00100     class RandomAssignment : public Assignment {
00101     protected:
00102       int* vals; 
00103       int  a;    
00104 
00105       int randval(void);
00106     public:
00108       RandomAssignment(int n, const Gecode::IntSet& d, int a);
00110       virtual bool operator()(void) const;
00112       virtual void operator++(void);
00114       virtual int operator[](int i) const;
00116       virtual ~RandomAssignment(void);
00117     };
00118 
00120     enum ConTestLevel {
00121       CTL_NONE,     
00122       CTL_DOMAIN,   
00123       CTL_BOUNDS_D, 
00124       CTL_BOUNDS_Z, 
00125     };
00126 
00127     class Test;
00128 
00130     class TestSpace : public Gecode::Space {
00131     public:
00133       Gecode::IntSet d;
00135       Gecode::IntVarArray x;
00137       Gecode::BoolVar b;
00139       bool reified;
00141       Test* test;
00142 
00151       TestSpace(int n, Gecode::IntSet& d0, bool r, Test* t, bool log=true);
00153       TestSpace(bool share, TestSpace& s);
00155       virtual Gecode::Space* copy(bool share);
00157       bool assigned(void) const;
00159       void post(void);
00161       bool failed(void);
00163       void rel(int i, Gecode::IntRelType irt, int n);
00165       void rel(bool sol);
00167       void assign(const Assignment& a, bool skip=false);
00169       void bound(void);
00175       void prune(int i, bool bounds_only);
00177       void prune(void);
00179       bool prune(const Assignment& a);
00180     };
00181 
00186     class Test : public Base {
00187     protected:
00189       int arity;
00191       Gecode::IntSet dom;
00193       bool reified;
00195       Gecode::IntConLevel icl;
00197       ConTestLevel contest;
00199       bool testsearch;
00200 
00201     public:
00210       Test(const std::string& s, int a, const Gecode::IntSet& d, bool r=false,
00211            Gecode::IntConLevel i=Gecode::ICL_DEF);
00220       Test(const std::string& s, int a, int min, int max, bool r=false,
00221            Gecode::IntConLevel i=Gecode::ICL_DEF);
00223       virtual Assignment* assignment(void) const;
00225       virtual bool solution(const Assignment&) const = 0;
00227       virtual bool ignore(const Assignment&) const;
00229       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) = 0;
00231       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00232                         Gecode::BoolVar b);
00234       virtual bool run(void);
00236 
00237 
00238       static std::string str(Gecode::ExtensionalPropKind epk);
00240       static std::string str(Gecode::IntConLevel icl);
00242       static std::string str(Gecode::IntRelType irl);
00244       static std::string str(Gecode::BoolOpType bot);
00246       static std::string str(int i);
00248       static std::string str(const Gecode::IntArgs& i);
00250 
00251 
00252 
00253       template<class T> static bool cmp(T x, Gecode::IntRelType r, T y);
00255     };
00257 
00259     class IntConLevels {
00260     private:
00262       static const Gecode::IntConLevel icls[3];
00264       int i;
00265     public:
00267       IntConLevels(void);
00269       bool operator()(void) const;
00271       void operator++(void);
00273       Gecode::IntConLevel icl(void) const;
00274     };
00275 
00277     class IntRelTypes {
00278     private:
00280       static const Gecode::IntRelType irts[6];
00282       int i;
00283     public:
00285       IntRelTypes(void);
00287       void reset(void);
00289       bool operator()(void) const;
00291       void operator++(void);
00293       Gecode::IntRelType irt(void) const;
00294     };
00295 
00297     class BoolOpTypes {
00298     private:
00300       static const Gecode::BoolOpType bots[5];
00302       int i;
00303     public:
00305       BoolOpTypes(void);
00307       bool operator()(void) const;
00309       void operator++(void);
00311       Gecode::BoolOpType bot(void) const;
00312     };
00313 
00314   }
00315 }
00316 
00321 std::ostream& operator<<(std::ostream& os, const Test::Int::Assignment& a);
00322 
00323 #include "test/int.hpp"
00324 
00325 #endif
00326 
00327 // STATISTICS: test-int
00328