[gecode-users] Copying spaces
Mikael Zayenz Lagerkvist
zayenz at kth.se
Wed Feb 4 09:18:56 CET 2009
Hi,
You shouldn't use the copy-function directly, it is only part of the
process of cloning a space. To make a clone of a space you should call
the clone-member in Space. Thus, you should change
Space *copySpace = space->copy(true);
to
Space *copySpace = space->clone(true);
Cheers,
Mikael
On Wed, Feb 4, 2009 at 9:06 AM, Malcolm Ryan <malcolmr at cse.unsw.edu.au> wrote:
> What is the correct way to create a copy of a space? I'm confused by
> the behaviour of the following example:
>
> class MySpace: public Space {
> private:
> IntVar x;
> public:
> MySpace() : Space(), x(this, 1, 4) {}
>
> MySpace(bool share, MySpace& old) : Space(share, old) {
> x.update(this, share, old.x);
> }
>
> Space* copy(bool share) {
> return new MySpace(share, *this);
> }
>
> virtual ~MySpace() {}
> };
>
> void CompletePlanVarTest::testUpdate0() {
>
> MySpace *space = new MySpace();
> cout << "Status: " << space->status() << endl;
>
> Space *copySpace = space->copy(true);
> cout << "Status: " << copySpace->status() << endl;
> }
>
> The output is:
>
> Status: 1
> Status: 0
>
> That is the first space is solved (because it has no branchings) but
> the second space has failed. Why?
>
> Is this not the right way to copy a space? Or have I implemented the
> space wrongly?
>
> Malcolm
>
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users
>
--
Mikael Zayenz Lagerkvist, http://www.ict.kth.se/~zayenz/
More information about the gecode-users
mailing list