Generated on Tue May 22 09:40:11 2018 for Gecode by doxygen 1.6.3

optimize.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main author:
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 <gecode/minimodel.hh>
00035 
00036 namespace Gecode {
00037 
00038   void
00039   IntMinimizeSpace::constrain(const Space& _best) {
00040     const IntMinimizeSpace* best =
00041       dynamic_cast<const IntMinimizeSpace*>(&_best);
00042     if (best == NULL)
00043       throw DynamicCastFailed("IntMinimizeSpace::constrain");
00044     rel(*this, cost(), IRT_LE, best->cost().val());
00045   }
00046 
00047 
00048   void
00049   IntMaximizeSpace::constrain(const Space& _best) {
00050     const IntMaximizeSpace* best =
00051       dynamic_cast<const IntMaximizeSpace*>(&_best);
00052     if (best == NULL)
00053       throw DynamicCastFailed("IntMaximizeSpace::constrain");
00054     rel(*this, cost(), IRT_GR, best->cost().val());
00055   }
00056 
00057 
00058   void
00059   IntLexMinimizeSpace::constrain(const Space& _best) {
00060     const IntLexMinimizeSpace* best =
00061       dynamic_cast<const IntLexMinimizeSpace*>(&_best);
00062     if (best == NULL)
00063       throw DynamicCastFailed("IntLexMinimizeSpace::constrain");
00064     IntVarArgs cx(cost()), bx(best->cost());
00065     IntArgs bn(bx.size());
00066     for (int i=bn.size(); i--; )
00067       bn[i] = bx[i].val();
00068     rel(*this, cx, IRT_LE, bn);
00069   }
00070 
00071   void
00072   IntLexMaximizeSpace::constrain(const Space& _best) {
00073     const IntLexMaximizeSpace* best =
00074       dynamic_cast<const IntLexMaximizeSpace*>(&_best);
00075     if (best == NULL)
00076       throw DynamicCastFailed("IntLexMaximizeSpace::constrain");
00077     IntVarArgs cx(cost()), bx(best->cost());
00078     IntArgs bn(bx.size());
00079     for (int i=bn.size(); i--; )
00080       bn[i] = bx[i].val();
00081     rel(*this, cx, IRT_GR, bn);
00082   }
00083 
00084 #ifdef GECODE_HAS_FLOAT_VARS
00085 
00086   void
00087   FloatMinimizeSpace::constrain(const Space& _best) {
00088     const FloatMinimizeSpace* best =
00089       dynamic_cast<const FloatMinimizeSpace*>(&_best);
00090     if (best == NULL)
00091       throw DynamicCastFailed("FloatMinimizeSpace::constrain");
00092     rel(*this, cost(), FRT_LE, best->cost().val()-step);
00093   }
00094 
00095 
00096   void
00097   FloatMaximizeSpace::constrain(const Space& _best) {
00098     const FloatMaximizeSpace* best =
00099       dynamic_cast<const FloatMaximizeSpace*>(&_best);
00100     if (best == NULL)
00101       throw DynamicCastFailed("FloatMaximizeSpace::constrain");
00102     rel(*this, cost(), FRT_GR, best->cost().val()+step);
00103   }
00104 
00105 #endif
00106 
00107 }
00108 
00109 // STATISTICS: minimodel-search
00110