Commit 5e73087e authored by Simon de Givry's avatar Simon de Givry
Browse files

academic problem generator

parent e1ed1888
## Soft AllInterval series generator
## see CSPLib problem 007
## usage:
## awk -f allintervals.awk > allintervals.cp
## gawk -f cp2wcsp.awk allintervals.cp > allintervals.wcsp
BEGIN {
N = 20; ## problem size (number of x_i variables)
U = 5; ## generate random unary costs in [0,U[
B = 1; ## default cost for violation of soft alldifferent (each pair of equal variables adds this cost to the total cost)
# problem name
print "AllIntervals" N;
# x_i variables
for (i= 1; i<=N ; i++) {
printf("x%d", i);
for (d= 0; d<=N-1 ; d++) {
printf(" %d", d);
}
print "";
}
# d_i variables
for (i= 1; i<=N-1 ; i++) {
printf("d%d", i);
for (d= 1; d<=N-1 ; d++) {
printf(" %d", d);
}
print "";
}
# d_i = |x_i - x_{i+1}|
for (i= 1; i<=N-1 ; i++) {
print "hard(d" i " == abs(x" i " - x" i+1 "))";
}
# random unary costs
for (i= 1; i<=N ; i++) {
print "x" i, 0;
for (d= 0; d<=N-1 ; d++) {
print d,int(U * rand());
}
}
# soft alldifferent on x_i variables using binary cost functions
for (i= 1; i<=N ; i++) {
for (j= i+1; j<=N ; j++) {
print "soft(" B ", x" i " != x" j ")";
}
}
# soft alldifferent on d_i variables using binary cost functions
for (i= 1; i<=N-1 ; i++) {
for (j= i+1; j<=N-1 ; j++) {
print "soft(" B ", d" i " != d" j ")";
}
}
}
BEGIN {
n = ARGV[1] + 0;
ARGV[1] = "";
ARGC = 1;
print "latin" n, n*n, n, 2*n, 1;
for (i=0; i<n*n;i++) printf(" %d",n);
print "";
for (i=0; i<n;i++) {
printf("%d",n);
for (j=0; j<n;j++) {
printf(" %d",t++);
}
print " -1 salldiff var 1";
}
for (i=0; i<n;i++) {
printf("%d",n);
for (j=0; j<n;j++) {
printf(" %d",i+j*n);
}
print " -1 salldiff var 1";
}
}
BEGIN {
N = 140;
B = 5;
print "SCHUR_" N "_" B, 1;
for (i=1;i<=N;i++) {
printf("X%d", i);
for (v=1;v<=B;v++) {
printf(" %d", v);
}
print "";
}
for (i=1;i<=N;i++) {
for (j=i+1;j<=N;j++) {
for (k=j+1;k<=N;k++) {
if (i+j == k) {
print "hard(!(X" i "==X" j " && X" i "==X" k " && X" j "==X" k "))";
# print "hard(alldiff(X" i ",X" j ",X" k "))";
}
}
}
}
exit;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment