Presentation is loading. Please wait.

Presentation is loading. Please wait.

Working with GAMS Vikas Argod Research Computing and Cyberinfrastructure

Similar presentations


Presentation on theme: "Working with GAMS Vikas Argod Research Computing and Cyberinfrastructure"— Presentation transcript:

1 Working with GAMS Vikas Argod Research Computing and Cyberinfrastructure vikasargod@psu.edu

2 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 http://rcc.its.psu.edu/hpc/

3 Compute Engines Core Compute Engines SystemNodesCoresMemory (GB)Interconnect Lion-XO641921280SDR Infiniband Lion-XB16128512SDR Infiniband Lion-XC1405601664SDR Infiniband Lion-XJ14411525120DDR Infiniband Lion-XI645124096DDR Infiniband Lion-XK645124096DDR Infiniband Lion-XH483842304QDR Infiniband Lion-CLSF1 virtual node using ScaleMP technology 128768QDR Infiniband CyberStar22420487680QDR Infiniband Hammer8641024GigE Tesla2 servers1632GigE 1 NVIDIA S107096016GigE 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

4 Connecting to Hammer, Lion-X systems Remote Desktop Connection to hammer.aset.psu.edu OR Download and install SSH client http://downloads.its.psu.eduhttp://downloads.its.psu.edu OR Download Putty : http://rcc.its.psu.edu/hpc/guides/connectivity/putty/http://rcc.its.psu.edu/hpc/guides/connectivity/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

5 File transfer In Windows, use WinSCP : http://rcc.its.psu.edu/hpc/guides/filetransfer/winscp/http://rcc.its.psu.edu/hpc/guides/filetransfer/winscp/ In Linux/Mac: scp local_file user@hostname:destination_directory Copy individual files: [abc123@funkmachine ~]$ scp foo.c foo.h abc123@lionxj.rcc.psu.edu:.abc123@lionxj.rcc.psu.edu Copy directory: [abc123@funkmachine ~]$ scp -r srcdir abc123@hammer.aset.psu.edu:.abc123@hammer.aset.psu.edu For more details: http://rcc.its.psu.edu/hpc/guides/connectivity/ssh/#filetransfer http://rcc.its.psu.edu/hpc/guides/connectivity/ssh/#filetransfer

6 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!

7 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

8 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 http://rcc.its.psu.edu/hpc/guides/apps/pbs/ for more information on working with PBShttp://rcc.its.psu.edu/hpc/guides/apps/pbs/

9 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

10 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) 19921048 27033543 37828058 49126546 Determine the minimum cost blend which has quality index-1 between 85 and 90 and quality index-2 between 270 and 280.

11 Mathematical Formulation

12 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 G1 99 210 G2 70 335 G3 78 280 G4 91 265; 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

13 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

14 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}

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

16 blend_model.gms: Tables Table quality_val(i,j) quality indices Q1 Q2 G1 99 210 G2 70 335 G3 78 280 G4 91 265; 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.

17 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

18 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;

19 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.

20 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

21 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

22 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

23 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.

24 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;

25 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

26 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;

27 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

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

29 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

30 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

31 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 45.2941 RESOURCE USAGE, LIMIT 0.000 1000.000 ITERATION COUNT, LIMIT 4 2000000000 ---- EQU min_spec_cons minimum Quality index constraint LOWER LEVEL UPPER MARGINAL G1. 0.1765 1.0000. G2. 0.3529 1.0000. G3.. 1.0000 13.0000 G4. 0.4706 1.0000.

32 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

33 Useful links/Reference Online GAMS documentation http://www.gams.com/docs/document.htm http://www.gams.com/docs/document.htm GAMS World : http://www.gamsworld.org/http://www.gamsworld.org/

34 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


Download ppt "Working with GAMS Vikas Argod Research Computing and Cyberinfrastructure"

Similar presentations


Ads by Google