1 / 28

GAMS

GAMS. General Algebraic Modeling System. What is GAMS?. The General Algebraic Modeling System (GAMS) is a high-level modeling system for mathematical programming and optimization. It consists of a language compiler and a stable of integrated high-performance solvers.

kaden-cole
Télécharger la présentation

GAMS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GAMS General Algebraic Modeling System

  2. What is GAMS? • The General Algebraic Modeling System (GAMS) is a high-level modeling system for mathematical programming and optimization. • It consists of a language compiler and a stable of integrated high-performance solvers. • GAMS is tailored for complex, large scale modeling applications, and allows you to build large maintainable models that can be adapted quickly to new situations.

  3. Gamside *free demo online • Without a valid GAMS license the system will operate as a free demo system with these limitations: • Model limits: • Number of constraints and variables: 300 • Number of nonzero elements: 2000 (of which 1000 nonlinear) • Number of discrete variables: 50 (including semi continuous, semi integer and member of SOS-Sets) • Global solver limits: • Number of constraints and variables: 10 • Create your model here and submit it to a NEOS Solver.

  4. Example • There are two canning plants and three markets, with the given data as follows. (This example is adapted from Dantzig, 1963) • Shipping distances are in thousands of miles, and shipping costs are assumed to be $90.00 per case per thousand miles. Minimize the cost of shipping goods from 2 plants to 3 markets

  5. Formulation

  6. GAMS Basic Model Structure • SETS • Declaration • Assignment of Members • Data • PARAMETERS, TABLES, SCALAR • Declaration • Assignment of Values • VARIABLES • Declaration • Assignment of type • EQUATIONS • Declaration • Definition • MODEL and SOLVE statements • Display statement (optional)

  7. Notes • An entity of the model cannot be referenced before it is declared to exist. • Typographical layout can be almost any style (multiple lines per statement, embedded blank lines etc.) • Terminate each statement with a semicolon ; • Doesn’t distinguish between upper and lower case letters • Comments are any line that start with a * in column 1 • Names of entities must start with a letter and can have up to 9 more characters (numbers or letters)

  8. SETS • Correspond 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 / ; Assign members to the set name them

  9. SETS • When the elements follow a sequence it is convenient to use an asterisk. For example: t = {1991,1992,1993, .....,2000} m = { mach1, mach2,......mach24} Set t time periods /1991*2000/ ; Set m machines /mach1*mach24/ ; • There is no difference in the use of SET or SETS

  10. SUBSETS • Sometimes it may be useful to create subsets. • Every element in the subset must be an element of the larger set. • Format: subsetname(setname) /elements/; • In this example hour1 is a subset of set h Sets g group /1*12/ h hour /1*6/ hour1(h) /1*4/ hour2(h) /5*6/

  11. Data • There are three fundamentally different formats that are allowed for entering data. • Lists • Tables • Direct assignments

  12. Lists declares its domain 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 / ; name it documentation assign a value for each element of i and j

  13. Some notes on Lists • Entire list must be enclosed in slashes and element-values must be separated by commas or entered on separate lines. • GAMS checks the domain and verifies each element in the list is actually a member of the declared domain (careful with spelling errors). • Zero is the default value for all parameters. So you only need to include the non-zero entries in the element-value list. • If the domain has multiple dimensions (up to 20) it can also be entered as a list: parameter salaries(employee,manager,department) /anderson .murphy .toy = 6000 hendry .smith .toy = 9000 hoffman .morgan .cosmetics = 8000 / ;

  14. Scalars • Scalars are considered a type of list and are structured the same way. • This can also be used to initialize variables. SCALAR F freight in dollars per case per thousand miles /90/ ;

  15. Tables documentation declares its domain 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 ; name it assign a value for each element of i and j (blanks are interpreted as 0s)

  16. Tables beyond 2 dimensions Sets ci "commodities : intermediate" / naphtha "naphtha" dist "distillate" gas-oil "gas-oil" / cr "commodities : crude oils" / mid-c "mid-continent" w-tex "west-texas" / q "attributes of intermediate products" / density, sulfur / ; table attrib(ci, cr, q) blending attributes density sulfur naphtha. mid-c 272 .283 naphtha. w-tex 272 1.48 dist . mid-c 292 .526 dist . w-tex 297 2.83 gas-oil. mid-c 295 .98 gas-oil. w-tex 303 5.05 ;

  17. The table attrib could also be laid out like this:

  18. Direct Assignment • Divides the task of parameter assignment and declaration between separate statements. PARAMETER C(I,J) transport cost in thousands of dollars per case ; C(I,J) = F * D(I,J) / 1000 ; • Using F and D(I,J) is only legal if you have already assigned values to them.

  19. VARIABLES • Each decision variable must be declared. VARIABLES X(I,J) shipment quantities in cases Z total transportation costs in thousands of dollars ; POSITIVE VARIABLE X ; • Once declared, every variable must be assigned a type.

  20. Equations • Equations must be declared and defined in separate statements. The format of the declaration is the same as for other GAMS entities. 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) ;

  21. Equation Types: =e= Equality: RHS must equal LHS =g= Greater than: LHS must be greater than or equal to RHS =l= Less than: LHS must be less than or equal to RHS =n= No relationships enforced between LHS and RHS. (This equation type is rarely used.) 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) ;

  22. GAMS Summation Notation • The format is based on the idea of always thinking of a summation as an operator with two arguments: Sum(index of summation, summand) • A comma separates the two arguments, and if the first argument requires a comma then it should be in parentheses. • A simple example Would be equivalent to: sum(j,(x(i,j)) • A more complex example Would be equivalent to: sum((i,j), c(i,j)*x(i,j))

  23. The components of an equation definition are, in order: • The name of the equation being defined • The domain • Domain restriction condition (optional) • The symbol '..' • Left-hand-side expression • Relational operator: =l=, =e=, or =g= • Right-hand-side expression

  24. Some notes on Equations • Names of equations must begin with a letter. • Names can only contain letters and numbers. • The text describing the identifier (or name) must be contained on the same line. • The two dots “..” are always required between the equation name and the start of the algebra. • Variables can appear on the right and left hand side of equations.

  25. Objective Function • GAMS does not have an explicit entity called the “objective function” • To create the objective function create an unconstrained variable and use an equation to define it. VARIABLES X(I,J) shipment quantities in cases Z total transportation costs in thousands of dollars ; POSITIVE VARIABLE 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) ;

  26. Model Statement • Format: keyword Model followed by the name of the model, followed by a list of equation names enclosed in slashes. • If all previously defined equations are to be included, you can enter /all/ Activity level (.l) or (.L) in place of the explicit list. model transport /all/ ; or model transport / cost, supply, demand/ ; • This is useful to advanced users who may create several models in one GAMS run.

  27. Solve Statement solve transport using lp minimizing z ; Format: 1. The keyword solve 2. The name of the model to be solved 3. The keyword using 4. An available solution procedure. The complete list is • lp for linear programming • nlp for nonlinear programming • mip for mixed integer programming • rmipfor relaxed mixed integer programming • minlp for mixed integer nonlinear programming • rminlp for relaxed mixed integer nonlinear programming • mcp for mixed complementarity problems • cns for constrained nonlinear systems 5. The keyword minimizing or maximizing 6. The name of the variable to be optimized

  28. For more info… Documentation including tutorial and user guide: • http://www.gams.com/docs/document.htm Download a copy of gamside: • http://www.gams.com/download/ • Model limits: • Number of constraints and variables: 300 • Number of nonzero elements: 2000 (of which 1000 nonlinear) • Number of discrete variables: 50 (including semi continuous, semi integer and member of SOS-Sets) • Global solver limits: • Number of constraints and variables: 10 Solvers for larger models: • http://www.neos-server.org/neos/index.html

More Related