You should read the files in the "examples" directory.
By making your example inherits from Script, you see that it has no
solution.
See the test.cpp attached file.
Vincent
2013/7/4 Christian Schulte <[email protected]>
> Please read MPG, at least the introductory material (especially Chapter 3
> answers your question). This mailing list assumes that you read the
> documentation and not that it is being spoon-fed to you on the users
> mailing list.****
>
> ** **
>
> Christian****
>
> ** **
>
> --****
>
> Christian Schulte, Professor of Computer Science, KTH,
> www.ict.kth.se/~cschulte/****
>
> ** **
>
> *From:* [email protected] [mailto:[email protected]] *On
> Behalf Of *manel askri
> *Sent:* Thursday, July 04, 2013 4:21 AM
> *To:* [email protected]; [email protected]; [email protected]
> *Subject:* [gecode-users] generation of a solution with success but no
> display at the console****
>
> ** **
>
> hi every one!****
>
> ** **
>
> i m new with gecode and this is my first model, it consists in displaying
> the following result :****
>
> ** **
>
> 2 19 22 12 10****
>
> 11 13 18 17 6****
>
> 21 16 1 7 20****
>
> 8 14 15 24 4****
>
> 23 3 9 5 25****
>
> CSTE_65:65 ****
>
> ** **
>
> so this is my code :****
>
> #include <gecode/int.hh>****
>
> #include <gecode/driver.hh>****
>
> #include <gecode/minimodel.hh>****
>
> #include <gecode/search.hh>****
>
> ** **
>
> using namespace Gecode;****
>
> ** **
>
> class E1 : public Space {****
>
> private :****
>
> ****
>
> static const int n =5;****
>
> protected:****
>
> ** **
>
> IntVarArray v1;****
>
> ** **
>
> IntVar v2;****
>
> ** **
>
> public:****
>
> ** **
>
> E1(void) : v1(*this, n*n,1,n*n),
> v2(*this,n*(n*n+1)/2,n*(n*n+1)/2){****
>
> ****
>
> distinct (*this, v1);****
>
> IntVarArgs rowArray (*this,n , 1, n);****
>
> IntVarArgs colArray (*this,n , 1, n);****
>
> IntVarArgs diag1Array (*this,n , 1, n);****
>
> IntVarArgs diag2Array (*this,n , 1, n);****
>
> ** **
>
> ****
>
> ****
>
> //IntVarArgs sumConstraints ;****
>
> ** **
>
> for (int i =0; i<n;i++)****
>
> {****
>
> for (int j=0; j<n; j++)****
>
> {****
>
> rowArray[j]= v1[i*n+1];***
> *
>
> colArray[j]= v1[j*n+1];***
> *
>
> }****
>
> ****
>
> // rel (*this, sum(rowArray),IRT_EQ, v2);****
>
> // rel ( *this , sum(colArray), IRT_EQ ,v2);****
>
> ** **
>
> linear( *this , rowArray, IRT_EQ, v2);****
>
> linear( *this , colArray, IRT_EQ, v2);****
>
> diag1Array[i]=v1[i * n + i];****
>
> diag2Array[i]= v1[i*n+n-i-1];****
>
> }****
>
> ** **
>
> //rel(*this , sum(diag1Array), IRT_EQ,v2);****
>
> //rel(*this, sum(diag2Array), IRT_EQ,v2);****
>
> ** **
>
> ****
>
> linear( *this , diag1Array, IRT_EQ, v2);****
>
> linear( *this , diag2Array, IRT_EQ, v2);****
>
> ** **
>
> ** **
>
> // post branching****
>
> branch(*this, v1, INT_VAR_SIZE_MIN(),
> INT_VAL_MIN());****
>
> ** **
>
> }****
>
> // search support****
>
> E1(bool share, E1& s) : Space(share, s) {****
>
> v1.update(*this, share, s.v1);****
>
> ****
>
> }****
>
> ** **
>
> virtual Space* copy(bool share) {****
>
> return new E1(share,*this);****
>
> }****
>
> ** **
>
> // print solution****
>
> void print(void) const {****
>
> for(int i = 0; i < n; i++) {****
>
> for(int j = 0; j < n; j++) {****
>
> v1[i * n + j];****
>
> std::cout << v1[i * n + j]
> << std::endl;****
>
> ****
>
> }****
>
> }****
>
> }****
>
> ** **
>
> };****
>
> // main function****
>
> int main(int argc, char* argv[]) {****
>
> // create model and search engine****
>
> E1* m = new E1;****
>
> DFS<E1> e(m);****
>
> delete m;****
>
> // search and print all solutions****
>
> while (E1* s = e.next()) {****
>
> s->print(); delete s;****
>
> }****
>
> return 0;****
>
> }****
>
> ** **
>
> my problem is that when i generat the solution i do it successfly but when
> i use the command prompt to execute the executable the console displays
> nothing****
>
> so please if any one have any idea obout this i will be so greatful ****
>
> ** **
>
> thanks very much for any help****
>
> ** **
>
> ASKRI Manel****
>
> ** **
>
> ****
>
> ** **
>
> ** **
>
> _______________________________________________
> Gecode users mailing list
> [email protected]
> https://www.gecode.org/mailman/listinfo/gecode-users
>
>
--
Vincent Barichard Université d'Angers (LERIA)
Tel: 02 41 73 52 06 Département Informatique
Fax: 02 41 73 50 73 H203
#include <gecode/int.hh>
#include <gecode/driver.hh>
#include <gecode/minimodel.hh>
#include <gecode/search.hh>
using namespace Gecode;
class E1 : public Script {
private :
static const int n =5;
protected:
IntVarArray v1;
IntVar v2;
public:
E1(const Options&) : v1(*this, n*n,1,n*n), v2(*this,n*(n*n+1)/2,n*(n*n+1)/2){
distinct (*this, v1);
IntVarArgs rowArray (*this,n , 1, n);
IntVarArgs colArray (*this,n , 1, n);
IntVarArgs diag1Array (*this,n , 1, n);
IntVarArgs diag2Array (*this,n , 1, n);
//IntVarArgs sumConstraints ;
for (int i =0; i<n;i++)
{
for (int j=0; j<n; j++)
{
rowArray[j]= v1[i*n+1];
colArray[j]= v1[j*n+1];
}
// rel (*this, sum(rowArray),IRT_EQ, v2);
// rel ( *this , sum(colArray), IRT_EQ ,v2);
linear( *this , rowArray, IRT_EQ, v2);
linear( *this , colArray, IRT_EQ, v2);
diag1Array[i]=v1[i * n + i];
diag2Array[i]= v1[i*n+n-i-1];
}
//rel(*this , sum(diag1Array), IRT_EQ,v2);
//rel(*this, sum(diag2Array), IRT_EQ,v2);
linear( *this , diag1Array, IRT_EQ, v2);
linear( *this , diag2Array, IRT_EQ, v2);
// post branching
branch(*this, v1, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
}
// search support
E1(bool share, E1& s) : Script(share, s) {
v1.update(*this, share, s.v1);
v2.update(*this, share, s.v2);
}
virtual Space* copy(bool share) {
return new E1(share,*this);
}
// print solution
void print(std::ostream& os) const {
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
v1[i * n + j];
os << v1[i * n + j] << std::endl;
}
}
}
};
// main function
int main(int argc, char* argv[]) {
// // create model and search engine
// E1* m = new E1;
// DFS<E1> e(m);
// delete m;
// // search and print all solutions
// while (E1* s = e.next()) {
// s->print(); delete s;
// }
Options opt("Test Problem");
opt.parse(argc,argv);
Script::run<E1,DFS,Options>(opt);
return 0;
}
_______________________________________________
Gecode users mailing list
[email protected]
https://www.gecode.org/mailman/listinfo/gecode-users