gist.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Guido Tack, 2006
*
* 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.
*
*/
namespace Gecode { namespace Gist {
template<class S>
VarComparator<S>::VarComparator(std::string name)
: TextOutput(name) {}
template<class S>
void
VarComparator<S>::compare(const Space& s0, const Space& s1) {
std::ostringstream result;
dynamic_cast<const S&>(s0).compare(s1,result);
if (result.str() != "") {
init();
addHtml("<pre>\n");
getStream() << result.str() << std::endl;
addHtml("</pre><hr />");
}
}
template<class S>
std::string
VarComparator<S>::name(void) {
return TextOutput::name();
}
template<class S>
void
VarComparator<S>::finalize(void) {
TextOutput::finalize();
}
inline std::string
Comparator::compare(std::string x_n, IntVar x, IntVar y) {
IntVarRanges xr(x), yr(y);
if (!Iter::Ranges::equal(xr,yr)) {
std::ostringstream ret;
ret << x_n << "=" << x << " -> " << y;
return ret.str();
}
return "";
}
inline std::string
Comparator::compare(std::string x_n, BoolVar x, BoolVar y) {
if (! (x.min() == y.min() && x.max() == y.max()) ) {
std::ostringstream ret;
ret << x_n << "=" << x << " -> " << y;
return ret.str();
}
return "";
}
#ifdef GECODE_HAS_SET_VARS
inline std::string
Comparator::compare(std::string x_n, SetVar x, SetVar y) {
SetVarGlbRanges xglbr(x), yglbr(y);
SetVarLubRanges xlubr(x), ylubr(y);
if (! (Iter::Ranges::equal(xglbr,yglbr) &&
Iter::Ranges::equal(xlubr,ylubr) &&
x.cardMin() == y.cardMin() &&
y.cardMax() == y.cardMax()) ) {
std::ostringstream ret;
ret << x_n << "=" << x << " -> " << y;
return ret.str();
}
return "";
}
#endif
#ifdef GECODE_HAS_FLOAT_VARS
inline std::string
Comparator::compare(std::string x_n, FloatVar x, FloatVar y) {
if (! (x.min() == y.min() && x.max() == y.max()) ) {
std::ostringstream ret;
ret << x_n << "=" << x << " -> " << y;
return ret.str();
}
return "";
}
#endif
template<class Var>
std::string
Comparator::compare(std::string x_n, const VarArgArray<Var>& x,
const VarArgArray<Var>& y) {
if (x.size() != y.size())
return "Error: array size mismatch";
std::ostringstream ret;
bool first = true;
for (int i=0; i<x.size(); i++) {
std::ostringstream xni;
xni << x_n << "[" << i << "]";
std::string cmp = compare(xni.str(),x[i],y[i]);
if (cmp != "") {
if (!first) {
ret << ", ";
} else {
first = false;
}
ret << cmp;
}
}
return ret.str();
}
template<class S>
Print<S>::Print(const std::string& name)
: TextOutput(name) {}
template<class S>
void
Print<S>::inspect(const Space& node) {
init();
addHtml("<pre>\n");
dynamic_cast<const S&>(node).print(getStream());
flush();
addHtml("</pre><hr />");
}
template<class S>
std::string
Print<S>::name(void) {
return TextOutput::name();
}
template<class S>
void
Print<S>::finalize(void) {
TextOutput::finalize();
}
forceinline
Options::Options(void) {}
forceinline
Options::_I::_I(void) : _click(heap,1), n_click(0),
_solution(heap,1), n_solution(0),
_move(heap,1), n_move(0), _compare(heap,1), n_compare(0) {}
forceinline void
Options::_I::click(Inspector* i) {
_click[static_cast<int>(n_click++)] = i;
}
forceinline void
Options::_I::solution(Inspector* i) {
_solution[static_cast<int>(n_solution++)] = i;
}
forceinline void
Options::_I::move(Inspector* i) {
_move[static_cast<int>(n_move++)] = i;
}
forceinline void
Options::_I::compare(Comparator* c) {
_compare[static_cast<int>(n_compare++)] = c;
}
forceinline Inspector*
Options::_I::click(unsigned int i) const {
return (i < n_click) ? _click[i] : NULL;
}
forceinline Inspector*
Options::_I::solution(unsigned int i) const {
return (i < n_solution) ? _solution[i] : NULL;
}
forceinline Inspector*
Options::_I::move(unsigned int i) const {
return (i < n_move) ? _move[i] : NULL;
}
forceinline Comparator*
Options::_I::compare(unsigned int i) const {
return (i < n_compare) ? _compare[i] : NULL;
}
inline int
dfs(Space* root, const Gist::Options& opt) {
return explore(root, false, opt);
}
inline int
bab(Space* root, const Gist::Options& opt) {
return Gist::explore(root, true, opt);
}
}}
// STATISTICS: gist-any
Gecode::ArgArrayBase::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1607
Gecode::BoolVar
Boolean integer variables.
Definition int.hh:512
Gecode::BoolVar::max
int max(void) const
Return maximum of domain.
Definition bool.hpp:71
Gecode::BoolVar::min
int min(void) const
Return minimum of domain.
Definition bool.hpp:63
Gecode::FloatVar
Float variables.
Definition float.hh:870
Gecode::FloatVar::min
FloatNum min(void) const
Return minimum of domain.
Definition float.hpp:59
Gecode::FloatVar::max
FloatNum max(void) const
Return maximum of domain.
Definition float.hpp:67
Gecode::Gist::Comparator
Abstract base class for comparators.
Definition gist.hh:119
Gecode::Gist::Comparator::compare
virtual void compare(const Space &s0, const Space &s1)=0
Call-back function.
Gecode::Gist::Inspector
Abstract base class for inspectors.
Definition gist.hh:99
Gecode::Gist::Options::_I::click
void click(Inspector *i)
Add inspector that reacts on node double clicks.
Definition gist.hpp:170
Gecode::Gist::Options::_I::move
void move(Inspector *i)
Add inspector that reacts on each move of the cursor.
Definition gist.hpp:178
Gecode::Gist::Options::_I::compare
void compare(Comparator *c)
Add comparator.
Definition gist.hpp:182
Gecode::Gist::Options::_I::_I
_I(void)
Constructor.
Definition gist.hpp:165
Gecode::Gist::Options::_I::solution
void solution(Inspector *i)
Add inspector that reacts on each new solution that is found.
Definition gist.hpp:174
Gecode::Gist::Options
Options for Gist
Definition gist.hh:234
Gecode::Gist::Options::Options
Options(void)
Initialize with default values.
Definition gist.hpp:162
Gecode::Gist::Print::inspect
virtual void inspect(const Space &node)
Use the print method of the template class S to print a space.
Definition gist.hpp:141
Gecode::Gist::Print::name
virtual std::string name(void)
Return name.
Definition gist.hpp:151
Gecode::Gist::Print::finalize
virtual void finalize(void)
Clean up when Gist exits.
Definition gist.hpp:157
Gecode::Gist::Print::Print
Print(const std::string &name)
Constructor.
Definition gist.hpp:136
Gecode::Gist::TextOutput::finalize
void finalize(void)
Clean up when Gist exits.
Definition gist.cpp:64
Gecode::Gist::TextOutput::flush
void flush(void)
Flush stream.
Definition gist.cpp:90
Gecode::Gist::TextOutput::TextOutput
TextOutput(const std::string &name)
Constructor.
Definition gist.cpp:60
Gecode::Gist::TextOutput::getStream
std::ostream & getStream(void)
Get the stream that is used to output text.
Definition gist.cpp:85
Gecode::Gist::TextOutput::name
virtual std::string name(void)
Name of the inspector.
Definition gist.cpp:74
Gecode::Gist::TextOutput::init
void init(void)
Initialize the implementation object.
Definition gist.cpp:77
Gecode::Gist::TextOutput::addHtml
void addHtml(const char *s)
Add html text s to the output.
Definition gist.cpp:95
Gecode::Gist::VarComparator::VarComparator
VarComparator(std::string name)
Constructor.
Definition gist.hpp:37
Gecode::Gist::VarComparator::compare
virtual void compare(const Space &s0, const Space &s1)
Compare s0 to s1.
Definition gist.hpp:42
Gecode::Gist::VarComparator::name
virtual std::string name(void)
Return name.
Definition gist.hpp:55
Gecode::Gist::VarComparator::finalize
virtual void finalize(void)
Finalize when Gist exits.
Definition gist.hpp:61
Gecode::IntVarRanges
Range iterator for integer variables
Definition int.hh:473
Gecode::IntVar
Integer variables.
Definition int.hh:371
Gecode::SetVarGlbRanges
Iterator for the greatest lower bound ranges of a set variable.
Definition set.hh:270
Gecode::SetVarLubRanges
Iterator for the least upper bound ranges of a set variable.
Definition set.hh:302
Gecode::SetVar
Set variables
Definition set.hh:127
Gecode::SetVar::cardMax
unsigned int cardMax(void) const
Return cardinality maximum.
Definition set.hpp:81
Gecode::SetVar::cardMin
unsigned int cardMin(void) const
Return cardinality minimum.
Definition set.hpp:78
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::VarArgArray
Argument array for variables.
Definition array.hpp:774
Gecode::heap
Heap heap
The single global heap.
Definition heap.cpp:44
Gecode::Gist::bab
int bab(Space *root, const Gist::Options &opt=Gist::Options::def)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition gist.hpp:208
Gecode::Gist::dfs
int dfs(Space *root, const Gist::Options &opt=Gist::Options::def)
Create a new stand-alone Gist for root.
Definition gist.hpp:203
Gecode::Gist
The Gecode Interactive Search Tool.
Gecode::Gist::explore
int explore(Space *root, bool bab, const Options &opt)
Create a new stand-alone Gist for root using bab.
Definition gist.cpp:102
Gecode::Iter::Ranges::equal
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
Definition ranges-operations.hpp:84
Gecode::Set::print
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
Definition print.hpp:63
Gecode
Gecode toplevel namespace
forceinline
#define forceinline
Definition config.hpp:187