optimize.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00110