optimize.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main author:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2008
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <gecode/minimodel.hh>
namespace Gecode {
void
IntMinimizeSpace::constrain(const Space& _best) {
const IntMinimizeSpace* best =
dynamic_cast<const IntMinimizeSpace*>(&_best);
if (best == nullptr)
throw DynamicCastFailed("IntMinimizeSpace::constrain");
rel(*this, cost(), IRT_LE, best->cost().val());
}
void
IntMaximizeSpace::constrain(const Space& _best) {
const IntMaximizeSpace* best =
dynamic_cast<const IntMaximizeSpace*>(&_best);
if (best == nullptr)
throw DynamicCastFailed("IntMaximizeSpace::constrain");
rel(*this, cost(), IRT_GR, best->cost().val());
}
void
IntLexMinimizeSpace::constrain(const Space& _best) {
const IntLexMinimizeSpace* best =
dynamic_cast<const IntLexMinimizeSpace*>(&_best);
if (best == nullptr)
throw DynamicCastFailed("IntLexMinimizeSpace::constrain");
IntVarArgs cx(cost()), bx(best->cost());
IntArgs bn(bx.size());
for (int i=bn.size(); i--; )
bn[i] = bx[i].val();
rel(*this, cx, IRT_LE, bn);
}
void
IntLexMaximizeSpace::constrain(const Space& _best) {
const IntLexMaximizeSpace* best =
dynamic_cast<const IntLexMaximizeSpace*>(&_best);
if (best == nullptr)
throw DynamicCastFailed("IntLexMaximizeSpace::constrain");
IntVarArgs cx(cost()), bx(best->cost());
IntArgs bn(bx.size());
for (int i=bn.size(); i--; )
bn[i] = bx[i].val();
rel(*this, cx, IRT_GR, bn);
}
#ifdef GECODE_HAS_FLOAT_VARS
void
FloatMinimizeSpace::constrain(const Space& _best) {
const FloatMinimizeSpace* best =
dynamic_cast<const FloatMinimizeSpace*>(&_best);
if (best == nullptr)
throw DynamicCastFailed("FloatMinimizeSpace::constrain");
rel(*this, cost(), FRT_LE, best->cost().val()-step);
}
void
FloatMaximizeSpace::constrain(const Space& _best) {
const FloatMaximizeSpace* best =
dynamic_cast<const FloatMaximizeSpace*>(&_best);
if (best == nullptr)
throw DynamicCastFailed("FloatMaximizeSpace::constrain");
rel(*this, cost(), FRT_GR, best->cost().val()+step);
}
#endif
}
// STATISTICS: minimodel-search
Gecode::ArgArrayBase::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1607
Gecode::DynamicCastFailed
Exception: dynamic cast failed
Definition exception.hpp:69
Gecode::FloatMaximizeSpace::constrain
virtual void constrain(const Space &best)
Member function constraining according to cost.
Definition optimize.cpp:97
Gecode::FloatMaximizeSpace::step
FloatNum step
Step by which a next solution has to have lower cost.
Definition minimodel.hh:2474
Gecode::FloatMaximizeSpace::cost
virtual FloatVar cost(void) const =0
Return variable with current cost.
Gecode::FloatMaximizeSpace::FloatMaximizeSpace
FloatMaximizeSpace(FloatNum s=0.0)
Constructor with step s.
Definition optimize.hpp:80
Gecode::FloatMinimizeSpace::cost
virtual FloatVar cost(void) const =0
Return variable with current cost.
Gecode::FloatMinimizeSpace::constrain
virtual void constrain(const Space &best)
Member function constraining according to cost.
Definition optimize.cpp:87
Gecode::FloatMinimizeSpace::FloatMinimizeSpace
FloatMinimizeSpace(FloatNum s=0.0)
Constructor with step s.
Definition optimize.hpp:71
Gecode::FloatMinimizeSpace::step
FloatNum step
Step by which a next solution has to have lower cost.
Definition minimodel.hh:2449
Gecode::FloatVar::val
FloatVal val(void) const
Return assigned value.
Definition float.hpp:53
Gecode::IntArgs
Passing integer arguments.
Definition int.hh:628
Gecode::IntLexMaximizeSpace::cost
virtual IntVarArgs cost(void) const =0
Return variables with current costs.
Gecode::IntLexMaximizeSpace::IntLexMaximizeSpace
IntLexMaximizeSpace(void)
Default constructor.
Definition optimize.hpp:61
Gecode::IntLexMaximizeSpace::constrain
virtual void constrain(const Space &best)
Member function constraining according to increasing costs.
Definition optimize.cpp:72
Gecode::IntLexMinimizeSpace::cost
virtual IntVarArgs cost(void) const =0
Return variables with current costs.
Gecode::IntLexMinimizeSpace::constrain
virtual void constrain(const Space &best)
Member function constraining according to decreasing costs.
Definition optimize.cpp:59
Gecode::IntLexMinimizeSpace::IntLexMinimizeSpace
IntLexMinimizeSpace(void)
Default constructor.
Definition optimize.hpp:53
Gecode::IntMaximizeSpace::cost
virtual IntVar cost(void) const =0
Return variable with current cost.
Gecode::IntMaximizeSpace::IntMaximizeSpace
IntMaximizeSpace(void)
Default constructor.
Definition optimize.hpp:45
Gecode::IntMaximizeSpace::constrain
virtual void constrain(const Space &best)
Member function constraining according to increasing cost.
Definition optimize.cpp:49
Gecode::IntMinimizeSpace::cost
virtual IntVar cost(void) const =0
Return variable with current cost.
Gecode::IntMinimizeSpace::IntMinimizeSpace
IntMinimizeSpace(void)
Default constructor.
Definition optimize.hpp:37
Gecode::IntMinimizeSpace::constrain
virtual void constrain(const Space &best)
Member function constraining according to decreasing cost.
Definition optimize.cpp:39
Gecode::IntVarArgs
Passing integer variables.
Definition int.hh:656
Gecode::IntVar::val
int val(void) const
Return assigned value.
Definition int.hpp:56
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
Gecode::FRT_GR
@ FRT_GR
Greater ( ).
Definition float.hh:1074
Gecode::FRT_LE
@ FRT_LE
Less ( ).
Definition float.hh:1072
Gecode::IRT_LE
@ IRT_LE
Less ( ).
Definition int.hh:929
Gecode::IRT_GR
@ IRT_GR
Greater ( ).
Definition int.hh:931
Gecode::Space::Space
Space(void)
Default constructor.
Definition core.cpp:115
minimodel.hh
Gecode
Gecode toplevel namespace