[gecode-users] very odd bug in small program

Mikael Zayenz Lagerkvist zayenz at gmail.com
Mon Sep 27 15:21:52 CEST 2010


Hi,

This happens because matrix stores a copy of it's array. For variable-arrays
it works as expected, since copy construction shares the elements. For
argument arrays, it doesn't. Maybe we should consider using references
instead of copies for matrices...

For your current problem, you could use the Matrix initialization and then
use the get_array member function to get a copy of the contents.

/Mikael

On Mon, Sep 27, 2010 at 3:08 PM, Christian Schulte <cschulte at kth.se> wrote:

> Denys,
>
> I also believed that this was the case: it is for variable arrays but not
> for argument arrays (is that correct?).
>
> Mikael: can you shed some light on this, please?
>
> Christian
>
> --
> Christian Schulte, www.ict.kth.se/~cschulte/
>
>
> -----Original Message-----
> From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
> Of Denys Duchier
> Sent: Monday, September 27, 2010 1:21 PM
> To: users at gecode.org
> Subject: Re: [gecode-users] very odd bug in small program
>
> Chris Mears <chris.mears at monash.edu> writes:
>
> > I think the problem is that the Matrix constructor copies the IntArgs
> > array, so that when you modify MC you aren't changing C itself.
>
> meh! I expected a matrix to be a view of the same underlying model, not
> a copy. me not likey!
>
> > (Whether it ought to do this or not is another question.)  One
> > solution is to instead write:
> >
> >   IntArgs C(4*4, 7, 1, 3, 4, 8, 2, 5, 1, 4, 3, 7, 2, 3, 1, 6, 8);
>
> ok, thank you, but... (sigh)
>
> --Denys
>
> _______________________________________________
> 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
>



-- 
Mikael Zayenz Lagerkvist, http://www.ict.kth.se/~zayenz/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20100927/f611425d/attachment.htm>


More information about the users mailing list