I am writing constraints for the following problem
There are seven friends A,B,C,D,E,F and G in a seven-floor building. The ground floor is no. 1, the floor above it is no.2 and so on.
E does not live on an even numbered floor. G does not live on the topmost floor. Only one person lives between E and G. A does not live on even numbered floor and does not live below F.D does not live immediately above or immediately below G. There two floors between D and E. Both B and C live on even-numbered floor. G and C live in between the two floors. No one shares same floor. F lives on floor number 5.
This is the constraints I have written for the the problem
constraint value {a>0; a<8;
b>0; b<8;
c>0; c<8;
d>0; d<8;
e>0; e<8;
f>0; f<8;
g>0; g<8;
}
constraint A { a%2 !=0; a > f; }
constraint B { b%2 == 0;}
constraint C { c%2 ==0;}
constraint D { soft d != g+1; soft d != g-1;}
constraint E { e%2 !=0;}
constraint F { f == 5;}
constraint G { g != 7;}
constraint E_G { soft e == g+1; soft e == g-1;}
constraint D_E { soft e == d+2; soft e == d-2;}
When I ran the simulation and checked the output manually its wrong.
I quote my output here.
It would help to put the constraints in the same order of your description.
I think there is some confusion with your between constraints. If “only one person lives between E and G”, do you mean to say “there is one person living in between E and G”? Then the difference between E and G’s floors should be 2, not 1. There is no constraint for “G and C live in between the two floors” and I don’t know which two floors.
Also, do not use soft constraints here. Any mistakes and they may get silently discarded. Just use logical OR/AND
//Constraining values from 1 to7
constraint value {a>0; a<8;
b>0; b<8;
c>0; c<8;
d>0; d<8;
e>0; e<8;
f>0; f<8;
g>0; g<8;
}
//No one shares same floor
constraint uinque_value { unique {a,b,c,d,e,f,g};}
//E does not live on an even numbered floor
constraint E { e%2 !=0;}
//G does not live on the top most floor
constraint G { g != 7;}
//Only one person lives between E and G
constraint E_G { e-g == 2 || g-e == 2;}
//A does not live on even numbered floor and does not live below F
constraint A { a%2 !=0; a > f; }
//D does not live immediately above or immediately below G
constraint D_G { d-g != 1 || g-d != 1;}
// There two floors between D and E
constraint D_E { e-d == 3 || d-e == 3;}
// Both B and C live on even-numbered floor.
constraint B { b%2 == 0;}
constraint C { c%2 ==0;}
// F lives on floor number 5
constraint F { f == 5;}
//G and C live in between the two floors.
constraint G_C { g-c == 1 || c-g == 1;}
I still don’t get the statement “G and C live in between the two floors”
P.S. That was mentioned in the problem statement.