Date post: | 15-Dec-2015 |
Category: |
Documents |
Upload: | cael-henney |
View: | 217 times |
Download: | 1 times |
… and BIBD’s, 0/1 encoding, symmetry breaking
See • choco manual 1.4.2, page 14 and 15• CSPLib prob028• choco manual 6.3, pages 64 and 65• choco manual 8.56 lex (constraint)
Represented with two bounds
kernel: intersection of all possible sets
envelope: the union of all possible sets upper bound
lower bound
We are given a set S of size n. Produce n.(n-1)/6 triples (subsets of S of size 3) such that given any pair of triples their intersection is of size at most 1
Equivalently, every possible pair of elements in S occurs in onlyone of the n.(n-1)/6 triples
Given a set of size n, how many triples are we to produce?
Equivalently, every possible pair of elements in S occurs in onlyone of the triples
How many pairs are there? n.(n-1)/2
Every triple contains 3 pairs Therefore n.(n-1)/6 triples required
We are given a set S of size n. Produce n.(n-1)/6 triples (subsets of S of size 3) such that given any pair of triples their intersection is of size at most 1
A triple is also called a “block” and the entries of a block a “point”
This is then a BIBD (balanced incomplete block design)
Applications: design of experiments, testing, …
Given a set of size n, how many triples are we to produce?
Equivalently, every possible pair of elements in S occurs in onlyone of the triples
How many pairs are there? n.(n-1)/2
Every triple contains 3 pairs Therefore n.(n-1)/6 triples required
0/1 Array
m=7
block
point
Sum of a column = 3, intersection between two columns is at most 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
Compile & Run
For both models try n=1, n=7, n=9
Show effect of symmetry breaking and search over only decision variable
How about we do the following:
Generate all triples <i,j,k> where 0 ≤ i < j < k < m and pick the ones we want
Have a zero/one IntegerVariable for each triple, in an arrayA, such that A[i][j][k] is 1 iff we select triple <i,j,k>
Flatten the array A into a one-D vector, say v?
Constrain v such that it sums to m.(m-1)/6
For every pair of triples that match on two indices make thesum of their corresponding constrained integer variables be at most 1 (i.e. select at most 1 of these triples)
Is this dumb?
Fix i and j: Sum of A[i][j][*] ≤ 1
Fix i and k: Sum of A[i][*][k] ≤ 1
Fix j and k: Sum of A[*][j][k] ≤ 1
But we need to ensure that the sum of the above sums is also at most 1
For every pair of triples that match on two indices make thesum of their corresponding constrained integer variables be at most 1 (i.e. select at most 1 of these triples)
An array, m by m, where pair[i][j] is an integer
pair[i][j] = k means that pair (i,j) is in kth block
Proposed by Chris Unsworth
Location, location, location
pair[i][j] = k iff points i and j are in block[k]
The number of points in a block is 3
Proposed by Chris Unsworth
Location, location, location
Constrain pair[i][j] = k iff block[k][i] = 1 and b[k][j] = 1
i and j are in the kth triple
if and only if kth triple contains i
and kth triple contains j
public class SteinerTriple03 { public static void main(String[] args) {
CPModel model = new CPModel(); int m = I nteger.parseInt(args[0]); int n = m*(m- 1)/6;
I ntegerVariable[][] block = makeIntVarArray("block",n,m,0,1); / / block[i][j] = 1 <- > j is in ith block I ntegerVariable[][] pair = new IntegerVariable[m][m]; / / pair[i][j] = k <- > (i,j) is in block[k]
for (int i=0;i<m- 1;i++) for (int j=i+1;j<m;j++) pair[i][j] = makeIntVar("pair_"+ i +"_"+ j,0,n- 1);
/ / / / one variable for each pair (i,j) where i<j / /
for (int i=0;i<n;i++) model.addConstraint(eq(sum(block[i]),3));
/ / / / there are 3 points in a block / /
for (int i=0;i<m- 1;i++) for (int j=i+1;j<m;j++) for (int k=0;k<n;k++)
model.addConstraint(ifOnlyI f(eq(pair[i][j],k),and(eq(block[k][i],1),eq(block[k][j],1)))); / / / / pair[i][j] = k <- > block[k][i] = 1 && block[k][j] = 1 / /
public class SteinerTriple03 { public static void main(String[] args) {
CPModel model = new CPModel(); int m = I nteger.parseInt(args[0]); int n = m*(m- 1)/6;
I ntegerVariable[][] block = makeIntVarArray("block",n,m,0,1); / / block[i][j] = 1 <- > j is in ith block I ntegerVariable[][] pair = new IntegerVariable[m][m]; / / pair[i][j] = k <- > (i,j) is in block[k]
for (int i=0;i<m- 1;i++) for (int j=i+1;j<m;j++) pair[i][j] = makeIntVar("pair_"+ i +"_"+ j,0,n- 1);
/ / / / one variable for each pair (i,j) where i<j / /
for (int i=0;i<n;i++) model.addConstraint(eq(sum(block[i]),3));
/ / / / there are 3 points in a block / /
for (int i=0;i<m- 1;i++) for (int j=i+1;j<m;j++) for (int k=0;k<n;k++)
model.addConstraint(ifOnlyI f(eq(pair[i][j],k),and(eq(block[k][i],1),eq(block[k][j],1)))); / / / / pair[i][j] = k <- > block[k][i] = 1 && block[k][j] = 1 / /
public class SteinerTriple03 { public static void main(String[] args) {
CPModel model = new CPModel(); int m = I nteger.parseInt(args[0]); int n = m*(m- 1)/6;
I ntegerVariable[][] block = makeIntVarArray("block",n,m,0,1); / / block[i][j] = 1 <- > j is in ith block I ntegerVariable[][] pair = new IntegerVariable[m][m]; / / pair[i][j] = k <- > (i,j) is in block[k]
for (int i=0;i<m- 1;i++) for (int j=i+1;j<m;j++) pair[i][j] = makeIntVar("pair_"+ i +"_"+ j,0,n- 1);
/ / / / one variable for each pair (i,j) where i<j / /
for (int i=0;i<n;i++) model.addConstraint(eq(sum(block[i]),3));
/ / / / there are 3 points in a block / /
for (int i=0;i<m- 1;i++) for (int j=i+1;j<m;j++) for (int k=0;k<n;k++)
model.addConstraint(ifOnlyI f(eq(pair[i][j],k),and(eq(block[k][i],1),eq(block[k][j],1)))); / / / / pair[i][j] = k <- > block[k][i] = 1 && block[k][j] = 1 / /
public class SteinerTriple03 { public static void main(String[] args) {
CPModel model = new CPModel(); int m = I nteger.parseInt(args[0]); int n = m*(m- 1)/6;
I ntegerVariable[][] block = makeIntVarArray("block",n,m,0,1); / / block[i][j] = 1 <- > j is in ith block I ntegerVariable[][] pair = new IntegerVariable[m][m]; / / pair[i][j] = k <- > (i,j) is in block[k]
for (int i=0;i<m- 1;i++) for (int j=i+1;j<m;j++) pair[i][j] = makeIntVar("pair_"+ i +"_"+ j,0,n- 1);
/ / / / one variable for each pair (i,j) where i<j / /
for (int i=0;i<n;i++) model.addConstraint(eq(sum(block[i]),3));
/ / / / there are 3 points in a block / /
for (int i=0;i<m- 1;i++) for (int j=i+1;j<m;j++) for (int k=0;k<n;k++)
model.addConstraint(ifOnlyI f(eq(pair[i][j],k),and(eq(block[k][i],1),eq(block[k][j],1)))); / / / / pair[i][j] = k <- > block[k][i] = 1 && block[k][j] = 1 / /
public class SteinerTriple03 { public static void main(String[] args) {
CPModel model = new CPModel(); int m = I nteger.parseInt(args[0]); int n = m*(m- 1)/6;
I ntegerVariable[][] block = makeIntVarArray("block",n,m,0,1); / / block[i][j] = 1 <- > j is in ith block I ntegerVariable[][] pair = new IntegerVariable[m][m]; / / pair[i][j] = k <- > (i,j) is in block[k]
for (int i=0;i<m- 1;i++) for (int j=i+1;j<m;j++) pair[i][j] = makeIntVar("pair_"+ i +"_"+ j,0,n- 1);
/ / / / one variable for each pair (i,j) where i<j / /
for (int i=0;i<n;i++) model.addConstraint(eq(sum(block[i]),3));
/ / / / there are 3 points in a block / /
for (int i=0;i<m- 1;i++) for (int j=i+1;j<m;j++) for (int k=0;k<n;k++)
model.addConstraint(ifOnlyI f(eq(pair[i][j],k),and(eq(block[k][i],1),eq(block[k][j],1)))); / / / / pair[i][j] = k <- > block[k][i] = 1 && block[k][j] = 1 / /
CPSolver sol = new CPSolver(); sol.read(model);
I ntDomainVar[] decision = new IntDomainVar[m*(m- 1)/2]; for (int i=0,k=0;i<m- 1;i++)
for (int j=i+1;j<m;j++,k++) decision[k] = sol.getVar(pair[i][j]);
sol.setVarIntSelector(new StaticVarOrder(decision)); / / / / decision variables are the pairs / /
System.out.println(sol.solve()); sol.printRuntimeSatistics(); for (int i=0;i<n;i++){
for (int j=0;j<m;j++) if(sol.getVar(block[i][j]).getVal() == 1) System.out.print(j +" "); for (int j=0;j<m;j++) System.out.print(sol.getVar(block[i][j]).getVal()); System.out.println();
} }
CPSolver sol = new CPSolver(); sol.read(model);
I ntDomainVar[] decision = new IntDomainVar[m*(m- 1)/2]; for (int i=0,k=0;i<m- 1;i++)
for (int j=i+1;j<m;j++,k++) decision[k] = sol.getVar(pair[i][j]);
sol.setVarIntSelector(new StaticVarOrder(decision)); / / / / decision variables are the pairs / /
System.out.println(sol.solve()); sol.printRuntimeSatistics(); for (int i=0;i<n;i++){
for (int j=0;j<m;j++) if(sol.getVar(block[i][j]).getVal() == 1) System.out.print(j +" "); for (int j=0;j<m;j++) System.out.print(sol.getVar(block[i][j]).getVal()); System.out.println();
} }
So?
1. Set variables2. Steiner triples3. Various models (four!)4. Symmetry breaking with
lex5. Dare to be stupid