Generated on Mon Aug 25 11:35:45 2008 for Gecode by doxygen 1.5.6

mm-rel.cc

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, 2008
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-02-29 01:09:17 +0100 (Fri, 29 Feb 2008) $ by $Author: schulte $
00011  *     $Revision: 6355 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include "test/int.hh"
00039 
00040 #include "gecode/minimodel.hh"
00041 
00042 namespace Test { namespace Int {
00043 
00045    namespace MiniModel {
00046    
00052 
00053      class IntLex : public Test {
00054      protected:
00056        Gecode::IntRelType irt;
00057      public:
00059        IntLex(Gecode::IntRelType irt0)
00060          : Test("MiniModel::Lex::Int::"+str(irt0),6,-2,2), irt(irt0) {}
00062        virtual bool solution(const Assignment& x) const {
00063          int n=x.size() >> 1;
00064          for (int i=0; i<n; i++)
00065            if (x[i] != x[n+i])
00066              return cmp(x[i],irt,x[n+i]);
00067          return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) || 
00068                  (irt == Gecode::IRT_EQ));
00069          GECODE_NEVER;
00070          return false;
00071        }
00073        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00074          using namespace Gecode;
00075          int n=x.size() >> 1;
00076          IntVarArgs y(n); IntVarArgs z(n);
00077          for (int i=0; i<n; i++) {
00078            y[i]=x[i]; z[i]=x[n+i];
00079          }
00080          lex(home, y, irt, z);
00081        }
00082      };
00083    
00085      class BoolLex : public Test {
00086      protected:
00088        Gecode::IntRelType irt;
00089      public:
00091        BoolLex(Gecode::IntRelType irt0)
00092          : Test("MiniModel::Lex::Bool::"+str(irt0),10,0,1), irt(irt0) {}
00094        virtual bool solution(const Assignment& x) const {
00095          int n=x.size() >> 1;
00096          for (int i=0; i<n; i++)
00097            if (x[i] != x[n+i])
00098              return cmp(x[i],irt,x[n+i]);
00099          return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) || 
00100                  (irt == Gecode::IRT_EQ));
00101          GECODE_NEVER;
00102          return false;
00103        }
00105        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00106          using namespace Gecode;
00107          int n=x.size() >> 1;
00108          BoolVarArgs y(n); BoolVarArgs z(n);
00109          for (int i=0; i<n; i++) {
00110            y[i]=channel(home,x[i]); z[i]=channel(home,x[n+i]);
00111          }
00112          lex(home, y, irt, z);
00113        }
00114      };
00115 
00117      class Create {
00118      public:
00120        Create(void) {
00121          using namespace Gecode;
00122          for (IntRelTypes irts; irts(); ++irts) {
00123            (void) new IntLex(irts.irt());
00124            (void) new BoolLex(irts.irt());
00125          }      
00126        }
00127      };
00128      
00129      Create c;
00131 
00132    }
00133 
00134 }}
00135 
00136 // STATISTICS: test-minimodel