Skip to content

Commit 97f74e2

Browse files
author
Christian Schulte
committed
Improved
git-svn-id: file:///Users/tack/GecodeGitMigration/gecode-svn-mirror/gecode/trunk@14452 e85b7adc-8362-4630-8c63-7469d557c915
1 parent 7e78761 commit 97f74e2

File tree

5 files changed

+275
-92
lines changed

5 files changed

+275
-92
lines changed

Makefile.dep

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7220,6 +7220,74 @@ gecode/minimodel/reg$(OBJSUFFIX) gecode/minimodel/reg$(SBJSUFFIX): \
72207220
./gecode/support/sort.hpp ./gecode/support/static-stack.hpp ./gecode/support/thread.hpp \
72217221
./gecode/support/thread/none.hpp ./gecode/support/thread/pthreads.hpp ./gecode/support/thread/thread.hpp \
72227222
./gecode/support/thread/windows.hpp ./gecode/support/timer.hpp
7223+
gecode/minimodel/optimize$(OBJSUFFIX) gecode/minimodel/optimize$(SBJSUFFIX): \
7224+
./gecode/float.hh ./gecode/float/array-traits.hpp ./gecode/float/array.hpp \
7225+
./gecode/float/branch/activity.hpp ./gecode/float/branch/afc.hpp ./gecode/float/branch/assign.hpp \
7226+
./gecode/float/branch/traits.hpp ./gecode/float/branch/val.hpp ./gecode/float/branch/var.hpp \
7227+
./gecode/float/exception.hpp ./gecode/float/limits.hpp ./gecode/float/nextafter.hpp \
7228+
./gecode/float/num.hpp ./gecode/float/rounding.hpp ./gecode/float/val.hpp \
7229+
./gecode/float/var-imp.hpp ./gecode/float/var-imp/delta.hpp ./gecode/float/var-imp/float.hpp \
7230+
./gecode/float/var/float.hpp ./gecode/float/var/print.hpp ./gecode/float/view.hpp \
7231+
./gecode/float/view/float.hpp ./gecode/float/view/minus.hpp ./gecode/float/view/offset.hpp \
7232+
./gecode/float/view/print.hpp ./gecode/float/view/rel-test.hpp ./gecode/float/view/scale.hpp \
7233+
./gecode/int.hh ./gecode/int/array-traits.hpp ./gecode/int/array.hpp \
7234+
./gecode/int/branch/activity.hpp ./gecode/int/branch/afc.hpp ./gecode/int/branch/assign.hpp \
7235+
./gecode/int/branch/traits.hpp ./gecode/int/branch/val.hpp ./gecode/int/branch/var.hpp \
7236+
./gecode/int/div.hh ./gecode/int/div.hpp ./gecode/int/exception.hpp \
7237+
./gecode/int/extensional/dfa.hpp ./gecode/int/extensional/tuple-set.hpp ./gecode/int/int-set-1.hpp \
7238+
./gecode/int/int-set-2.hpp ./gecode/int/limits.hpp ./gecode/int/propagator.hpp \
7239+
./gecode/int/reify.hpp ./gecode/int/var-imp.hpp ./gecode/int/var-imp/bool.hpp \
7240+
./gecode/int/var-imp/delta.hpp ./gecode/int/var-imp/int.hpp ./gecode/int/var/bool.hpp \
7241+
./gecode/int/var/int.hpp ./gecode/int/var/print.hpp ./gecode/int/view.hpp \
7242+
./gecode/int/view/bool-test.hpp ./gecode/int/view/bool.hpp ./gecode/int/view/cached.hpp \
7243+
./gecode/int/view/constint.hpp ./gecode/int/view/int.hpp ./gecode/int/view/iter.hpp \
7244+
./gecode/int/view/minus.hpp ./gecode/int/view/neg-bool.hpp ./gecode/int/view/offset.hpp \
7245+
./gecode/int/view/print.hpp ./gecode/int/view/rel-test.hpp ./gecode/int/view/scale.hpp \
7246+
./gecode/int/view/zero.hpp ./gecode/iter.hh ./gecode/iter/ranges-add.hpp \
7247+
./gecode/iter/ranges-append.hpp ./gecode/iter/ranges-array.hpp ./gecode/iter/ranges-cache.hpp \
7248+
./gecode/iter/ranges-compl.hpp ./gecode/iter/ranges-diff.hpp ./gecode/iter/ranges-empty.hpp \
7249+
./gecode/iter/ranges-inter.hpp ./gecode/iter/ranges-list.hpp ./gecode/iter/ranges-map.hpp \
7250+
./gecode/iter/ranges-minmax.hpp ./gecode/iter/ranges-minus.hpp ./gecode/iter/ranges-negative.hpp \
7251+
./gecode/iter/ranges-offset.hpp ./gecode/iter/ranges-operations.hpp ./gecode/iter/ranges-positive.hpp \
7252+
./gecode/iter/ranges-rangelist.hpp ./gecode/iter/ranges-scale.hpp ./gecode/iter/ranges-singleton-append.hpp \
7253+
./gecode/iter/ranges-singleton.hpp ./gecode/iter/ranges-size.hpp ./gecode/iter/ranges-union.hpp \
7254+
./gecode/iter/ranges-values.hpp ./gecode/iter/values-array.hpp ./gecode/iter/values-bitset.hpp \
7255+
./gecode/iter/values-bitsetoffset.hpp ./gecode/iter/values-inter.hpp ./gecode/iter/values-list.hpp \
7256+
./gecode/iter/values-map.hpp ./gecode/iter/values-minus.hpp ./gecode/iter/values-negative.hpp \
7257+
./gecode/iter/values-offset.hpp ./gecode/iter/values-positive.hpp ./gecode/iter/values-ranges.hpp \
7258+
./gecode/iter/values-singleton.hpp ./gecode/iter/values-union.hpp ./gecode/iter/values-unique.hpp \
7259+
./gecode/kernel.hh ./gecode/kernel/activity.hpp ./gecode/kernel/advisor.hpp \
7260+
./gecode/kernel/afc.hpp ./gecode/kernel/allocators.hpp ./gecode/kernel/archive.hpp \
7261+
./gecode/kernel/array.hpp ./gecode/kernel/branch-tiebreak.hpp ./gecode/kernel/branch-traits.hpp \
7262+
./gecode/kernel/branch-val.hpp ./gecode/kernel/branch-var.hpp ./gecode/kernel/brancher-merit.hpp \
7263+
./gecode/kernel/brancher-val-commit.hpp ./gecode/kernel/brancher-val-sel-commit.hpp ./gecode/kernel/brancher-val-sel.hpp \
7264+
./gecode/kernel/brancher-view-sel.hpp ./gecode/kernel/brancher-view-val.hpp ./gecode/kernel/brancher-view.hpp \
7265+
./gecode/kernel/core.hpp ./gecode/kernel/exception.hpp ./gecode/kernel/global-afc.hpp \
7266+
./gecode/kernel/macros.hpp ./gecode/kernel/memory-config.hpp ./gecode/kernel/memory-manager.hpp \
7267+
./gecode/kernel/modevent.hpp ./gecode/kernel/propagator.hpp ./gecode/kernel/range-list.hpp \
7268+
./gecode/kernel/region.hpp ./gecode/kernel/rnd.hpp ./gecode/kernel/shared-array.hpp \
7269+
./gecode/kernel/var-imp.hpp ./gecode/kernel/var-type.hpp ./gecode/kernel/var.hpp \
7270+
./gecode/kernel/view.hpp ./gecode/minimodel.hh ./gecode/minimodel/bool-expr.hpp \
7271+
./gecode/minimodel/exception.hpp ./gecode/minimodel/float-rel.hpp ./gecode/minimodel/int-rel.hpp \
7272+
./gecode/minimodel/ldsb.hpp ./gecode/minimodel/matrix.hpp ./gecode/minimodel/optimize.hpp \
7273+
./gecode/minimodel/set-expr.hpp ./gecode/minimodel/set-rel.hpp ./gecode/set.hh \
7274+
./gecode/set/array-traits.hpp ./gecode/set/array.hpp ./gecode/set/branch/activity.hpp \
7275+
./gecode/set/branch/afc.hpp ./gecode/set/branch/assign.hpp ./gecode/set/branch/traits.hpp \
7276+
./gecode/set/branch/val.hpp ./gecode/set/branch/var.hpp ./gecode/set/exception.hpp \
7277+
./gecode/set/limits.hpp ./gecode/set/var-imp.hpp ./gecode/set/var-imp/delta.hpp \
7278+
./gecode/set/var-imp/integerset.hpp ./gecode/set/var-imp/iter.hpp ./gecode/set/var-imp/set.hpp \
7279+
./gecode/set/var/print.hpp ./gecode/set/var/set.hpp ./gecode/set/view.hpp \
7280+
./gecode/set/view/cached.hpp ./gecode/set/view/complement.hpp ./gecode/set/view/const.hpp \
7281+
./gecode/set/view/print.hpp ./gecode/set/view/set.hpp ./gecode/set/view/singleton.hpp \
7282+
./gecode/support.hh ./gecode/support/auto-link.hpp ./gecode/support/bitset-base.hpp \
7283+
./gecode/support/bitset-offset.hpp ./gecode/support/bitset.hpp ./gecode/support/block-allocator.hpp \
7284+
./gecode/support/cast.hpp ./gecode/support/config.hpp ./gecode/support/dynamic-array.hpp \
7285+
./gecode/support/dynamic-queue.hpp ./gecode/support/dynamic-stack.hpp ./gecode/support/exception.hpp \
7286+
./gecode/support/heap.hpp ./gecode/support/hw-rnd.hpp ./gecode/support/int-type.hpp \
7287+
./gecode/support/macros.hpp ./gecode/support/marked-pointer.hpp ./gecode/support/random.hpp \
7288+
./gecode/support/sort.hpp ./gecode/support/static-stack.hpp ./gecode/support/thread.hpp \
7289+
./gecode/support/thread/none.hpp ./gecode/support/thread/pthreads.hpp ./gecode/support/thread/thread.hpp \
7290+
./gecode/support/thread/windows.hpp ./gecode/support/timer.hpp
72237291
gecode/driver/options$(OBJSUFFIX) gecode/driver/options$(SBJSUFFIX): \
72247292
./gecode/driver.hh ./gecode/driver/options.hpp ./gecode/driver/script.hpp \
72257293
./gecode/float.hh ./gecode/float/array-traits.hpp ./gecode/float/array.hpp \

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ MMSRC0 = \
594594
int-expr.cpp int-rel.cpp int-arith.cpp bool-expr.cpp \
595595
set-expr.cpp set-rel.cpp \
596596
float-expr.cpp float-rel.cpp float-arith.cpp \
597-
reg.cpp
597+
reg.cpp optimize.cpp
598598
MMHDR0 = \
599599
int-rel.hpp float-rel.hpp exception.hpp matrix.hpp \
600600
bool-expr.hpp set-expr.hpp set-rel.hpp \

gecode/minimodel.hh

Lines changed: 94 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,12 +2179,14 @@ namespace Gecode {
21792179
* @{
21802180
*/
21812181
namespace Gecode {
2182+
21822183
/// Construct linear expression as sum of \ref IntArgs \ref Slice elements
21832184
GECODE_MINIMODEL_EXPORT LinIntExpr
21842185
sum(const Slice<IntArgs>& slice);
21852186
/// Construct linear expression as sum of \ref IntArgs \ref Matrix elements
21862187
GECODE_MINIMODEL_EXPORT LinIntExpr
21872188
sum(const Matrix<IntArgs>& matrix);
2189+
21882190
}
21892191
/** @}*/
21902192

@@ -2198,66 +2200,107 @@ namespace Gecode {
21982200
*
21992201
* \ingroup TaskModelMiniModel
22002202
*/
2201-
//@{
2202-
namespace MiniModel {
2203-
2204-
/// Baseclass for integer-based cost-based optimization
2205-
template<IntRelType irt>
2206-
class IntOptimizeSpace : public Space {
2207-
public:
2208-
/// Default constructor
2209-
IntOptimizeSpace(void);
2210-
/// Constructor for cloning
2211-
IntOptimizeSpace(bool share, IntOptimizeSpace& s);
2212-
/// Member function constraining according to cost
2213-
virtual void constrain(const Space& best);
2214-
/// Return variable with current cost
2215-
virtual IntVar cost(void) const = 0;
2216-
};
2217-
2218-
#ifdef GECODE_HAS_FLOAT_VARS
2219-
2220-
/// Baseclass for float-based cost-based optimization
2221-
template<FloatRelType frt>
2222-
class FloatOptimizeSpace : public Space {
2223-
protected:
2224-
/// Step to increment for next better solution
2225-
FloatNum step;
2226-
public:
2227-
/// Constructor with step \a s
2228-
FloatOptimizeSpace(FloatNum s=0.0);
2229-
/// Constructor for cloning
2230-
FloatOptimizeSpace(bool share, FloatOptimizeSpace& s);
2231-
/// Member function constraining according to cost
2232-
virtual void constrain(const Space& best);
2233-
/// Return variable with current cost
2234-
virtual FloatVar cost(void) const = 0;
2235-
};
22362203

2237-
#endif
2204+
/**
2205+
* \brief Class for minimizing integer cost
2206+
* \ingroup TaskModelMiniModelOptimize
2207+
*/
2208+
class IntMinimizeSpace : public Space {
2209+
public:
2210+
/// Default constructor
2211+
IntMinimizeSpace(void);
2212+
/// Constructor for cloning
2213+
IntMinimizeSpace(bool share, IntMinimizeSpace& s);
2214+
/// Member function constraining according to decreasing cost
2215+
GECODE_MINIMODEL_EXPORT
2216+
virtual void constrain(const Space& best);
2217+
/// Return variable with current cost
2218+
virtual IntVar cost(void) const = 0;
2219+
};
22382220

2239-
}
2221+
/**
2222+
* \brief Class for maximizing integer cost
2223+
* \ingroup TaskModelMiniModelOptimize
2224+
*/
2225+
class IntMaximizeSpace : public Space {
2226+
public:
2227+
/// Default constructor
2228+
IntMaximizeSpace(void);
2229+
/// Constructor for cloning
2230+
IntMaximizeSpace(bool share, IntMaximizeSpace& s);
2231+
/// Member function constraining according to increasing cost
2232+
GECODE_MINIMODEL_EXPORT
2233+
virtual void constrain(const Space& best);
2234+
/// Return variable with current cost
2235+
virtual IntVar cost(void) const = 0;
2236+
};
22402237

2241-
/// Class for minimizing integer cost
2242-
typedef MiniModel::IntOptimizeSpace<IRT_LE> MinimizeSpace;
2243-
/// Class for maximizing integer cost
2244-
typedef MiniModel::IntOptimizeSpace<IRT_GR> MaximizeSpace;
2245-
/// Class for minimizing integer cost
2246-
typedef MiniModel::IntOptimizeSpace<IRT_LE> IntMinimizeSpace;
2247-
/// Class for maximizing integer cost
2248-
typedef MiniModel::IntOptimizeSpace<IRT_GR> IntMaximizeSpace;
2238+
/**
2239+
* \brief Class for minimizing integer cost
2240+
* \deprecated Use IntMinimizeSpace instead.
2241+
*/
2242+
typedef IntMinimizeSpace MinimizeSpace;
2243+
/**
2244+
* \brief Class for maximizing integer cost
2245+
* \deprecated Use IntMaximizeSpace instead.
2246+
*/
2247+
typedef IntMaximizeSpace MaximizeSpace;
22492248

2249+
22502250
#ifdef GECODE_HAS_FLOAT_VARS
22512251

2252-
/// Class for minimizing float cost
2253-
typedef MiniModel::FloatOptimizeSpace<FRT_LE> FloatMinimizeSpace;
2254-
/// Class for maximizing float cost
2255-
typedef MiniModel::FloatOptimizeSpace<FRT_GR> FloatMaximizeSpace;
2252+
/**
2253+
* \brief Class for minimizing float cost
2254+
*
2255+
* The class supports using a step value \a step that will make sure
2256+
* that better solutions must be better by at least the value of
2257+
* \a step.
2258+
*
2259+
* \ingroup TaskModelMiniModelOptimize
2260+
*/
2261+
class FloatMinimizeSpace : public Space {
2262+
protected:
2263+
/// Step by which a next solution has to have lower cost
2264+
FloatNum step;
2265+
public:
2266+
/// Constructor with step \a s
2267+
FloatMinimizeSpace(FloatNum s=0.0);
2268+
/// Constructor for cloning
2269+
FloatMinimizeSpace(bool share, FloatMinimizeSpace& s);
2270+
/// Member function constraining according to cost
2271+
GECODE_MINIMODEL_EXPORT
2272+
virtual void constrain(const Space& best);
2273+
/// Return variable with current cost
2274+
virtual FloatVar cost(void) const = 0;
2275+
};
2276+
2277+
/**
2278+
* \brief Class for maximizing float cost
2279+
*
2280+
* The class supports using a step value \a step that will make sure
2281+
* that better solutions must be better by at least the value of
2282+
* \a step.
2283+
*
2284+
* \ingroup TaskModelMiniModelOptimize
2285+
*/
2286+
class FloatMaximizeSpace : public Space {
2287+
protected:
2288+
/// Step by which a next solution has to have lower cost
2289+
FloatNum step;
2290+
public:
2291+
/// Constructor with step \a s
2292+
FloatMaximizeSpace(FloatNum s=0.0);
2293+
/// Constructor for cloning
2294+
FloatMaximizeSpace(bool share, FloatMaximizeSpace& s);
2295+
/// Member function constraining according to cost
2296+
GECODE_MINIMODEL_EXPORT
2297+
virtual void constrain(const Space& best);
2298+
/// Return variable with current cost
2299+
virtual FloatVar cost(void) const = 0;
2300+
};
22562301

22572302
#endif
22582303

2259-
//@}
2260-
22612304
}
22622305

22632306
#include <gecode/minimodel/optimize.hpp>

gecode/minimodel/optimize.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
/*
3+
* Main author:
4+
* Christian Schulte <[email protected]>
5+
*
6+
* Copyright:
7+
* Christian Schulte, 2008
8+
*
9+
* Last modified:
10+
* $Date$ by $Author$
11+
* $Revision$
12+
*
13+
* This file is part of Gecode, the generic constraint
14+
* development environment:
15+
* http://www.gecode.org
16+
*
17+
* Permission is hereby granted, free of charge, to any person obtaining
18+
* a copy of this software and associated documentation files (the
19+
* "Software"), to deal in the Software without restriction, including
20+
* without limitation the rights to use, copy, modify, merge, publish,
21+
* distribute, sublicense, and/or sell copies of the Software, and to
22+
* permit persons to whom the Software is furnished to do so, subject to
23+
* the following conditions:
24+
*
25+
* The above copyright notice and this permission notice shall be
26+
* included in all copies or substantial portions of the Software.
27+
*
28+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35+
*
36+
*/
37+
38+
#include <gecode/minimodel.hh>
39+
40+
namespace Gecode {
41+
42+
void
43+
IntMinimizeSpace::constrain(const Space& _best) {
44+
const IntMinimizeSpace* best =
45+
dynamic_cast<const IntMinimizeSpace*>(&_best);
46+
if (best == NULL)
47+
throw DynamicCastFailed("IntMinimizeSpace::constrain");
48+
rel(*this, cost(), IRT_LE, best->cost().val());
49+
}
50+
51+
52+
void
53+
IntMaximizeSpace::constrain(const Space& _best) {
54+
const IntMaximizeSpace* best =
55+
dynamic_cast<const IntMaximizeSpace*>(&_best);
56+
if (best == NULL)
57+
throw DynamicCastFailed("IntMaximizeSpace::constrain");
58+
rel(*this, cost(), IRT_GR, best->cost().val());
59+
}
60+
61+
62+
#ifdef GECODE_HAS_FLOAT_VARS
63+
64+
void
65+
FloatMinimizeSpace::constrain(const Space& _best) {
66+
const FloatMinimizeSpace* best =
67+
dynamic_cast<const FloatMinimizeSpace*>(&_best);
68+
if (best == NULL)
69+
throw DynamicCastFailed("FloatMinimizeSpace::constrain");
70+
rel(*this, cost(), FRT_LE, best->cost().val()-step);
71+
}
72+
73+
74+
void
75+
FloatMaximizeSpace::constrain(const Space& _best) {
76+
const FloatMaximizeSpace* best =
77+
dynamic_cast<const FloatMaximizeSpace*>(&_best);
78+
if (best == NULL)
79+
throw DynamicCastFailed("FloatMaximizeSpace::constrain");
80+
rel(*this, cost(), FRT_GR, best->cost().val()+step);
81+
}
82+
83+
#endif
84+
85+
}
86+
87+
// STATISTICS: minimodel-search
88+

0 commit comments

Comments
 (0)