#!/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...)