[gecode-users] Multiple separate searches
Milton Friedman
aemhm1 at hotmail.com
Fri Apr 20 14:16:14 CEST 2012
Christian Schulte <cschulte at ...> writes:
>
> Hi,
>
> Multiple engines are not only allowed they are in fact normal
>
> From what you describe I can venture a guess: you pass the solution s from
> the first engine to the second, configure the snd engine to not take a clone
> of s and then delete s? Is that the case? That could explain the bug: both
> the snd engine as well as your code delete s, hence the kaboom!
>
> If that is not the case, maybe just sketch in more detail what you are
> doing.
>
> Cheers
> Christian
>
> --
> Christian Schulte, www.ict.kth.se/~cschulte/
>
> > -----Original Message-----
> > From: users-bounces at ...
> [mailto:users-bounces at ...] On
> > Behalf Of Milton Friedman
> > Sent: Friday, April 20, 2012 6:37 AM
> > To: users at ...
> > Subject: [gecode-users] Multiple separate searches
> >
> > I'm working on a problem with many cases, encoded into an IntArray A, of
> which
> > some branchings are valid according to a set of constraints, and for each
> of
> > those valid cases, another IntArray B describes a more detailed analysis,
> subject
> > to other constraints.
> >
> > I only need one solution of B for each case.
> >
> > So what I think I should do in Gecode, is create a loop down in main that
> runs
> > DFS on Space/model IntArray A, and for each sequential solution A that
> returns,
> > call a different instance of DFS on Space/model IntArray B DFS to get
just
> one
> > solution.
> > Does that sound like a reasonable approach?
> >
> > When I tried to do this, I ran into a problem.
> > The MwG document explains how to loop on DFS, using s<-e.next to find the
> > next space, etc, and I've done that for another application.
> > But when I tried to feed DFS the new s, I got an error in Gecode's DFS
> destructor
> > on the line where it's trying to delete e (called by the end bracket of my
> loop).
> > So is it legal to have multiple separate DFS engines?
> > Do you need to delete them when you're creating the next one?
> > (delete e didn't work in my code any better than in the destructor).
> > I don't see any examples of this on the Gecode examples page...
> > they all look like single calls to the search engine.
> >
> > Any thoughts? Am I going about this w/the right approach?
> > Thanks,
> > -Milt
> >
> >
> > _______________________________________________
> > Gecode users mailing list
> > users at ...
> > https://www.gecode.org/mailman/listinfo/gecode-users
>
Hi Christian...Thanks for responding.
You're right!...I must be doing one too many delete s
When I remove one, it works, though I'm not sure exactly why.
The error I get in Visual Studio (Windows7) is that it breaks in DFS.hpp with:
Unhandled exception at 0x00643917 (GecodeSearch-3-7-1-d-x86.dll)
in ModelsAandB.exe: 0xC0000005:
Access violation reading location 0xfeeefeee.
To simplify communication, I hardcoded the outer-loop of ModelA in C++
(simple simulated branching with easy constriants),
so I'm only calling Gecode for ModelB.
I put the call to DFS for modelB into a function "DoOneDFS"
The call to DoOneDFS looks like: DoOneDFS(argc,argv,"ModelB")
and it's inside a simple loop in main.
So there's no s or deleting s outside this function...
only this function calls Gecode, and this function is called repeatedly.
The function code is:
void DoOneDFS(int argc, char* argv[],const char* ModelName){
SizeOptions optModel(ModelName);
optModel.iterations(1);
optModel.size(3);
optModel.parse(argc,argv);
ModelB* s = new ModelB(optModel);
//call once
DFS<ModelB> e(s);
bool wasBranch = SS_BRANCH==s->status();
bool wasSolved = SS_SOLVED==s->status();
bool wasFailed = SS_FAILED==s->status();
//loop while wasBranch and not null, wasSolved or wasFailed
while (wasBranch && s) {
cout<<"Branch"<<endl;
s->myprint();
delete s; //in while loop...deletes space we branched from
//calls Gecode...then done with this next space
Packing2DRectTopology* s = e.next();
wasBranch = SS_BRANCH==s->status();
wasSolved = SS_SOLVED==s->status();
wasFailed = SS_FAILED==s->status();
}
if (wasSolved){ //record it
cout<<"Solved"<<endl;
s->myprint();
s->mydebugprint();
system("PAUSE");
}
else if (wasFailed){ //ignore it
//system("PAUSE");
}
else { //unexpected
cout<<"Shouldn't arrive here. status: "<<s->status()<<endl;
system("PAUSE");
}
//delete s; //<<<---Works if commented out; fails otherwise...why?
}
Thanks for your help
-Milt
More information about the users
mailing list