forked from stephenlsmith/GLNS.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GLNScmd.jl
executable file
·91 lines (84 loc) · 3.3 KB
/
GLNScmd.jl
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
#!/usr/bin/env julia
# Copyright 2017 Stephen L. Smith and Frank Imeson
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
using GLNS
"""
Optional Flags -- values are given in square brackets []
-max_time=[Int] (default set by mode)
-trials=[Int] (default set by mode)
-restarts=[Int] (default set by mode)
-mode=[default, fast, slow] (default is default)
-verbose=[0, 1, 2, 3] (default is 3. 0 is no output, 2 is most verbose)
-output=[filename] (default is output.tour)
-epsilon=[Float in [0,1]] (default is 0.5)
-reopt=[Float in [0,1]] (default is set by mode)
"""
function parse_cmd(ARGS)
if isempty(ARGS)
println("no input instance given")
exit(0)
end
if ARGS[1] == "-help" || ARGS[1] == "--help"
println("Usage: GTSPcmd.jl [filename] [optional flags]\n")
println("Optional flags (vales are give in square brackets) :\n")
println("-mode=[default, fast, slow] (default is default)")
println("-max_time=[Int] (default set by mode)")
println("-trials=[Int] (default set by mode)")
println("-restarts=[Int] (default set by mode)")
println("-noise=[None, Both, Subset, Add] (default is Both)")
println("-num_iterations=[Int] (default set by mode. Number multiplied by # of sets)")
println("-verbose=[0, 1, 2, 3] (default is 3. 0 is no output, 3 is most.)")
println("-output=[filename] (default is None)")
println("-epsilon=[Float in [0,1]] (default is 0.5)")
println("-reopt=[Float in [0,1]] (default is 1.0)")
println("-budget=[Int] (default has no budget)")
exit(0)
end
int_flags = ["-max_time", "-trials", "-restarts", "-verbose", "-budget", "-num_iterations"]
float_flags = ["-epsilon", "-reopt"]
string_flags = ["-mode", "-output", "-noise", "-devel"]
filename = ""
optional_args = Dict{Symbol, Any}()
for arg in ARGS
temp = split(arg, "=")
if length(temp) == 1 && filename == ""
filename = temp[1]
elseif length(temp) == 2
flag = temp[1]
value = temp[2]
if flag in int_flags
key = Symbol(flag[2:end])
optional_args[key] = parse(Int64, value)
elseif flag in float_flags
key = Symbol(flag[2:end])
optional_args[key] = parse(Float64, value)
elseif flag in string_flags
key = Symbol(flag[2:end])
optional_args[key] = value
else
println("WARNING: skipping unknown flag ", flag, " in command line arguments")
end
else
error("argument ", arg, " not in proper format")
end
end
if !isfile(filename)
println("the problem instance ", filename, " does not exist")
exit(0)
end
return filename, optional_args
end
# running the code on the problem instance passed in via command line args.
problem_instance, optional_args = parse_cmd(ARGS)
GLNS.solver(problem_instance; optional_args...)