AmplNLWriter.OptimizerType
Optimizer(
    solver_command::Union{String,Function},
    solver_args::Vector{String};
    stdin::Any = stdin,
    stdout:Any = stdout,
    directory::String = "",
)

Create a new Optimizer object.

Arguments

  • solver_command: one of two things:
    • A String of the full path of an AMPL-compatible executable
    • A function that takes takes a function as input, initializes any environment as needed, calls the input function with a path to the initialized executable, and then destructs the environment.
  • solver_args: a vector of String arguments passed solver executable. However, prefer passing key=value options via MOI.RawOptimizerAttribute.
  • stdin and stdio: arguments passed to Base.pipeline to redirect IO. See the Julia documentation for more details by typing ? pipeline at the Julia REPL.
  • directory: the directory in which to write the model.nl and model.sol files. If left empty, this defaults to a temporary directory. This argument may be useful when debugging.

Examples

A string to an executable:

Optimizer("/path/to/ipopt.exe")

A function or string provided by a package:

Optimizer(Ipopt.amplexe)
# or
Optimizer(Ipopt_jll.amplexe)

A custom function

function solver_command(f::Function)
    # Create environment ...
    ret = f("/path/to/ipopt")
    # Destruct environment ...
    return ret
end
Optimizer(solver_command)

The following two calls are equivalent:

# Okay:
model = Optimizer(Ipopt_jll.amplexe, ["print_level=0"])
# Better:
model = Optimizer(Ipopt_jll.amplexe)
MOI.set(model, MOI.RawOptimizerAttribute("print_level"), 0
AmplNLWriter._solver_commandMethod
_solver_command(x::Union{Function,String})

Functionify the solver command so it can be called as follows:

foo = _solver_command(x)
foo() do path
    run(`$(path) args...`)
end
AmplNLWriter.call_solverFunction
call_solver(
    solver::AbstractSolverCommand,
    nl_filename::String,
    options::Vector{String},
    stdin::IO,
    stdout::IO,
)::String

Execute the solver given the NL file at nl_filename, a vector of options, and stdin and stdout. Return the filename of the resulting .sol file.

You can assume nl_filename ends in model.nl, and that you can write a .sol file to replace(nl_filename, "model.nl" => "model.sol").

If anything goes wrong, throw a descriptive error.