#!/bin/ksh
#####################################################
# Sample script for generating benchmark instance   #
#####################################################
# The script should be launched with option -all n  #
# where n is at least 10 or 50 to generate a        #
# sufficient number of instances (otherwise the     #
# tests may not be statistically significant)       #
#####################################################

####################################################
# The first argument is the generatore source file #
# The rest are used as options for the generator   #
####################################################
SOURCE=$1
shift
OPTIONS=$*

############################################
# Check the source exists and is readable  #
# and then compile it (optimized) with gcc #
############################################
if test -z ${SOURCE}
then
  echo "Source file missing"
  echo "Usage"
  echo "sampling <generator> [options for generator]"
  exit
elif test ! -r ${SOURCE}.c
then
   echo "File ${SOURCE}.c not found or not readable"
   exit
fi

rm -f sampler

gcc -O3 ${SOURCE}.c -o sampler

############################
# Fixed Sampling Intervals #
############################
# This code generates 160  #
# paramentes combinations  #
############################

echo "If the program seems to loop forever"
echo "Try to run it with the option -failures <n>"
echo "which give up generation after <n> failures."
echo "Some problems might not be generable for some"
echo "Combination of parameters"

for DEPTH in 1 2 4 8
do
 for VARS in 2 4 8 16
 do
  for Cstep in 2 3 4 5 6 7 8 16 32 64
  do
   let CLAUSES=${VARS}*${Cstep}
   sampler "-clauses ${CLAUSES}" "-vars ${VARS}" "-depth ${DEPTH}" "${OPTIONS}"
  done
 done
done

#######################################################################
# For the UNBOUNDED QBF benchmark it better to let the depth increase #
# because the variables increase proportionally as well               #
# So is better to use something like                                  #
#                                                                     #
# for DEPTH in 1 2 4 8 16 32                                          #
# do                                                                  #
#   for VARS in 2 4 8                                                 #
#   do                                                                #
#     etc.                                                            #
#######################################################################


################################
# Continuous Sampling Interval #
################################
# This code generates 7560     #
# paramentes combinations      #
################################
DEPTH=1
while test ${DEPTH} -le 8
do
 VARS=2
 while test ${VARS} -le 16
 do
  Cstep=2
  while test ${Cstep} -le 64
  do
   let CLAUSES=${VARS}*${Cstep}
   sampler "-clauses ${CLAUSES}" "-vars ${VARS}" "-depth ${DEPTH}" "${OPTIONS}"
   let Cstep=${Cstep}+1
  done
  let VARS=${VARS}+1
 done
 let DEPTH=${DEPTH}+1
done

