[gecode-users] users Digest, Vol 124, Issue 6

Christian Schulte cschulte at kth.se
Mon Feb 1 21:32:02 CET 2016


Hi Juan Carlos,

 

I think the “solution” suggested by me was a little bit too elegant, in fact it is buggy and that’s why you experience segfaults… Reminds of an Einstein quote: Everything should be made as simple as possible, but not simpler.

 

The problem is as follows: variables in Gecode belong to just one space and they are deleted when the space is deleted. However in the constrain() function a new propagator is created with both variables from the *this space as well as from the space for the so-far best solution b. Now what can happen is that b might already be deleted while *this is still alive: hence the access to variables which are already did and kaboom: segfault!

 

The problem is easy to fix, though: when the constrain() function is called you create new variables, one for each variable from b, but now in *this! The variables in b must be assigned, so creating new variables in *this must happen with the variables assigned to the value of the respective variable in b.

 

The code should look this, roughly:

               IntVarArgs bo(*this, mycpSolver.objectives.size(), Int::Limits::min, Int::Limits::max);

               for (int i=0; i< mycpSolver.objectives.size(), i++)

                 rel(*this, bo[i], IRT_EQ, mycpSolver.objectives[i].val());

               rel(*this, objectives, IRT_LE, bo);

 

Sorry for not thinking about this in the first place. I’ll add a tip and a warning in MPG.

 

Cheers

Christian

 

--

Christian Schulte,  <http://www.gecode.org/~schulte> www.gecode.org/~schulte 

Professor of Computer Science, KTH,  <mailto:cschulte at kth.se> cschulte at kth.se

Expert Researcher, SICS,  <mailto:cschulte at sics.se> cschulte at sics.se

 

From: Juan Carlos Hernandez [mailto:jchernandez.madrid at gmail.com] 
Sent: Monday, February 1, 2016 06:25 PM
To: Christian Schulte <cschulte at kth.se>
Cc: Alexander Schiendorfer <alexander.schiendorfer at informatik.uni-augsburg.de>; users at gecode.org
Subject: Re: [gecode-users] users Digest, Vol 124, Issue 6

 

Dear Alex and Christian,

 

thanks a lot! A very elegant solution - it works well, but I am now battling with two problems

 

1. I get a segmentation fault when I try to run it in parallel mode (say, using 8 threads). The error happens irregularly, but more often when I increase the thread count. Here is what my constrain function looks like for a maximization problem

 

virtual void constrain(const Space& _b){

 

const cpSolver& mycpSolver = static_cast<const cpSolver&>(_b);

rel(*this, objectives, IRT_GR, mycpSolver.objectives);

 

}

 

Since this does not really look like the other examples in the Gecode manual, I guess that it is not correct. But I was unable to come up with any other solution that rel would accept (that is, for which there is a matching version of rel). 

 

2. Ideally, I would like to have more than two objectives and have the search to first try to maximize the first objective, then the second, etc. But I do not manage, not matter which variable selection rule I use. Typically, I get a little advancement in the first objective (say, it goes from 0 to 1, and perhaps to two), and then the search makes progress on the third or fourth objective in order.

 

Thanks,

 

JC

 

 

2016-01-29 12:15 GMT+01:00 Christian Schulte <cschulte at kth.se <mailto:cschulte at kth.se> >:

Alex is spot on here: but let me expand a little.

You might have used the cost() member function for B&B. However the cost()
member function is just implemented in terms of the constrain() member
function. So what I would do is the following:
 - Have a integer variable array cost containing the two cost variables you
have in mind.
 - implement a constrain(const Space& _b) member function: _b refers to the
so-far best solution. Cast this to your script type, say b. Then this just
posts
        rel(*this, cost, IRT_LQ, b.cost);
   This enforces that this->cost is lexicographically smaller then the so
far best cost b.cost.

That's it. More on the  constrain() function you can find in Chapter 2 of
MPG.

Cheers
Christian

--
Christian Schulte, www.gecode.org/~schulte <http://www.gecode.org/~schulte> 
Professor of Computer Science, KTH, cschulte at kth.se <mailto:cschulte at kth.se> 
Expert Researcher, SICS, cschulte at sics.se <mailto:cschulte at sics.se> 



-----Original Message-----
From: users-bounces at gecode.org <mailto:users-bounces at gecode.org>  [mailto:users-bounces at gecode.org <mailto:users-bounces at gecode.org> ] On Behalf
Of Alexander Schiendorfer
Sent: Friday, January 29, 2016 12:06 PM
To: users at gecode.org <mailto:users at gecode.org> 
Subject: Re: [gecode-users] users Digest, Vol 124, Issue 6

Hi Juan,

it seems to me that you're searching for lexicographic branch-and-bound.
There is a global constraint lex_lesseq that you might want to consider for
posting in the constrain method of a Space.

Cheers,
Alex

On 29.01.2016 12:00, users-request at gecode.org <mailto:users-request at gecode.org>  wrote:
> Send users mailing list submissions to
>       users at gecode.org <mailto:users at gecode.org> 
>
> To subscribe or unsubscribe via the World Wide Web, visit
>       http://www.gecode.org/cgi-bin/mailman/listinfo/users
> or, via email, send a message with subject or body 'help' to
>       users-request at gecode.org <mailto:users-request at gecode.org> 
>
> You can reach the person managing the list at
>       users-owner at gecode.org <mailto:users-owner at gecode.org> 
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of users digest..."
>
>
> Today's Topics:
>
>     1. Best way to implement multi-criterion optimization     in Gecode?
>        (Juan Carlos Hernandez)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 28 Jan 2016 12:30:54 +0100
> From: Juan Carlos Hernandez <jchernandez.madrid at gmail.com <mailto:jchernandez.madrid at gmail.com> >
> To: users at gecode.org <mailto:users at gecode.org> 
> Subject: [gecode-users] Best way to implement multi-criterion
>       optimization    in Gecode?
> Message-ID:
>       <CAFd=f3EAU+XPqJo02KPT9SWibPjxkifw-F2so-4mE+x4Kv7Q5A at mail.gmail.com <mailto:f3EAU%2BXPqJo02KPT9SWibPjxkifw-F2so-4mE%2Bx4Kv7Q5A at mail.gmail.com> >
> Content-Type: text/plain; charset="utf-8"
>
> Hi everyone,
>
>
> I am trying to use Gecode to solve a multi-criterion problem
>
>
> minimize        (F1(x,z), F2(x,z) )
>
> subject to       constraints on x,z
>
>
> The objectives are ordered in order of importance, so I would like to
> first solve the problem P1
>
>
> minimize        F1(x,z)
>
> subject to       original constraints on x,z
>
>
> and then consider the modified problem P2
>
>
> minimize        F2(x,z)
>
> subject to      original constraints on x,z
>
>                          F1(x,z) = F1opt
>
>
> where F1opt is the optimal value of P1.
>
>
> What is the most efficient way to implement this in Gecode?
>
>
>
> I am now doing two completely separate searches, in the sense that I
> create a new Space and run BAB on it for each of the problems. I am
> sure that this cannot be the most efficient way of dealing with the
> problem, but am unable to figure out how to do it "the right way".
> Essentially, when solving P2 I should be able to make use of the work done
while solving P1...
>
>
> Any feedback is very much appreciated!
>
>
> Thanks,
>
> JC
> -------------- next part -------------- An HTML attachment was
> scrubbed...
> URL:
> <http://www.gecode.org/pipermail/users/attachments/20160128/06e6ff75/a
> ttachment-0001.html>
>
> ------------------------------
>
> _______________________________________________
> Gecode users mailing list
> users at gecode.org <mailto:users at gecode.org> 
> https://www.gecode.org/mailman/listinfo/gecode-users
>
>
> End of users Digest, Vol 124, Issue 6
> *************************************

--
Alexander Schiendorfer, M.Sc.
Institute for Software & Systems Engineering Raum 3043, Gebäude N
Universität Augsburg

Web:
http://www.informatik.uni-augsburg.de/lehrstuehle/swt/se/staff/aschiendorfer
/
Tel.: +49 (821) 598 - 2196 <tel:%2B49%20%28821%29%20598%20-%202196> 
E-Mail: alexander.schiendorfer at informatik.uni-augsburg.de <mailto:alexander.schiendorfer at informatik.uni-augsburg.de> 


_______________________________________________
Gecode users mailing list
users at gecode.org <mailto:users at gecode.org> 
https://www.gecode.org/mailman/listinfo/gecode-users


_______________________________________________
Gecode users mailing list
users at gecode.org <mailto:users at gecode.org> 
https://www.gecode.org/mailman/listinfo/gecode-users

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20160201/1f6492b6/attachment-0001.html>


More information about the users mailing list