Skip to content

A MathOptInterface Optimizer to solve JuMP models using GAMS

License

Notifications You must be signed in to change notification settings

GAMS-dev/gams.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GAMS.jl

GAMS.jl provides a MathOptInterface Optimizer to solve JuMP models using GAMS.

GAMS comes with dozens of supported solvers. Among them are: ALPHAECP, ANTIGONE, BARON, CBC, CONOPT, CPLEX, DICOPT, GUROBI, IPOPT, KNITRO, LINDO, LINDOGLOBAL, MINOS, MOSEK, NLPEC, PATH, QUADMINOS, SBB, SHOT, SCIP, SNOPT, SOPLEX, XPRESS. Find a complete list here.

GAMS.jl supports the following JuMP features:

  • linear, quadratic and nonlinear (convex and non-convex) objective and constraints
  • continuous, binary, integer, semi-continuous and semi-integer variables
  • SOS1 and SOS2 sets
  • complementarity constraints

Installation

  1. Download GAMS and obtain a GAMS license. Please note that GAMS also offers a free community license.
  2. (optional) Add the GAMS system directory to the PATH variable in order to find GAMS automatically.
  3. Install GAMS.jl using the Julia package manager:
    using Pkg
    Pkg.add("GAMS")

Usage

Using GAMS as optimizer for your JuMP model:

using GAMS, JuMP
model = Model(GAMS.Optimizer)

GAMS System

If the GAMS system directory has been added to the PATH variable (you can check this with print(ENV["PATH"])), GAMS.jl will find it automatically. Otherwise, or if you like to switch between systems, the system directory can be specified by (one of the following):

set_optimizer_attribute(model, "SysDir", "<gams_system_dir>")
set_optimizer_attribute(model, GAMS.SysDir(), "<gams_system_dir>")

Analogously, you can specify a working directory with "WorkDir" or GAMS.WorkDir(). If no working directory has been set, GAMS.jl will create a temporary one.

If you want to use the same GAMS workspace (same system and working directory) for multiple models, you can create a GAMSWorkspace first with either of the following

ws = GAMS.GAMSWorkspace()
ws = GAMS.GAMSWorkspace("<gams_system_dir>")
ws = GAMS.GAMSWorkspace("<gams_system_dir>", "<gams_working_dir>")

and then pass it to your models:

model = Model(() -> GAMS.Optimizer(ws))

GAMS Options

GAMS command line options can be specified by

set_optimizer_attribute(model, "<option>", "<solver_name>")
set_optimizer_attribute(model, GAMS.<option>(), "<solver_name>")

where <option> is either HoldFixed, IterLim, License, LogOption, NodLim, OptCA, OptCR, ResLim, Solver, Threads, Trace, TraceOpt as well as LP, MIP, RMIP, NLP, DNLP, CNS, MINLP, RMINLP, QCP, MIQCP, RMIQCP, MCP or MPEC. Note that GAMS.ResLim() is equivalent to MOI.TimeLimitSec() and GAMS.Threads() to MOI.NumberOfThreads(). Options LimCol, LimRow, SolPrint and SolveLink cannot be changed and are set to 0, 0, 0 and 5, respectively.

Model Type

GAMS.jl will automatically choose a GAMS model type for you. Choosing a different model type:

set_optimizer_attribute(model, GAMS.ModelType(), "<model_type>")

GAMS Solver Options

Specifying GAMS solver options:

set_optimizer_attribute(model, "<solver_option_name>", <option_value>)

Note that passing a solver option is only valid when explicitly choosing a GAMS solver and not using the default.

GAMS Names vs. JuMP Names

GAMS uses generated variable and constraint names although it is possible to pass the JuMP names to the GAMS optimizer, because GAMS is more restrictive when it comes to variable and constraint naming. Use the attributes GeneratedVariableName, GeneratedConstraintName, OriginalVariableName, OriginalConstraintName to query a GAMS symbol name from a JuMP symbol and vice versa. This can help for debugging, for example in case of GAMS compilation errors. For example:

using GAMS

model = direct_model(GAMS.Optimizer())

@variable(model, x[1:2,1:3] >= 0)
@constraint(model, c[i = 1:2], sum(x[i,j] for j = 1:3) <= 10)

MOI.get(model, GAMS.GeneratedVariableName(), x[2,2]) # returns x4
MOI.get(model, GAMS.OriginalVariableName("x6"))      # returns x[2,3]
MOI.get(model, GAMS.OriginalVariableName("x10"))     # returns nothing

MOI.get(model, GAMS.GeneratedConstraintName(), c[2]) # returns eq2
MOI.get(model, GAMS.OriginalConstraintName("eq1"))   # returns c[1]
MOI.get(model, GAMS.OriginalConstraintName("eq10"))  # returns nothing

Note that JuMP direct-mode is used.