-- Guido Tack http://www.csse.monash.edu/~guidot/
On 20/04/2012, at 10:16 PM, Milton Friedman wrote: > 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? > } > When you construct DFS from a space, DFS takes ownership of that space, unless you give it a search options argument where you set clone to false (see the reference documentation for the DFS class). So here it depends on whether s is still the initial space (in which case you mustn't delete it) or a space returned from e.next (in which case you must delete it). But that's not the main problem with the code above: a space returned from e.next() is always NULL or SS_SOLVED. What you probably want to do is to implement your own Brancher that runs a DFS internally. There is code that does more or less that in gecode/flatzinc/flatzinc.cpp in the current svn trunk, it's called "AuxVarBrancher". Perhaps that can help you to get started. Cheers, Guido
_______________________________________________ Gecode users mailing list users@gecode.org https://www.gecode.org/mailman/listinfo/gecode-users