-
Notifications
You must be signed in to change notification settings - Fork 1
/
selectproblems.rb
executable file
·134 lines (117 loc) · 3.03 KB
/
selectproblems.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/ruby -w
def usage (options)
puts "Usage: ./selectproblems.rb --<option> <value>"
puts " Where <option> is one of the following:"
options.each { |key,value|
puts " - #{key}"
}
end
def all_in_options (option, array, options)
unless (options[option])
raise "Option `#{option}` does not exist"
end
array.each { |v|
unless (options[option].include?(v))
return false
end
}
true
end
def read_options_from_file (options, filename)
begin
File.open(filename,'r') { |file|
file.each() { |line|
if options[line.split[0]]
options[line.split[0]] = line.split[1];
end
}
}
rescue
raise "No file " + filename
end
end
def write_options_to_file (options, filename)
File.open(filename,'w') { |file|
options.each() { |key, value|
printf(file, "%s %s\n", key, value);
}
}
end
def parse_options_from_argv (options, argv)
argv.each_slice(2) do |option, value|
option = option[/[^-].*/]
if 'h,help,usage'.include?(option)
usage(options)
exit
end
unless options[option]
raise "Option `#{option}` does not exist"
end
options[option] = value;
end
end
filename = "options.rc"
options = {
"min_nvar" => 1,
"max_nvar" => 1e9.to_i,
"min_ncon" => 0,
"max_ncon" => 1e9.to_i,
"linearity" => "lincon,nlncon",
"constr_type" => "unc,equ,inq,gen",
"bounds" => "boxed,lower,upper,nobnd",
"fixed_var" => "fixed,nofix",
"use_slack" => "true,false"
}
#puts "Selecting options from the file " + filename
begin
read_options_from_file(options, filename)
rescue
puts "Do you want to create the file " + filename +
" with the default options? (Y/n)"
yn = gets.chomp.downcase
if (yn == '')
yn = 'y'
end
if (yn == 'y')
write_options_to_file(options, filename)
elsif (yn != 'n')
puts "Option unidentified"
end
end
parse_options_from_argv(options, ARGV)
#options.each { |key,value|
#puts "#{key} => #{value}"
#}
class_file = File.open("sif.bsc","r")
decoder_file = File.open("sif.dcd","r")
list_file = File.open("problem.list","w")
class_file.each.zip(decoder_file.each).each do |line1, line2|
name = line1.split[0]
if (name != line2.split[0])
raise "#{name} not equal #{line2.split[0]}"
end
nvar = line2.split[1].to_i
nconE = line2.split[2].to_i
nconI = line2.split[3].to_i
constr = line2.split[4].split(',')
linear = line2.split[5].split(',')
bound = line2.split[6].split(',')
fixed = line2.split[7].split(',')
if (options["use_slack"] == "true")
nvar += nconI
end
ncon = nconE + nconI
if (options["min_nvar"].to_i <= nvar &&
nvar <= options["max_nvar"].to_i &&
options["min_ncon"].to_i <= ncon &&
ncon <= options["max_ncon"].to_i &&
all_in_options("constr_type", constr, options) &&
all_in_options("linearity", linear, options) &&
all_in_options("bounds", bound, options) &&
all_in_options("fixed_var", fixed, options) )
printf(list_file, "%s\n", name)
end
end
list_file.close()
decoder_file.close()
class_file.close()