int-trace-view.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2016
*
* 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 Int {
class IntTraceView {
protected:
RangeList* dom;
public:
IntTraceView(void);
IntTraceView(Space& home, IntView y);
RangeList* ranges(void) const;
void prune(Space& home, IntView y, const Delta& d);
void update(Space& home, IntTraceView x);
static unsigned long long int slack(IntView x);
};
forceinline
IntTraceView::IntTraceView(void) {}
forceinline
IntTraceView::IntTraceView(Space& home, IntView y) {
ViewRanges<IntView> yr(y);
RangeList::copy(home, dom, yr);
}
forceinline RangeList*
IntTraceView::ranges(void) const {
return dom;
}
forceinline void
IntTraceView::prune(Space& home, IntView y, const Delta& d) {
if (y.range() && (dom->next() == NULL)) {
dom->min(y.min()); dom->max(y.max());
} else if (!y.any(d) && (y.max(d)+1 == y.min())) {
// The lower bound has been adjusted
if (y.min() > dom->max()) {
RangeList* p = dom;
RangeList* l = p->next();
while ((l != NULL) && (l->max() < y.min())) {
p=l; l=l->next();
}
dom->dispose(home,p);
dom = l;
}
dom->min(y.min());
} else if (!y.any(d) && (y.max()+1 == y.min(d))) {
// upper bound has been adjusted
if ((y.max() <= dom->max()) && (dom->next() == NULL)) {
dom->max(y.max());
} else {
RangeList* p = dom;
RangeList* l = p->next();
while ((l != NULL) && (l->min() <= y.max())) {
p=l; l=l->next();
}
p->max(y.max());
if (p->next() != NULL)
p->next()->dispose(home);
p->next(NULL);
}
} else {
// Just copy the domain
ViewRanges<IntView> yr(y);
RangeList::overwrite(home,dom,yr);
}
}
forceinline void
IntTraceView::update(Space& home, IntTraceView y) {
Iter::Ranges::RangeList yr(y.dom);
RangeList::copy(home,dom,yr);
}
forceinline unsigned long long int
IntTraceView::slack(IntView x) {
return x.width()-1;
}
}}
// STATISTICS: int-trace
Gecode::Delta
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
Gecode::Int::IntTraceView::dom
RangeList * dom
Ranges capturing the variable domain.
Definition int-trace-view.hpp:40
Gecode::Int::IntTraceView::slack
static unsigned long long int slack(IntView x)
Return slack measure.
Definition int-trace-view.hpp:115
Gecode::Int::IntTraceView::ranges
RangeList * ranges(void) const
Give access to ranges.
Definition int-trace-view.hpp:66
Gecode::Int::IntTraceView::prune
void prune(Space &home, IntView y, const Delta &d)
Update duplicated view from view y and modification delta d.
Definition int-trace-view.hpp:71
Gecode::Int::IntTraceView::IntTraceView
IntTraceView(void)
Default constructor (initializes with no view).
Definition int-trace-view.hpp:57
Gecode::Int::IntTraceView::update
void update(Space &home, IntTraceView x)
Update during cloning.
Definition int-trace-view.hpp:109
Gecode::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::Int::IntView::min
int min(void) const
Return minimum of domain.
Definition int.hpp:58
Gecode::Int::IntView::width
unsigned int width(void) const
Return width of domain (distance between maximum and minimum).
Definition int.hpp:85
Gecode::Int::IntView::range
bool range(void) const
Test whether domain is a range.
Definition int.hpp:103
Gecode::Int::IntView::any
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition int.hpp:230
Gecode::Int::IntView::max
int max(void) const
Return maximum of domain.
Definition int.hpp:62
Gecode::Int::ViewRanges
Range iterator for integer views.
Definition view.hpp:54
Gecode::Iter::Ranges::RangeList
Range iterator for range lists
Definition ranges-rangelist.hpp:44
Gecode::RangeList
Lists of ranges (intervals).
Definition range-list.hpp:49
Gecode::RangeList::max
int max(void) const
Return maximum.
Definition range-list.hpp:168
Gecode::RangeList::min
int min(void) const
Return minimum.
Definition range-list.hpp:164
Gecode::RangeList::dispose
void dispose(Space &home, RangeList *l)
Free memory for all elements between this and l (inclusive).
Definition range-list.hpp:201
Gecode::RangeList::next
RangeList * next(void) const
Return next element.
Definition range-list.hpp:141
Gecode::RangeList::overwrite
static void overwrite(Space &home, RangeList *&r, Iter &i)
Overwrite rangelist r with ranges from range iterator i.
Definition range-list.hpp:228
Gecode::RangeList::copy
static void copy(Space &home, RangeList *&r, Iter &i)
Create rangelist r from range iterator i.
Definition range-list.hpp:215
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::Int
Finite domain integers.
Gecode
Gecode toplevel namespace
forceinline
#define forceinline
Definition config.hpp:187