A clear and reliable language for building optimization models, choosing the right solver, and turning decision problems into results.
The GAMS Language helps you express complex optimization problems in a compact, readable way, connect them to data, and solve them efficiently across different solvers and deployment environments within the GAMS ecosystem.
GAMS is designed for optimization models where scale, structure, and dependable execution matter from prototype to production.
Describe the decision problem clearly and let optimization algorithms find the best solution.
Efficiently generate, solve, and secure large-scale optimization workflows built for enterprise demands.
Model once in GAMS, or in Python, connect the same optimization logic to analysis, apps, and managed execution.
Use familiar GAMS modeling concepts directly in Python workflows.
Turn models into interactive decision-support applications.
Run optimization workloads centrally on-premise or in the cloud.
GAMS models are written in an algebraic form that mirrors the underlying mathematics, making them easier to read, review, and maintain as they grow.
Define the structure of the model and provide input data through sets, parameters, and tables.
Represent the decisions the optimizer can make, including various continuous and discrete variable types.
Declare objective functions and constraints in compact indexed algebraic form.
Select the model type, solver, optimization direction, and objective variable.
GAMS helps teams move from a clear model description to reliable optimization results, with strong solver support and long-term stability.
The transportation model shows how a compact algebraic formulation turns sets, data, variables, and equations into a solvable optimization model.
A canonical linear program that shows how GAMS combines model structure, input data, decisions, and constraints in one readable formulation.
Sets
i canning plants / Seattle, San-Diego /
j markets / New-York, Chicago, Topeka / ;
Parameters
a(i) capacity of plant i in cases
/ Seattle 350
San-Diego 600 /
b(j) demand at market j in cases
/ New-York 325
Chicago 300
Topeka 275 / ;
Table d(i,j) distance in thousands of miles
New-York Chicago Topeka
Seattle 2.5 1.7 1.8
San-Diego 2.5 1.8 1.4 ;
Scalar f freight in dollars per case per thousand miles /90/ ;
Parameter
c(i,j) transport cost in thousands of dollars per case ;
c(i,j) = f * d(i,j) / 1000 ;
Variables
x(i,j) shipment quantities in cases
z total transportation costs in thousands of dollars ;
Positive variables x ;
Equations
cost define objective function
supply(i) observe supply limit at plant i
demand(j) satisfy demand at market j ;
cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
supply(i) .. sum(j, x(i,j)) =l= a(i) ;
demand(j) .. sum(i, x(i,j)) =g= b(j) ;
Model transport /all/ ;
Solve transport using LP minimizing z ;
Capacities, market demand, distances, freight rate
Shipment quantities between plants and markets
Minimize total transportation cost
Open the sections below to see how each part of the transportation model maps to a specific GAMS language concept.
Sets are the basic building blocks of a GAMS model, corresponding exactly to the indices in the algebraic representations of models. The Transportation example above contains just one Set statement:
Sets
i canning plants / Seattle, San-Diego /
j markets / New-York, Chicago, Topeka / ;
The effect of this statement is probably self-evident. We declared two sets and gave them the names $i$ and $j$. We also assigned members to the sets as follows:
$i =$ {Seattle, San-Diego}
$j =$ {New-York, Chicago, Topeka}.
Note the use of forward slashes ("/") for surrounding the list of set members. In mathematical notation this would be done with curly braces instead.
Parameters are one way of entering data in GAMS. In this case, the parameters $a$ and $b$ are defined over the sets $i$ and $j$.
Parameters
a(i) capacity of plant i in cases
/ Seattle 350
San-Diego 600 /
b(j) demand at market j in cases
/ New-York 325
Chicago 300
Topeka 275 / ;
GAMS lets you place explanatory text (shown in lower case) throughout your model as you develop it. Your comments are automatically incorporated into the output report at the appropriate places.
Data can also be entered in convenient table form. GAMS lets you input data in their basic form - transformations are specified algebraically.
Table d(i,j) distance in thousands of miles
New-York Chicago Topeka
Seattle 2.5 1.7 1.8
San-Diego 2.5 1.8 1.4 ;
Constants can simply be declared as scalars:
Scalar f freight in dollars per case per thousand miles /90/ ;
When data values are to be calculated, you first declare the parameter, give it a symbol and optionally index it, then give its algebraic formulation. GAMS will automatically make the calculations.
Parameter
c(i,j) transport cost in thousands of dollars per case ;
c(i,j) = f * d(i,j) / 1000 ;
Decision variables are expressed algebraically, with their indices specified. From this general form, GAMS generates each instance of the variable in the domain. Variables are specified as to type: FREE, POSITIVE, NEGATIVE, BINARY, or INTEGER. The default is FREE. The objective variable, z here, is simply declared without an index.
Variables
x(i,j) shipment quantities in cases
z total transportation costs in thousands of dollars ;
Positive variables x ;
Objective function and constraint equations are first declared by giving them names. Then their general algebraic formulae are described. GAMS now has enough information from data entered above and from the algebraic relationships specified in the equations to automatically generate each individual constraint statement. An extensive set of tools enables you to model any expression that can be stated algebraically: arithmetic, indexing, functions and exception-handling logic.
=E= indicates equal to
=L= indicates less than or equal to
=G= indicates greater than or equal to
Equations
cost define objective function
supply(i) observe supply limit at plant i
demand(j) satisfy demand at market j ;
cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
supply(i) .. sum(j, x(i,j)) =l= a(i) ;
demand(j) .. sum(i, x(i,j)) =g= b(j) ;
The model is given a unique name, here TRANSPORT, and the modeler specifies which equations should be included in this particular formulation. In this case we specified ALL which indicates that all equations are part of the model. This would be equivalent to MODEL TRANSPORT /COST, SUPPLY, DEMAND/. This equation selection enables you to formulate different models within a single GAMS input file, based on the same or different given data.
Model transport /all/ ;
The solve statement tells GAMS which model to solve, selects the solver to use, indicates the direction of the optimization, either MINIMIZING or MAXIMIZING, and specifies the objective variable.
Solve transport using LP minimizing z ;
Start with the documentation, explore model examples, or download GAMS to try the language locally.
Learn the language fundamentals, data handling, model structure, execution, and reporting workflows.
Open docsCompare supported solvers, model types, and platform availability for GAMS optimization workflows.
View solversBrowse ready-to-run GAMS models across industries, mathematical structures, and application domains.
Explore modelsDownload GAMS, request a license, and follow the first steps for running your own optimization models.
Get startedContact our team if you would like to discuss licensing, solver options, evaluation copies, or how GAMS fits into your optimization workflow.