# Translate in dzn format from an original binary WCSP instance # Usage: awk -f wcsp2dzn.awk smallrandom.wcsp TOP DIV > smallrandom.dzn # Maximum cost is given by TOP and all costs (including initial upper bound) are divided by DIV # Warning! wcsp problem file must have only unary and binary cost functions in extension with all tuples defined function cost2int(x) { if (x= 3 { if (tuple==0) { # read header of current unary or binary cost function constraint = ""; if ($1 == 2) { c2++; nbtuples2 = nbtuples2 "," $NF; cumtuples2 = cumtuples2 "," cum2; cum2 += $NF; func2x = func2x "," 1+$2; func2y = func2y "," 1+$3; binary = 1; } else if ($1 == 1) { c1++; nbtuples1 = nbtuples1 "," $NF; cumtuples1 = cumtuples1 "," cum1; cum1 += $NF; func1x = func1x "," 1+$2; binary = 0; } else if ($1 == 0) { lb += $(NF-1); } else { print "ERROR bad arity" > "/dev/stderr"; err = 1; exit(err); } tuple = $NF; e++; } else { if (binary) { if ($NF > maxcost2) maxcost2=$NF; constraint = constraint "," cost2int($NF) "," $1 "," $2; tuple--; if (tuple==0) { costs2 = costs2 "," substr(constraint,2) ""; } } else { if ($NF > maxcost1) maxcost1=$NF; constraint = constraint "," cost2int($NF) "," $1; tuple--; if (tuple==0) { costs1 = costs1 "," substr(constraint,2) ""; } } } } END { print "num_variables= " n ";"; print "max_domain = " maxd ";"; print "domains = [" substr(doms,2) "];"; print "top = " cost2int(ub) ";"; print "cost0 = " cost2int(lb) ";"; print "num_constraints1= " c1 ";"; print "max_constraints1 = " cum1*2 ";"; print "max_costs1 = " cost2int(maxcost1) ";"; print "num_constraints2= " c2 ";"; print "max_constraints2 = " cum2*3 ";"; print "max_costs2 = " cost2int(maxcost2) ";"; print "func1x = [" substr(func1x,2) "];"; print "num_tuples1 = [" substr(nbtuples1,2) "];"; print "cum_tuples1 = [" substr(cumtuples1,2) "];"; print "costs1 = [" substr(costs1,2) "];"; print "func2x = [" substr(func2x,2) "];"; print "func2y = [" substr(func2y,2) "];"; print "num_tuples2 = [" substr(nbtuples2,2) "];"; print "cum_tuples2 = [" substr(cumtuples2,2) "];"; print "costs2 = [" substr(costs2,2) "];"; }