Generated on Fri Mar 20 15:55:56 2015 for Gecode by doxygen 1.6.3

float.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  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00007  *
00008  *  Copyright:
00009  *     Christian Schulte, 2005
00010  *     Mikael Lagerkvist, 2006
00011  *     Vincent Barichard, 2012
00012  *
00013  *  Last modified:
00014  *     $Date: 2013-02-04 22:41:43 +0100 (Mon, 04 Feb 2013) $ by $Author: schulte $
00015  *     $Revision: 13264 $
00016  *
00017  *  This file is part of Gecode, the generic constraint
00018  *  development environment:
00019  *     http://www.gecode.org
00020  *
00021  *  Permission is hereby granted, free of charge, to any person obtaining
00022  *  a copy of this software and associated documentation files (the
00023  *  "Software"), to deal in the Software without restriction, including
00024  *  without limitation the rights to use, copy, modify, merge, publish,
00025  *  distribute, sublicense, and/or sell copies of the Software, and to
00026  *  permit persons to whom the Software is furnished to do so, subject to
00027  *  the following conditions:
00028  *
00029  *  The above copyright notice and this permission notice shall be
00030  *  included in all copies or substantial portions of the Software.
00031  *
00032  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00033  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00034  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00035  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00036  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00037  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00038  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00039  *
00040  */
00041 
00042 #ifndef __GECODE_TEST_FLOAT_HH__
00043 #define __GECODE_TEST_FLOAT_HH__
00044 
00045 #include "test/test.hh"
00046 
00047 #include <gecode/float.hh>
00048 
00049 namespace Test {
00050 
00052   namespace Float {
00053 
00055     enum MaybeType {
00056       MT_FALSE = 0, //< Does hold
00057       MT_TRUE,      //< Does not hold
00058       MT_MAYBE      //< Might or might not hold
00059     };
00060     
00062     MaybeType operator &(MaybeType a, MaybeType b);
00063 
00065     enum AssignmentType {
00066       CPLT_ASSIGNMENT = 0,
00067       RANDOM_ASSIGNMENT,
00068       EXTEND_ASSIGNMENT
00069     };
00070     
00071     class Test;
00072     
00083 
00084     class Assignment {
00085     protected:
00086       int n;              
00087       Gecode::FloatVal d; 
00088     public:
00090       Assignment(int n0, const Gecode::FloatVal& d0);
00092       virtual bool operator()(void) const = 0;
00094       virtual void operator++(void) = 0;
00096       virtual Gecode::FloatVal operator[](int i) const = 0;
00098       virtual void set(int i, const Gecode::FloatVal& val) = 0;
00100       int size(void) const;
00102       virtual ~Assignment(void);
00103     };
00104 
00106     class CpltAssignment : public Assignment {
00107     protected:
00108       Gecode::FloatVal* dsv; 
00109       Gecode::FloatNum step; 
00110     public:
00112       CpltAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s);
00114       virtual bool operator()(void) const;
00116       virtual void operator++(void);
00118       virtual Gecode::FloatVal operator[](int i) const;
00120       virtual void set(int i, const Gecode::FloatVal& val);
00122       virtual ~CpltAssignment(void);
00123     };
00124 
00126     class ExtAssignment : public Assignment {
00127     protected:
00128       const Test* curPb;     
00129       Gecode::FloatVal* dsv; 
00130       Gecode::FloatNum step; 
00131     public:
00133       ExtAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s, const Test * pb);
00135       virtual bool operator()(void) const;
00137       virtual void operator++(void);
00139       virtual Gecode::FloatVal operator[](int i) const;
00141       virtual void set(int i, const Gecode::FloatVal& val);
00143       virtual ~ExtAssignment(void);
00144     };
00145     
00146     
00148     class RandomAssignment : public Assignment {
00149     protected:
00150       Gecode::FloatVal* vals; 
00151       int  a;                 
00152 
00153       Gecode::FloatNum randval(void);
00154     public:
00156       RandomAssignment(int n, const Gecode::FloatVal& d, int a);
00158       virtual bool operator()(void) const;
00160       virtual void operator++(void);
00162       virtual Gecode::FloatVal operator[](int i) const;
00164       virtual void set(int i, const Gecode::FloatVal& val);
00166       virtual ~RandomAssignment(void);
00167     };
00168 
00170     class TestSpace : public Gecode::Space {
00171     public:
00173       Gecode::FloatVal d;
00175       Gecode::FloatNum step;
00177       Gecode::FloatVarArray x;
00179       Gecode::Reify r;
00181       Test* test;
00183       bool reified;
00184 
00192       TestSpace(int n, Gecode::FloatVal& d, Gecode::FloatNum s, Test* t);
00200       TestSpace(int n, Gecode::FloatVal& d, Gecode::FloatNum s, Test* t, 
00201                 Gecode::ReifyMode rm);
00203       TestSpace(bool share, TestSpace& s);
00205       virtual Gecode::Space* copy(bool share);
00207       virtual void dropUntil(const Assignment& a);
00209       bool assigned(void) const;
00211       bool matchAssignment(const Assignment& a) const;
00213       void post(void);
00215       bool failed(void);
00217       void rel(int i, Gecode::FloatRelType frt, Gecode::FloatVal n);
00219       void rel(bool sol);
00223       void assign(const Assignment& a, MaybeType& sol, bool skip=false);
00225       void bound(void);
00229       Gecode::FloatNum cut(int* cutDirections);
00231       void prune(int i);
00233       void prune(void);
00235       bool prune(const Assignment& a, bool testfix);
00236     };
00237 
00242     class Test : public Base {
00243     protected:
00245       int arity;
00247       Gecode::FloatVal dom;
00249       Gecode::FloatNum step;
00251       AssignmentType assigmentType;
00253       bool reified;
00255       int rms;
00257       bool testsearch;
00259       bool testfix;
00261       bool testsubsumed;
00263 
00264 
00265       bool eqv(void) const;
00267       bool imp(void) const;
00269       bool pmi(void) const;
00271     public:
00279       Test(const std::string& s, int a, const Gecode::FloatVal& d, 
00280            Gecode::FloatNum st, AssignmentType at,
00281            bool r);
00289       Test(const std::string& s, int a, 
00290            Gecode::FloatNum min, Gecode::FloatNum max, 
00291            Gecode::FloatNum st, AssignmentType at,
00292            bool r);
00294       virtual Assignment* assignment(void) const;
00297       virtual bool extendAssignement(Assignment& a) const;
00299       virtual MaybeType solution(const Assignment&) const = 0;
00302       bool subsumed(const TestSpace& ts) const;
00304       virtual bool ignore(const Assignment& a) const;
00306       virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) = 0;
00308       virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00309                         Gecode::Reify r);
00311       virtual bool run(void);
00313 
00314 
00315       static std::string str(Gecode::FloatRelType frt);
00317       static std::string str(Gecode::FloatNum f);
00319       static std::string str(Gecode::FloatVal f);
00321       static std::string str(const Gecode::FloatValArgs& f);
00323 
00324 
00325 
00326       static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r, 
00327                            Gecode::FloatVal y);
00329       static MaybeType eq(Gecode::FloatVal x, Gecode::FloatVal y);
00331       bool flip(void);
00333     };
00335 
00337     class FloatRelTypes {
00338     private:
00340       static const Gecode::FloatRelType frts[6];
00342       int i;
00343     public:
00345       FloatRelTypes(void);
00347       void reset(void);
00349       bool operator()(void) const;
00351       void operator++(void);
00353       Gecode::FloatRelType frt(void) const;
00354     };
00355 
00356   }
00357 }
00358 
00363 std::ostream& operator<<(std::ostream& os, const Test::Float::Assignment& a);
00364 
00365 #include "test/float.hpp"
00366 
00367 #endif
00368 
00369 // STATISTICS: test-float
00370