Generated on Thu Apr 11 13:59:12 2019 for Gecode by doxygen 1.6.3

unshare.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, 2008
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 "test/int.hh"
00035 
00036 #include <gecode/minimodel.hh>
00037 
00038 namespace Test { namespace Int {
00039 
00041    namespace Unshare {
00042 
00048 
00049      class Int : public Test {
00050      public:
00052        Int(Gecode::IntPropLevel ipl)
00053          : Test("Unshare::Int::"+str(ipl),9,-1,1,false,ipl) {}
00055        virtual bool solution(const Assignment& x) const {
00056          return ((x[0] == x[3]) &&
00057                  (x[1] == x[4]) && (x[1] == x[6]) &&
00058                  (x[2] == x[5]) && (x[2] == x[7]) && (x[2] == x[8]));
00059        }
00061        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00062          using namespace Gecode;
00063          IntVarArgs y(6);
00064          y[0]=x[0]; y[1]=y[3]=x[1]; y[2]=y[4]=y[5]=x[2];
00065          unshare(home, y, ipl);
00066          for (int i=0; i<6; i++)
00067            rel(home, y[i], IRT_EQ, x[3+i], IPL_DOM);
00068        }
00069      };
00070 
00072      class Bool : public Test {
00073      public:
00075        Bool(void)
00076          : Test("Unshare::Bool",9,0,1,false) {}
00078        virtual bool solution(const Assignment& x) const {
00079          return ((x[0] == x[3]) &&
00080                  (x[1] == x[4]) && (x[1] == x[6]) &&
00081                  (x[2] == x[5]) && (x[2] == x[7]) && (x[2] == x[8]));
00082        }
00084        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00085          using namespace Gecode;
00086          BoolVarArgs y(6);
00087          y[0]=channel(home,x[0]);
00088          y[1]=y[3]=channel(home,x[1]);
00089          y[2]=y[4]=y[5]=channel(home,x[2]);
00090          unshare(home, y);
00091          for (int i=0; i<6; i++)
00092            rel(home, y[i], IRT_EQ, channel(home,x[3+i]));
00093        }
00094      };
00095 
00097      class Failed : public Test {
00098      public:
00100        Failed(void)
00101          : Test("Unshare::Failed",1,-1,1) {}
00103        virtual bool solution(const Assignment& x) const {
00104          (void) x;
00105          return false;
00106        }
00108        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00109          using namespace Gecode;
00110          home.fail();
00111          IntVarArgs y(2);
00112          y[0]=x[0]; y[1]=x[0];
00113          unshare(home, y);
00114          REG r(1);
00115          extensional(home, y, r);
00116        }
00117      };
00118 
00119      Int i_bnd(Gecode::IPL_BND);
00120      Int i_dom(Gecode::IPL_DOM);
00121 
00122      Bool b;
00123 
00124      Failed f;
00126 
00127    }
00128 }}
00129 
00130 // STATISTICS: test-int