[gecode-users] Avoid the appearance of several simultaneous values
Christian Schulte
cschulte at kth.se
Sat Dec 28 14:50:41 CET 2013
Hi,
This is not really a Gecode-specific question but a general constraint modeling question, so you might want to turn elsewhere for help.
Christian
--
Christian Schulte, www.ict.kth.se/~cschulte
From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf Of inspecteur
Sent: Tuesday, December 24, 2013 03:59 PM
To: users at gecode.org
Subject: [gecode-users] Avoid the appearance of several simultaneous values
Hi
Sorry for my english, I'm french and beginner on gecode.
I want to create an array of integers (4 * 4) with the constraints:
1) Possible values between 1 and 6
2) no repeating values on lines
3) The values 3 and 4 must not be on the same line
4) No more than 2 times the same value on each column
I stumble on the constraint number 3)
If someone could put me on the track
Here is my code
class CarreMagique : public Script {
private:
const int n;
IntVarArray carreMag;
public:
CarreMagique(const SizeOptions& opt)
: n(opt.size()), carreMag(*this,n*4,1,6) {
Matrix<IntVarArray> tab(carreMag, n, 4);
IntVarArgs d1(4);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++) {
d1[j]=tab(i,j);
}
distinct(*this, d1);
}
IntVarArgs d2(n);
for (int j = 0; j < 4; j++) {
for (int i = 0; i < n; i++) {
d2[i]=tab(i,j);
}
count(*this, d2, IntSet(0,2), IntArgs::create(6,1,1));
}
}
branch(*this, carreMag, INT_VAR_NONE(), INT_VAL_SPLIT_MIN());
}
CarreMagique(bool share, CarreMagique& s) : Script(share,s), n(s.n) {
carreMag.update(*this, share, s.carreMag);
}
virtual Space* copy(bool share) {
return new CarreMagique(share,*this);
}
virtual void print(std::ostream& os) const {
// Pour acceder au tableau comme à une matrice
Matrix<IntVarArray> m(carreMag, n, 4);
for (int i = 0; i < n; i++) {
os << "\t";
for (int j = 0; j < 4; j++) {
os.width(2);
os << m(i,j) << " ";
}
os << std::endl;
}
}
};
int main(int argc, char* argv[]) {
SizeOptions opt("CarreMagique");
opt.size(4);
Script::run<CarreMagique,DFS,SizeOptions>(opt);
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20131228/06bfac15/attachment.html>
More information about the users
mailing list