Queen Placement IIb (chess5b)

Run LPL Code  ,  PDF Document

Problem

This model is an alternative formulation of the model chess5.


Listing 1: The Complete Model implemented in LPL [2]
model chess5b "Queen Placement IIb"; 
  set i,j := [1..8]; 
  integer variable x{i} [1..#i]; 
  constraint 
    D: Alldiff({i} x); 
    S: Alldiff({i} (x+i)); 
    T: Alldiff({i} (x-i)); 
  solve; 
  binary parameter X{i,j} := if(j=x[i],1); 
  Draw.Scale(50,50); 
  {i,j} Draw.Rect(i,j,1,1,if((i+j)%2,0,1),0); 
  {i,j|X} Draw.Circle(j+.5,i+.5,.3,5); 
end

An equivalent model is the following:

model chess5b "The Queen Problem"; 
  set i,j := [1..8]; 
  alldiff variable x{i} [1..#i]; 
  constraint 
    S{i,j|i<j}: x[i]+i <> x[j]+j; 
    T{i,j|i<j}: x[i]-i <> x[j]-j; 
  solve; 
  binary parameter X{i,j} := if(j=x[i],1); 
  Draw.Scale(50,50); 
  {i,j} Draw.Rect(i,j,1,1,if((i+j)%2,0,1),0); 
  {i,j|X} Draw.Circle(j+.5,i+.5,.3,5); 
end

References

[1]   MatMod. Homepage for Learning Mathematical Modeling :  https://matmod.ch.

[2]   Hürlimann T. Reference Manual for the LPL Modeling Language, most recent version. https://matmod.ch/lpl/doc/manual.pdf.