[gecode-users] Reducing a view domain during propagation
Martin Mann
mmann at informatik.uni-freiburg.de
Thu Jun 20 00:38:50 CEST 2013
Hi Amina,
years back I wrote the attached std::set range iterator. you can use it
with any of the IntView shrink function members like narrow etc.
something like
////////////
// setup iterator
GC_StlSetRangeIterator supportIter(&support);
// prune the domain to supported values
GECODE_ME_CHECK(x0.narrow_r(home, supportIter, false));
////////////
the iterator implementation is obviously not the nices nor best source
code possible but might be a starting point.. as I said, wrote it years
ago and didnt touched it since that time.
Hope it helps.
Best,
Martin
Am 19.06.2013 20:00, schrieb Christian Schulte:
> Read Chapter 25 in MPG and then you will have to implement a Gecode-style
> iterator that iterates over the values of set<int>.
>
>
>
> Best
>
> Christian
>
>
>
> --
>
> Christian Schulte, www.ict.kth.se/~cschulte/
>
>
>
> From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
> Of Mailing List Email
> Sent: Wednesday, June 19, 2013 7:49 PM
> To: Amina Kemmar
> Cc: users at gecode.org
> Subject: Re: [gecode-users] Reducing a view domain during propagation
>
>
>
> Sorry, that's bounds consistency.
>
> On 19 Jun 2013 19:23, "Mailing List Email" <mailinglistx at gmail.com> wrote:
>
> Try x1.le(max(s)), x1.ge(min(s)) for domain consistency.
>
> On 19 Jun 2013 19:17, "Amina Kemmar" <kemmar.amina at gmail.com> wrote:
>
> Hi,
>
> In my propagate function that I implemented, I want to reduce the domain of
> an IntView x1 to a fix set of values given by the strucure set<int> s, how
> can I do this?
>
> Thank you for your help.
> Regards.
>
>
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users
>
>
>
>
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users
>
--
Dr. Martin Mann, Postdoc
Bioinformatics - Inst. of Computer Science
Albert-Ludwigs-University Freiburg
Tel: ++49-761-203-8254
Fax: ++49-761-203-7462
http://www.bioinf.uni-freiburg.de/~mmann/
-------------- next part --------------
/*
* Main authors:
* Martin Mann http://www.bioinf.uni-freiburg.de/~mmann/
*
* Contributing authors:
* Sebastian Will http://www.bioinf.uni-freiburg.de/~will/
*
* Copyright:
* Martin Mann, 2007
*
* This file is part of the CPSP-tools package:
* http://www.bioinf.uni-freiburg.de/sw/cpsp/
*
* See the file "LICENSE" for information on usage and
* redistribution of this file, and for a
* DISCLAIMER OF ALL WARRANTIES.
*
*/
#include "GC_StlSetRangeIterator.h"
GC_StlSetRangeIterator::GC_StlSetRangeIterator() :
data(NULL), noFurtherRange(true)
{
getNextRange();
}
GC_StlSetRangeIterator::GC_StlSetRangeIterator(const std::set<int>* data_) :
data(data_), noFurtherRange(false)
{
if (data != NULL)
actElem = data->begin();
getNextRange();
}
GC_StlSetRangeIterator::~GC_StlSetRangeIterator()
{
}
void
GC_StlSetRangeIterator::getNextRange() {
if (data==NULL || actElem == data->end()) {
noFurtherRange = true;
return;
}
// find next range
nextMin = *actElem;
nextMax = nextMin;
// build up new upper bound until end of set reached or gap in
// sequence
while ( (++actElem != data->end()) && (*actElem == (nextMax+1))) {
nextMax++;
}
}
-------------- next part --------------
/*
* Main authors:
* Martin Mann http://www.bioinf.uni-freiburg.de/~mmann/
*
* Contributing authors:
* Sebastian Will http://www.bioinf.uni-freiburg.de/~will/
*
* Copyright:
* Martin Mann, 2007
*
* This file is part of the CPSP-tools package:
* http://www.bioinf.uni-freiburg.de/sw/cpsp/
*
* See the file "LICENSE" for information on usage and
* redistribution of this file, and for a
* DISCLAIMER OF ALL WARRANTIES.
*
*/
#ifndef GC_STLSETRANGEITERATOR_HH_
#define GC_STLSETRANGEITERATOR_HH_
#include <set>
#include <iostream>
/**
* Provides a constant Gecode RangeIterator of a std::set<int> that
* calculates the ranges on demand.
*/
class GC_StlSetRangeIterator
{
private:
const std::set<int>* data;
std::set<int>::const_iterator actElem;
bool noFurtherRange;
int nextMin, nextMax;
//! searchs for the next range and sets the inner members
void getNextRange();
public:
GC_StlSetRangeIterator();
GC_StlSetRangeIterator(const std::set<int>* data_);
virtual ~GC_StlSetRangeIterator();
void init(const std::set<int>* const data_) {
data = data_;
noFurtherRange = false;
if (data != NULL)
actElem = data->begin();
getNextRange();
}
bool operator()(void) const { return !noFurtherRange; }
void operator++(void) { getNextRange(); }
int min(void) const { return nextMin; }
int max(void) const { return nextMax; }
unsigned int width(void) { return nextMax-nextMin+1; }
};
#endif /*GC_STLSETRANGEITERATOR_HH_*/
More information about the users
mailing list