Working with GAMS Vikas Argod Research Computing and Cyberinfrastructure

Slides:



Advertisements
Similar presentations
Intermediate Code Generation
Advertisements

Solving LP Models Improving Search Special Form of Improving Search
What is GAMS?. While they are not NLP solvers, per se, attention should be given to modeling languages like: GAMS- AIMMS-
Tutorial 12: Enhancing Excel with Visual Basic for Applications
The Web Warrior Guide to Web Design Technologies
Chemical Engineering Optimization Models with GAMS
ITEC113 Algorithms and Programming Techniques
Good modeling practices AGEC 641 Lab, Fall 2011 Mario Andres Fernandez Based on material written by Gillig and McCarl. Improved upon by many previous lab.
GAMS/GAMSIDE AGEC 641 Lab, Fall 2011 Mario Andres Fernandez Based on material written by Gillig and McCarl and improved upon by previous lab instructors.
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Linear Programming and CPLEX Ting-Yuan Wang Advisor: Charlie C. Chen Department of Electrical and Computer Engineering University of Wisconsin-Madison.
VBA Modules, Functions, Variables, and Constants
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
By Hrishikesh Gadre Session I Introduction to EES Department of Mechanical Engineering Louisiana State University Engineering Equation.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R 2 nd Year C and R Workshop Part of module PA2930 – 2.5 credits Venue: Computer terminal.
What is GAMS?.
Introduction to UNIX/Linux Exercises Dan Stanzione.
Chapter 19 Linear Programming McGraw-Hill/Irwin
ITCS 4/5145 Parallel Programming, UNC-Charlotte, B. Wilkinson, 2012, Jan 18, 2012assignprelim.1 Assignment Preliminaries ITCS 4145/5145 Spring 2012.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
 Accessing the NCCS Systems  Setting your Initial System Environment  Moving Data onto the NCCS Systems  Storing Data on the NCCS Systems  Running.
Network Models II Shortest Path Cross Docking Enhance Modeling Skills Modeling with AMPL Spring 03 Vande Vate.
A GAMS TUTORIAL. WHAT IS GAMS ? General Algebraic Modeling System Modeling linear, nonlinear and mixed integer optimization problems Useful with large,
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Chapter 19: Solver Re-Visited Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Linear Programming: Basic Concepts
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Lecture 4 PL/SQL language. PL/SQL – procedural SQL Allows combining procedural and SQL code PL/SQL code is compiled, including SQL commands PL/SQL code.
GAMS Anwendung Nutzeroberfläche eigene Programme Modellierungs- System GAMS AMPL ILOG Studio … Solver CPLEX, CONOPT, MINOS, COIN, BARON,...
Simplex method (algebraic interpretation)
Teacher’s Assessment Assistant Worksheet Builder Starting the Program
How to get started with GAMS MS&E 348 – Lecture 1/20/04.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
1 ILOG CPLEX CPLEX is a product developed by ILOG to solve  LPs  MIPs  QPs  MIQPs  Network Flow problems CPLEX technologies  CPLEX callable library.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
The Software Development Process
] COREY PEARSON [ ASUG INSTALLATION MEMBER MEMBER SINCE: 2008 CHAVONE JACOBS [ ASUG INSTALLATION MEMBER MEMBER SINCE: 2003 ALLAN FISHER [ ASUG INSTALLATION.
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
Session 1 Module 1: Introduction to Data Integrity
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
HEI/OCAN College Access Program Data Submissions.
Dr. Sajib Datta Jan 16,  The website is up.  Course lectures will be uploaded there ◦ Check regularly for assignments and update.
Chapter 4: server services. The Complete Guide to Linux System Administration2 Objectives Configure network interfaces using command- line and graphical.
Chapter 29: Program Security Dr. Wayne Summers Department of Computer Science Columbus State University
Assignprelim.1 Assignment Preliminaries © 2012 B. Wilkinson/Clayton Ferner. Modification date: Jan 16a, 2014.
Advanced Computing Facility Introduction
LINGO TUTORIAL.
Web Database Programming Using PHP
GRID COMPUTING.
Lecture 5 Good modeling Chengcheng Fei 2017 Fall
Chapter 13 Solver .out File and CCL
IENG 212 LAB 1 Research Assıstant: Kehınde Adewale ADESINA
Web Database Programming Using PHP
Solver & Optimization Problems
Introduction to MATLAB for Engineers, Third Edition
Assignment Preliminaries
JavaScript: Functions.
A Mathematical Programming Language
Chapter Four UNIX File Processing.
Web DB Programming: PHP
A QUICK START TO OPL IBM ILOG OPL V6.3 > Starting Kit >
IENG 212 LAB 1 Research Assıstant: Kehınde Adewale ADESINA
Presentation transcript:

Working with GAMS Vikas Argod Research Computing and Cyberinfrastructure

Research Computing and Cyberinfrastructure Empowering scholars in their ability to compute and manage data by developing and maintaining several state-of-the-art computational clusters Staff members provide support and expertise for research using – programming languages – numerical libraries – statistical packages – finite element solvers and fluid mechanics – Optimization packages Visit us at

Compute Engines Core Compute Engines SystemNodesCoresMemory (GB)Interconnect Lion-XO SDR Infiniband Lion-XB SDR Infiniband Lion-XC SDR Infiniband Lion-XJ DDR Infiniband Lion-XI DDR Infiniband Lion-XK DDR Infiniband Lion-XH QDR Infiniband Lion-CLSF1 virtual node using ScaleMP technology QDR Infiniband CyberStar QDR Infiniband Hammer GigE Tesla2 servers1632GigE 1 NVIDIA S GigE Storage SystemCapacityPerformance IBM GPFS Parallel File System550 TBCan sustain 5+ GB/s  A 48-port 10 GigE switch connects all compute engines and storage  1280 core system coming online in Summer 2010  All compute engines together to deliver 40 million core hours in 2010  Emerging technologies in the hands of the user community – ScaleMP and GPU cluster 3

Connecting to Hammer, Lion-X systems Remote Desktop Connection to hammer.aset.psu.edu OR Download and install SSH client OR Download Putty : Host name : hammer.aset.psu.edu for hammer lionxo.aset.psu.edu for lion-xo lionxc.aset.psu.edu for lion-xc Username : Penn state access id Authentication method : Password

File transfer In Windows, use WinSCP : In Linux/Mac: scp local_file Copy individual files: ~]$ scp foo.c foo.h Copy directory: ~]$ scp -r srcdir For more details:

Working with Linux Basic Linux commands: CommandOperation ls List all the files mkdir Create new directory cp old_file name new_filename Copy files rm Delete file cd Change directory vi Text editor Nedit Text editor for more commands!

GAMS in Hammer and LION-X Load the module: module load gams Command to run GAMS files in Hammer: gams gams_input_filename is an ASCII file with GAMS commands and has an extension ‘.gms’ e.g. gams blend_model.gms Command to run GAMS files in LION-X* Submit to Queue using PBS script Useful for jobs which take longer computation time

Sample PBS script #PBS -l nodes=1:ppn=1 #PBS -l walltime=02:30:00 #PBS -joe cd $PBS_O_WORKDIR module load gams gams blend_model.gms Submit this file to the queue : qsub Good idea to write results to output file (Example given in the handout) Visit for more information on working with PBShttp://rcc.its.psu.edu/hpc/guides/apps/pbs/

General Algebraic Modeling System (GAMS) High-level modeling system for mathematical programming and optimization Algebraic formulation : closeness to mathematical notation Calling appropriate Algorithms Efficient handling of mathematical optimization problems Simple model building and solution process Increase productivity and maintainable models

Example Problem Statement Several forms of gasoline are produced during the petroleum refining process, and a last step combines them to obtain market products with specified quality measures. Suppose the following four gasoline products are available: TypeQuality Index-1Quality Index-2Cost($/Barrel) Determine the minimum cost blend which has quality index-1 between 85 and 90 and quality index-2 between 270 and 280.

Mathematical Formulation

sets i set of gasoline /G1*G4/ j set of quality indices /Q1,Q2/; parameters cost(i) cost of gasoline set i /G1 48 G2 43 G3 58 G4 46/ quality_spec_min(j) quality specifications - minimum /Q1 85 Q2 270/ quality_spec_max(j) quality specifications- maximum /Q1 90 Q2 280/; Table quality_val(i,j) quality indices Q1 Q2 G G G G ; variables tot_cost total cost in $ x(i) fraction of each Gasoline set; equations objective objective or cost function min_spec_cons(j) minimum Quality index constraint max_spec_cons(j) maximum Quality index constraint tot_frac_cons total fraction=1 constraint ; ***********Model Definition******************** objective.. tot_cost =e= sum(i,cost(i)*x(i)); min_spec_cons(j).. sum(i,quality_val(i,j)*x(i)) =g= quality_spec_min(j); max_spec_cons(j).. sum(i,quality_val(i,j)*x(i)) =l= quality_spec_max(j); tot_frac_cons.. sum(i,x(i)) =e= 1; x.lo(i) = 0; x.up(i) = 1; *********************************************** model blend / objective,min_spec_cons,max_spec_cons,tot_frac_cons/; ***********Solve Statement********************* solve blend using lp minimizing tot_cost; *********************************************** display x.l; Page 1Page 2

Structure of a GAMS model InputsOutputs  Sets  Declaration  Assignment of members  Data  ( Parameters, Tables, Scalar )  Declaration  Assignment of values  Variables  Declaration  Assignment of type  Assignment of bounds and/or initial values  (optional)  Equations  Declaration  Definition  Model and Solve statements  Display statement (optional)  Echo Print  Reference Maps  Equation Listings  Status Reports  Results

blend_model.gms: sets Sets are the basic building blocks of a GAMS model, corresponding exactly to the indices in the algebraic representations of models. sets i set of gasoline /G1,G2,G3,G4/ j set of quality indices /Q1,Q2/; Any name of your choice No space in any name G1*G4 is same as G1,G2,G3,G4 Text is optional. It’s like a comment Mathematically: i = {G1, G2,G3,G4} j = {Q1,Q2}

blend_model.gms: parameters parameters are for inserting given data Name of the parameter Given data Optional text, useful for understanding

blend_model.gms: Tables Table quality_val(i,j) quality indices Q1 Q2 G G G G ; Very useful for larger datasets GAMS will perform domain checking to make sure that the row and column names of the table are members of the appropriate sets.

General Comments on Data Entry Direct Assignment e. g cost(‘Q1') = 48; Zero is the default value for all the parameters. A scalar is regarded as a parameter that has no domain. e.g.. Scalar f cost in dollars per mile /90/ ; A scalar is regarded as a parameter that has no domain The same parameter can be assigned a value more than once. Each assignment statement takes effect immediately and overrides any previous values. The same parameter may not be declared more than once Element-value can be separated by commas or entered as separate lines Entire list must be enclosed in slashes

Blend_model.gms: variables variables tot_cost total cost in $ x(i) fraction of each Gasoline set ; Every GAMS problem must contain at least one variable which is minimized or maximized (tot_cost in this example) Variable TypeAllowed range of variables Free -  to +  Positive 0 to +  Negative -  to 0 Binary 0 or 1 Integer 0, 1, 2,….100 e. g Positive variable x;

Blend_model.gms: equations equations objective objective or cost function min_spec_cons(j) minimum Quality index constraint max_spec_cons(j) maximum Quality index constraint tot_frac_cons total fraction=1 constraint; The power of algebraic modeling languages like GAMS is most apparent in the creation of the equations and inequalities that comprise the model under construction. This is because whenever a group of equations or inequalities has the same algebraic structure, all the members of the group are created simultaneously, not individually.

Equation Declaration Equations must be declared and defined in separate statements. The format of the declaration is the same as for other GAMS entities. objective.. tot_cost =e= sum(i,cost(i)*x(i)); The name of the equation being defined The symbol '..‘ Left-hand-side expression Relational operator: =l=, =e=, or =g= Right-hand-side expression

Equation declaration :Summation Format : Sum(index of summation, summand) As a simple example, let us consider that the model has summation of x over i Sum(i,x(i)) =g=1 Sum(i, Sum(j, c(i,j)*x(i,j))) Sum((i,j), c(i,j)*x(i,j)) or

Other types of indexed operations prod(i,x(i)) =g=1 Product over controlling index Maximum value over controlling index max_demand = smax((i,j), demand_array(i,j)) Minimum value over controlling index min_distance = smin((p,q), distance(p,q)) Full list of functions are given in the handout

blend_model.gms: equations min_spec_cons(j).. sum(i,quality_val(i,j)*x(i)) =g= quality_spec_min(j); max_spec_cons(j).. sum(i,quality_val(i,j)*x(i)) =l= quality_spec_max(j); tot_frac_cons.. sum(i,x(i)) =e= 1; Variables can appear on the left or right-hand side of an equation or both. The same variable can appear in an equation more than once. An equation definition can appear anywhere in the GAMS input, provided the equation and all variables and parameters to which it refers are previously declared.

blend_model.gms: Bounds GAMS is designed with a small database system in which records are maintained for the variables and equations. There are four fields in each record:.lo = lower bound.l = level or primal value.up = upper bound.m = marginal or dual value x.lo(i) = 0; x.up(i) = 1;

blend_model.gms: model model blend /all/ ; model blend / objective,min_spec_cons,max_spec_cons,tot_frac_cons/; or Model is a collection of Equations. Like other GAMS entities, it must be given a name in a declaration. The format of the declaration is the keyword Model followed by the name of the model, followed by a list of equation names enclosed in slashes. If all the defined equations are to be used /all/ can be used

blend_model.gms: Solve The format of the solve statement is as follows: 1.The keyword solve 2.The name of the model to be solved 3.The keyword using 4.An available solution procedure. Examples are lp for linear programming nlp for nonlinear programming mip for mixed integer programming rmip for relaxed mixed integer programming minlp for mixed integer nonlinear programming 5.The keyword minimizing or maximizing 6.The name of the variable to be optimized solve blend using lp minimizing tot_cost;

Display Statements The solve statement will cause several things to happen when executed. – The specific instance of interest of the model will be generated – the appropriate data structures for inputting this problem to the solver will be created – the solver will be invoked – the output from the solver will be printed to a file. (*. lst ) – To get the optimal values of the primal and/or dual variables, we can look at the solver output, or, if we wish, we can request a display of these result from GAMS as follows; display x.l; for final values of x

GAMS output Echo print Error messages Reference maps Model statistics Status reports Solution reports

Echo Print and Error messages Echo Print: – Copy of your input file with line numbers – Irrespective of errors Error messages: – Coded error message inside the echo print on the line immediately following the scene of offense – Messages start with **** and contain a $ followed by a numerical error code – Explanation of numerical code after the echo prints

Reference maps Include $onsymxref as the first line in the script Cross reference maps – This lists the named items (Sets, Parameters, Variables, Equations, Models, Files, Acronyms) in alphabetical order – identifies them as to type, shows the line numbers where the symbols appear, and classifies each appearance SYMBOL TYPE REFERENCES blend MODEL declared 55 defined 55 impl-asn 59 ref 59 cost PARAM declared 8 defined 9 ref 41 List of model entities – All the model entities are grouped by type – Also lists documentary text associated with entities

Status and Solution reports S O L V E S U M M A R Y MODEL blend OBJECTIVE tot_cost TYPE LP DIRECTION MINIMIZE SOLVER CPLEX FROM LINE 59 1 Normal Completion **** SOLVER STATUS 1 Normal Completion **** MODEL STATUS 1 Optimal **** OBJECTIVE VALUE RESOURCE USAGE, LIMIT ITERATION COUNT, LIMIT EQU min_spec_cons minimum Quality index constraint LOWER LEVEL UPPER MARGINAL G G G G

Summary Generality of the model Generation of closely related constraints in one statement Self documentary script Easy to read output Easy to debug with reference maps

Useful links/Reference Online GAMS documentation GAMS World :

Try this Copy example files from /usr/global/seminar/econ cp -r /usr/global/seminar/econ. (notice the dot at the end) Load the module : module load gams Run : gams blend_model.gms Open the file: gvim blend_model.lst