[gecode-users] help--Question about Channel constraints

Christian Schulte cschulte at kth.se
Mon Aug 10 10:48:06 CEST 2009


Your copy constructor is wrong: the second update should update from s.mun
and not from s.num.

 

Christian

 

--

Christian Schulte, www.ict.kth.se/~cschulte/

 

From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Kayler Yao
Sent: Monday, August 10, 2009 10:33 AM
To: users at gecode.org
Subject: [gecode-users] help--Question about Channel constraints

 

hi,

 

     A question came out when i used Channel constraints. One type of
Channel constrains is for two integer variable arrays x and y of same size,
for example 

  "  

   channel(home, x, y); 

    posts the constraint
                      Xi   = j  <==>  Yj  = i    for 0 ? i, j < |x| 

"

 When i made a test , the result was not what it should to be. 

 My tools are VS2008,Gecode 3.1.0. My test is

 

 "

#include <gecode/driver.hh>
#include <gecode/int.hh>

using namespace Gecode;

 

class Fournum : public Script
{
protected:

  IntVarArray num;
  IntVarArray mun;


public:
 Fournum(const Options& opt) : num(*this,3,0,2),mun(*this,3,0,2)
 {


  channel(*this,num,mun);
  branch(*this, num, INT_VAR_NONE, INT_VAL_MIN);

  branch(*this,mun, INT_VAR_NONE, INT_VAL_MIN);
 }

 virtual void
 print(std::ostream& os) const
 {
    os << "\t" << num<<"-------"<<mun<<std::endl;
 }

  Fournum(bool share, Fournum& s) : Script(share,s) 
 {
       num.update(*this, share, s.num);
       mun.update(*this,share,s.num);
    }

  virtual Space*  copy(bool share)
 {
   return new Fournum(share,*this);
 }


};

 

int main()
{
 Options opt("\tJust for test");
 opt.solutions(0);
 opt.iterations(20000);
 Script::run<Fournum,DFS,Options>(opt);
 system("pause");
 return 0;
}

"

  The result is

       {0, 1, 2}-------{0, 1, 2}
       {0, 2, 1}-------{0, 2, 1}
       {1, 0, 2}-------{1, 0, 2}
       {1, 2, 0}-------{1, 2, 0}
       {2, 0, 1}-------{2, 0, 1}
       {2, 1, 0}-------{2, 1, 0}

You can see that the fourth and the fifth are not right . Who can tell me
why ? 

 

Look forward to your reply!

 

Kayler.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ps.uni-sb.de/pipermail/users/attachments/20090810/8540d5d9/attachment.htm>


More information about the gecode-users mailing list