BEGIN { #p FNMR FMR if (!Samples) Samples = 100 if (!Seed) Seed = 1 #if (!Parameters) split("0.999 0.0001834 0.0031", Parameters, " ") if (!InputFile) InputFile = "default.lqn" if (!OutputDir) OutputDir = "./samples" if (!DefaultRanges) DefaultRanges = "default_ranges.txt" srand(Seed) while (getline < InputFile) { File[++FileLines] = $0 } while (getline < DefaultRanges) { sum = 0 num_inputs = 0 for (i=4; i<=NF; i++) { sum = sum + $i num_inputs = num_inputs + 1 } DefaultMeans[$1" "$2] = sum / num_inputs #print "Default mean for feature \""$1" "$2"\" is "DefaultMeans[$1" "$2] } } #Feature constraint format #s scanMRTD = 0.02 0.03 0.04 NF > 1 { if ($3 != "=") print "Error: contraint infile must take the format: 's varname = val1 val2 val3...'" feature = $1" "$2 value_str = "" for (i=4; i<=NF; i++) value_str = (value_str ? value_str" "$i : $i) Constraints[feature] = value_str } function randRange(size) { return int(1 + (rand() * size)) } #cost is the difference from the mean choice #eg, choosing 5 seconds when the average choice is 8 seconds incurs a cost of +3 #choosing a slower time than mean incurs a negative coCt function measureCost(feature, choice, choices, tmp,sum,n,mean) { mean = DefaultMeans[feature] if (!mean) print "ERROR: No default mean for feature "feature return mean - choice } END { for (sample=1; sample<=Samples; sample++) { outfile = OutputDir"/sample"sample".lqn" choices = "" cost = 0 for (l=1; l<= FileLines; l++) { tokens = split(File[l], line, " ") found = 0 for (feature in Constraints) { if (line[1]" "line[2] == feature) { found = 1 #print constraint name num_vals = split(Constraints[feature], cons_vals, " ") printf feature >> outfile #print random constraint value cons_pick = randRange(num_vals) cons_val = cons_vals[cons_pick] printf " "cons_val >> outfile #record "cost" cost = cost + measureCost(feature, cons_vals[cons_pick], cons_vals) #print rest of line for (i=4; i<=tokens; i++) printf " "line[i] >> outfile printf "\n" >> outfile choices = choices feature"="cons_val"," } } if (found == 0) print File[l] >> outfile } print "#"choices "COST="cost",">> outfile } }