Dear Christian,

     Here are the codes. Many thanks.

Zichen

On Tue, Dec 16, 2014 at 11:04 PM, Christian Schulte <cschu...@kth.se> wrote:

> Hi Zichen,
>
>
>
> MPG does not make a promise here: it says "the solution might not be found
> again" but it does not give you a guarantee. But for your example I would
> have to know how nqueen_rbs looks like.
>
>
>
> Cheers
>
> Christian
>
>
>
> --
>
> Christian Schulte, Professor of Computer Science, KTH,
> www.gecode.org/~schulte/
>
>
>
> *From:* users-boun...@gecode.org [mailto:users-boun...@gecode.org] *On
> Behalf Of *Zhu Zichen's cse
> *Sent:* Tuesday, December 16, 2014 3:43 PM
> *To:* users@gecode.org
> *Subject:* [gecode-users] A problem for restart
>
>
>
> Dear all,
>
>
>
> I met a problem when using ​restart in Gecode.
>
>
>
> I simply use restart to find all solutions for 4-Queens while use the same
> heuristic after each restart:
>
> ./nqueen_rbs -restart geometric -restart-scale 2 -restart-base 10 -nogoods
> 1 -nogoods-limit 128 4
>
>
>
> But I got into an infinite loop which keeps printing the first solution.
>
>
>
> According to the newest version of document "MPG" (page 160), the master()
> function posts no-goods when the a solution is found. This means the same
> solution will not be found again.
>
>
>
> I rewrite the master() function by changing the last line "return true"
> into "return false", now all solutions are generated without trapped into a
> loop.
>
>
>
> I am wondering why the infinite loop happens and whether Gecode has truly
> recorded previous solutions as nogoods as the document says.
>
>
>
> Thanks for help.
>
>
>
> Zichen
>
> [image: Image removed by sender.]
>
#include <gecode/int.hh>
#include <gecode/search.hh>
#include <gecode/driver.hh>
#include <gecode/minimodel.hh>

using namespace Gecode;

class NQueen : public Script {
protected:
	IntVarArray q;
	const SizeOptions& opt;
public:
	NQueen(const SizeOptions& _opt) : q(*this, _opt.size(), 1, _opt.size()), opt(_opt) {
		distinct(*this, q);
		for (int i = 0; i < opt.size(); i++){
			for (int j = i + 1; j < opt.size(); j++){
				rel(*this, abs(q[i] - q[j]) != j - i);
			}
		}
		branch(*this, q, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
	}
	NQueen(bool share, NQueen& s) : Script(share, s), opt(s.opt) {
		q.update(*this, share, s.q);
	}
	virtual Space* copy(bool share) {
		return new NQueen(share, *this);
	}
	virtual void print(std::ostream& os) const {
		os << q << std::endl;
	}
};

int main(int argc, char* argv []){
	SizeOptions opt("NQueen");
	opt.size(4);
	opt.solutions(0);
	opt.parse(argc, argv);
	//Script::run<NQueen, DFS, SizeOptions>(opt);
	Search::Options o;
	o.cutoff = Search::Cutoff::geometric(10, 1.5);
	NQueen* q = new NQueen(opt);
	RBS<DFS, NQueen> e(q, o);
	delete q;
	// Use the search engine to find all solutions
	while (NQueen*s = e.next()) {
		s->print(std::cout); delete s;
	}
	//getchar();
	//Script::run<NQueen, RBS, SizeOptions>(opt);
	return 0;
}
_______________________________________________
Gecode users mailing list
users@gecode.org
https://www.gecode.org/mailman/listinfo/gecode-users

Reply via email to