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

construct.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 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/set.hh"
00035 
00036 using namespace Gecode;
00037 
00038 namespace Test { namespace Set {
00039 
00041   namespace Var {
00042 
00044     class Construct : public SetTest {
00045     public:
00047       Construct(void)
00048         : SetTest("Var::Construct",1,IntSet(0,0),false,0) {}
00050       virtual bool solution(const SetAssignment&) const {
00051         return true;
00052       }
00053       void con(Space& home, int glbMin, int glbMax,
00054                int lubMin, int lubMax,
00055                unsigned int minCard = 0,
00056                unsigned int maxCard = Gecode::Set::Limits::card,
00057                bool fail=true) {
00058         bool ok = false;
00059         try {
00060           SetVar x(home, glbMin, glbMax, lubMin, lubMax, minCard, maxCard);
00061           ok = true;
00062         } catch (Gecode::Set::VariableEmptyDomain&) {
00063           if (!fail) {
00064             home.fail();
00065             return;
00066           }
00067           ok = true;
00068         }
00069 
00070         if (ok) {
00071           try {
00072             SetVarArray xs(home, 1,
00073                            glbMin, glbMax, lubMin, lubMax, minCard, maxCard);
00074           } catch (Gecode::Set::VariableEmptyDomain&) {
00075             if (!fail) {
00076               home.fail();
00077               return;
00078             } else {
00079               return;
00080             }
00081           }
00082           if (fail) {
00083             home.fail();
00084           }
00085         }
00086       }
00087       void con(Space& home, const IntSet& glb, int lubMin, int lubMax,
00088                unsigned int minCard = 0,
00089                unsigned int maxCard = Gecode::Set::Limits::card,
00090                bool fail=true) {
00091         bool ok = false;
00092         try {
00093           SetVar x(home, glb, lubMin, lubMax, minCard, maxCard);
00094           ok = true;
00095         } catch (Gecode::Set::VariableEmptyDomain&) {
00096           if (!fail) {
00097             home.fail();
00098             return;
00099           }
00100           ok = true;
00101         }
00102         if (ok) {
00103           try {
00104             SetVarArray xs(home, 1,
00105                            glb, lubMin, lubMax, minCard, maxCard);
00106           } catch (Gecode::Set::VariableEmptyDomain&) {
00107             if (!fail) {
00108               home.fail();
00109               return;
00110             } else {
00111               return;
00112             }
00113           }
00114           if (fail) {
00115             home.fail();
00116           }
00117         }
00118       }
00119       void con(Space& home, int glbMin, int glbMax, const IntSet& lub,
00120                unsigned int minCard = 0,
00121                unsigned int maxCard = Gecode::Set::Limits::card,
00122                bool fail=true) {
00123         bool ok = false;
00124         try {
00125           SetVar x(home, glbMin, glbMax, lub, minCard, maxCard);
00126           ok = true;
00127         } catch (Gecode::Set::VariableEmptyDomain&) {
00128           if (!fail) {
00129             home.fail();
00130             return;
00131           }
00132           ok = true;
00133         }
00134         if (ok) {
00135           try {
00136             SetVarArray xs(home, 1,
00137                            glbMin, glbMax, lub, minCard, maxCard);
00138           } catch (Gecode::Set::VariableEmptyDomain&) {
00139             if (!fail) {
00140               home.fail();
00141               return;
00142             } else {
00143               return;
00144             }
00145           }
00146           if (fail) {
00147             home.fail();
00148           }
00149         }
00150       }
00151       void con(Space& home, const IntSet& glb, const IntSet& lub,
00152                unsigned int minCard = 0,
00153                unsigned int maxCard = Gecode::Set::Limits::card,
00154                bool fail=true) {
00155         bool ok = false;
00156         try {
00157           SetVar x(home, glb, lub, minCard, maxCard);
00158           ok = true;
00159         } catch (Gecode::Set::VariableEmptyDomain&) {
00160           if (!fail) {
00161             home.fail();
00162             return;
00163           }
00164           ok = true;
00165         }
00166         if (ok) {
00167           try {
00168             SetVarArray xs(home, 1,
00169                            glb, lub, minCard, maxCard);
00170           } catch (Gecode::Set::VariableEmptyDomain&) {
00171             if (!fail) {
00172               home.fail();
00173               return;
00174             } else {
00175               return;
00176             }
00177           }
00178           if (fail) {
00179             home.fail();
00180           }
00181         }
00182       }
00184       virtual void post(Space& home, SetVarArray&, IntVarArray&) {
00185         // Check non-empty lower, empty upper bound
00186         con(home, 1,1, 1,0);
00187         con(home, IntSet(1,1), 1,0);
00188         con(home, 1,1, IntSet(1,0));
00189         con(home, IntSet(1,1), IntSet(1,0));
00190 
00191         // Check min cardinality
00192         con(home, 1,0, 1,1, 2,3);
00193         con(home, IntSet(1,0), 1,1, 2U,3U);
00194         con(home, 1,0, IntSet(1,1), 2U,3U);
00195         con(home, IntSet(1,0), IntSet(1,1), 2U,3U);
00196 
00197         // Check max cardinality
00198         con(home, 1,3, 1,4, 0,2);
00199         con(home, IntSet(1,3), 1,4, 0U,2U);
00200         con(home, 1,3, IntSet(1,4), 0U,2U);
00201         con(home, IntSet(1,3), IntSet(1,4), 0U,2U);
00202 
00203         // Check non-subset bounds
00204         con(home, 1,3, 2,4);
00205         con(home, IntSet(1,3), 2,4);
00206         con(home, 1,3, IntSet(2,4));
00207         con(home, IntSet(1,3), IntSet(2,4));
00208         con(home, 1,4, 1,3);
00209         con(home, IntSet(1,4), 1,3);
00210         con(home, 1,4, IntSet(1,3));
00211         con(home, IntSet(1,4), IntSet(1,3));
00212 
00213         con(home, IntSet::empty, 2, 4, 0U, 10U, false);
00214       }
00215     };
00216     Construct _con;
00217 
00218 
00219 }}}
00220 
00221 // STATISTICS: test-set