Gams

Salvador Pineda 20/11/13 GAMS download www.gams.com IGAMSI •• Welcome to the GAMS Home Page! Toe General Algebraíc M

Views 214 Downloads 10 File size 2MB

Report DMCA / Copyright

DOWNLOAD FILE

Recommend stories

Citation preview

Salvador Pineda 20/11/13

GAMS download www.gams.com IGAMSI

••

Welcome to the GAMS Home Page! Toe General Algebraíc M odeling System (GAMS) is a high-level modeling system for mathematical programming maintainable models that can b e adapted quickly to new situations. • • • •

An Intmcmotion to GA.i\1S Docmnentation (induding FAQ) Conmbmed Doomnentation Presentations. Books. Poste,rs

• Download Current GAMS Svstem • Download Older GA.ivlS Systems • Conmbmed Software

. .//

V

• Comses and Workshops

• Mailing Llst Google Grow. and N ewsletters • Toe GAMS W orld • Sofution Specialists • Other Sites on the W eh

GAMS appearence gamside: C:\ Documents and Settings\ Eduardo Caro\M1s documentos\ gamsd1r\pr0Jd1r\gmsproj.gpr'! [D: ~ File

Edit

Search

Windows

Transporte.gms ) Transporte.lst ~

I

Utilities

Model Library

Untitled_2.gms

I

Help

Untitled_2.lst

II

Equil_v4.gms

pracllab2.gms

1

Programa para el Trabajo de la asignatura de doctorado: Modelos de Equilibro en Mercados Eléctricos

ile

out /salida_vl.out / ;

ut

out;

pt1on l1mrow = 100; $onuellist

option mcp

path

Sets I

1

Generadores'

/ i1;i;i2 /

J

1

Demandas

/

B

1

1

Bloques gen' 1 Bloques dem'

K

N L alias (N,Nl);

j3 ;i; j4 /

/ bl;i;b2/ / k3;i;k4/

1

Nudos 1

/

1

Parametro L'

/ 11*11 /

nl ;i;n4 /

,

ositive Variables ganmia(I,B), delta (J),

eta (J, K), phi (N,Nl),

taol(N,N,L), tao2(N,N,L), Pgib(I,B) 'Potencias a generar, por nudo y Pdjk(J,K) 'Potencias de demanda, por nudo y Pg2 ib I I, B) 'Potencias auxiliares a generar, Pd2jk (J, K) 'Potencias auxiliares de demanda, thetal(N,N,L), theta2(N,N,L)

arial>les

rho (N), u(I,B), nu(J,K)

6: 1

llnserl

bloque' bloque'

por nudo y bloque' por nudo y bloque'

,,

GAMS files

*•

*•

GAMS files •



[ Solver ] ·~_,,,,,,,,..

Model .""-_ _ __... Solution

.~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!--> Addñtñoll'i1ai~ Dil'i1fP)lDt fn~es

Addñtñoll'i1ai~ output fn~es

(OfP)1tDOil'i1aJ ~)

(optñoll'i1ai~)

GAMS file structure • Definition of sets, paran1eters, tables and variables • Definition of objective function • Definition of equality constraints • Definition of inequality constraints • Definition of the n1odel • Solve staten1ent • Display solution (optional)

Example

Transport problem

Transport problem example A un1e that a product i · to be shipped in the amounts u 1 . ... , um, . from each of m shipping origin and received in amounts v1 . ... , n . by each of n hip-ping destinai ion . The prob1em consists of determining I he amoun1s X ij · 1o be shipped from origins i to destina ion j

o minimize the cos of tl'ansporta1ion .

113

X

V

2

V

3

33

Transport problem example l. D ata: rn:

n:

he number of origins. he number of de tin.ations.

ui: the .amount to be shipped from origin í.

, 1 : the .amount to be received in destinai ion j. c i1 :

the cost of sending a u n it of product from origin í to des1ination j.

2. Variable X i j:

the .an1ount to be shipped from origin í to des1ina.tion j. It i a u1ned that hese variab] Xij

are non-negative, that is

> O;, i = l . . . m;, j = 1 . . . n.

Transport problem example 3.

e. on

. t. .t rain

The constraints of t his problem are: n

L Xi j j= l

ui ; i

= l . .. . . m .

rn

¿

V:(

Xij

j = 1 . .. n

i= l

4. Function to be optimize d. In I he t ra n portation prob1em we a re normally interested in tninimizing t he t otal cos1 of t ra nsportation (sum of t he unit co t I ime t he a mounts being shipped) t hat i we I\/_[ inimize n 1,

n

z = L L Cij X ij • i= l j = l

Transport problem example M inimize m

z

==

n

LL

Cij

ZJ .

i= l j = l

ub ject t o n

I:

iJ

-

uí ·

ij

-

.

ij

> O·



== 1 . .. m

j=l m

I:

í= l



\/j == 1 . .. n

v· == 1 . . . m · Vj

==

1 .. . n

Transport problem example l. Data: rn:

n:

he number of origins. he number of de tin.ations.

ui: the .amount to be shipped from origin í.

, 1 : the .amount to be received in destinai ion j. c i1 :

the cost of sending a unit of product from origin í to des1ination j.

,vhere m == n == 3 and

e

1 ==

'

2 3

2 1 2

3 2 1

U ==

2 3 4

,,

and v ==

2 2

GAMS basic commands

SETS Examples: o SET J. /ml" m2" m3/; .



SET

J /ml*m3/;



SET

J /1*3/;



SET

J

. .

explanation /1*3/;

Related commands: •

Alias (j,jj)



Card (j)



Ord (j)

Transport problem GAMS ** ** ** **

First, indices are declared and Index I is r1sed to refer to the Index is r1sed to refer to the I\Tote hov the s}"mbol ' *, is r1sed

SETS I inde.& a f s hipping a ri gins inde.& af s hipping dest inatian s

defined. three or.1gins. three destinations. to list sets members in a compact vay.

/ I

r-

I 3/ 3/ ;

m: n:

1

1

he number of origins. he number of de tinations.

m = n = 3

SCALARS Examples:

SCALAR f /0º056/;

SCALAR f explanation /0º056/;

PARAMETERS (vector of data) Examples: •

PARAMETER a(i) capacity of plant i in tons

/pl

p2 •

300 500/;

PARAMETER c(i,j) transportation cost

/ploml

300

pl om2

500

p2oml

400

p2om2

250 /;

TABLES (matrix of data) Examples: TABLE d (i,j) distance in km

pl p2



for ((i,j),

c(i,j)=3);

0

c(i,j) = 3;

0

c('pl',j) = 3;

0

c('pl','ml') = 3;

Transport problem GAMS u i : the a mount to be shipped from origin i. , j :

the an1ount to be reoeived in destina ion j.

2

U= ! (

** **

andv =

(D

Vectors of data (U(I) and V(J)) are defined as parameters ata are assigned to vector elements

PARAMETERS

U ( )i

t be

aro.O"

/I

2

,t

of

good to b e s , ipped fro :m. origi:n

,t

of

good to b e received in destin ation J

I2 3

I3 4 / t b e amo

/'

5 2 2 3 2/ ;

Transport problem GAMS ** **

The C ( I,J) data matrix is defined as a table ata are assigned to matrix elements

TAB:L E C (I, - )1

I

I.2

I3

2 3

c ast af sen d ing a 2 2 1 2

ni t fra m. arigi:n

ta dest ina t i a:n

3 3

2

.

~

'C ij : the cost of sending a unit of product from origin. i to des1ination j.

C=

1 2 3 2 1 2 3 2 1

VARIABLES Examples: Variable x(i,j) explanation ; •

Variable a, b, c(i); Free Variable h; Positive Variable h;

Types: Free, Binary, Integer, Positive and Negative

Options: x.lo(i,j)=20

x.up(x,'jl') - 50

x.fx('il', 'j2')= 50

x.l(i,j)=50

Transport problem GAMS ** **

The C(I,J) data matrix is defined as a table ata are assigned to matrix elements

TABl..E C ( I, - )1 cas t 2

3

2

3

2

I I.2

2

1

I3

3

2

** ** **

af sen din g a

fra m. arigi:n

ta destin atia:n

.

~

The optimization variables are declared. First, the objective function variable (z) is declared. Next, the remaining variables vith controlling indices are declared.

ARIAB:LES z ab j ect ive f .& (

ni t

,

)

t

e ama · , t

,ctian variab e af prad et ta be s ipped fram. arigi:n

ta destin a.tia ,

Transport problem GAMS ** ** **

The t:vpes of variables are given in the folloving sentence. In the transportation problemf all the variables are positive except the objective function variable.

ros I TIVE

VARIABLE

X (

.,

) ;

1Xij > O;

i

1 ... m;, j

1, ... ,

n. 1

EQUATIONS Examples: Equation Eql Eql ••

Texto descriptivo ;

a =e= b*S + 3;

Equation Eq2(i) Eql(i) ••

a =g= b(i)*S + 3;

Types: -g- -

--1--

Texto descriptivo ;

=e=

Transport problem GAMS ** ** **

The t:vpes of variables are given in the folloving sentence. In the transportation problemf all the variables are positive except the objective function variable.

ros I TIVE ** ** **

VARIABLE

X (

.,

) ;

The objective function equation is declared. The remaining six equations are declaredf in a compact vayf as tvo index-dependent equations .

. UATIONS COS S ñI P ( I )

RECE I VE ( . )1

abjectiv e f nct ian eq a.tian s l:üpping eq a.ti o , recei ving eq a.tiaiil ;

Transport problem GAMS ** ** ** ** ** ** ** **

The folloving sentences fo.rmulate the above declared equations. ~~l the constraints are equality constraints (=E=). The first one defines the objective function equation as a sr.immation. The second equation group represents three different single equations depending on index I. The left-hand-side is a sum in of the unknovns x ( I, ), and the right-hand-side is a previously defined vector of data. Similarly to SHIP constraints, the RECEIVE constraints are defined.

.

COST . s·, P ( )

smq ,

.& (

RECE V.IE ( )

SOO ( I,

.&

z

SOO ( ( I, - )1, C( I, - )1 ·X ('

=E=

,

)1 )

( I,

)1 )

E= E=

U(

)1

V(

)1

,

))

.

. .

n '1Th

z-

X· · I: J j= l

n

EE i= l j = l

CijXij •

'U,i • 'l

ni

E i= l

x-¡

Vj " j

.

l .'

m.

1 .

n-

'

MODEL Examples: MODEL Transporte /Eql,Eq2/ ; MODEL Transporte /All/ ; MODEL Transporte explanation /All/ ;

SOLVE Examples: SOLVE Transporte using nlp maximizing z; 0

SOLVE Transporte using lp minimizing z;

nlp dnlp m1p rnn

minlp rminlp mcp mpec cns

SOLVE Suffixes: o

. modelstat

o

.solvestat

o

.resusd

5

6 7

9

10 11 12 13

Options:

OPTION optcr

-

0.1

,

OPTION optca

-

o

,

OPTION iterlim OPTION reslim

le8

,

o

lelO ,

o

o

o

modelstat

solvestat

ptimal (lp rmip ) lo all op imal (nlp) unbound d (lp rmi p nlp) infi as·b (lp rmíp) lo ally infe ibl (nlp) in ermediate infea ible (nlp) m rmedia non-op ilnal (nlp) m g r olution (míp) in r dia e non-i t g r (mip) in g · · f as· I (mip)

normal om l ion i ra i n in rr 1p r 'Ourc inte rupt m·na d by ver evaluation error limí error

rror unknown , rror no solu ion

Transport problem GAMS ** ** ** ** ** ** ** **

The folloving sentences fo.rmulate the above declared equations. ~~l the constraints are equality constraints (=E=). The first one defines the objective function equation as a sr.immation. The second equation group represents three different single equations depending on index I. The left-hand-side is a sum in of the unknovns x ( I, ), and the right-hand-side is a previously defined vector of data. Similarly to SHIP constraints, the RECEIVE constraints are defined.

.

. COST s·, P ( )

smq ,

.& (

RECE V.IE ( )

SOO ( I,

.&

**

z

SOO ( ( I, - )1, C(I, - )1 ·X ('

=E=

,

)1 )

( I,

)1 )

E= E=

U(

)1

V(

)1

,

))

.

. .

The next sentence names the model and list its constraints.

DEL trr-ainsparr-t / OOS ,S

P,R1ECE V.IE / ;

Transport problem GAMS ** ** ** ** ** ** ** **

The folloving sentences fo.rmulate the above declared equations. ~~l the constraints are equality constraints (=E=). The first one defines the objective function equation as a sr.immation. The second equation group represents three different single equations depending on index I. The left-hand-side is a sum in of the unknovns x ( I, ), and the right-hand-side is a previously defined vector of data. Similarly to SHIP constraints, the RECEIVE constraints are defined.

.

. COST s·, P ( )

smq ,

.& (

RECE V.IE ( )

SOO ( I,

.&

**

z

=E=

,

)1 )

( I,

)1 )

.

The next sentence names the model and list its constraints.

DEL trr-ainsparr-t / OOS ,S

** **

C(I, - )1 ·X (' , )) E= U( )1 . E= V( )1 .

SOO ( ( I, - )1,

P,R1ECE V.IE / ;

The next sentence directs GAMS to solve the transportation model using a linear programming solver lp to minimize the objective function.

SO:LVE t rr-ainspa rr-t US NG

p M N MIZ NG z ;

DISPLAY Examples: •

DISPLAY e;



DISPLAY Eq2.m, Eql.m;



DISPLAY x.l;



DISPLAY ~Hello!" ;

DEBUGGING 1.

Write only a small part of the program and run it

2.

Fix the errors, starting from the top of the error messages



Windows: click on the error

3. Outcomment part of your program to locate the error

• * •

$ontext $offtext

Example

Let's try

. lst file ---- COST COST ..

ab j e c t i v e f ., nctian e q u at ian

z - .x. (I , -

----

= E=

1) -

2 "'x ( I 2 , J3 ) -

5 ~;1p

= E=

s

.

,

-1 )

2".x (I ,

3 "x ( I 3 , Jl )

x (I

SHI P (I 2 )

.X

(I 2, 1 )

x (I 2,J2 }

SHI P (I 3 )

X

(I 3, J l )

X

= E=

-

3"'.x (I ,

3) -

2".x (I2 ,

) - x (I2 ,

2 '"' x ( I 3 , J 2 ) - x ( I 3 , J3 ) = E= O ,

2)

( LHS = O )

ippi g e qua tia:n

SHI P (I1 )

---- RECE VE

2) -

x (I 1 ,

2)

+ x ( I • - 3 ) = E= 2 +

(I 3, J2 )

;5 =

.X

(I 2, J3 ) = E= 3

s

X

(I 3, J3 ) = E= 4

s

=

o

'

INFES = 2 ""'" " )

º·

INFES = 3 '" "'"'" )

o,

INFES = 4

'ifi!''ii('iti!'iif )1

r e c e i vL g e qua.tia_

RECEI\1E ( - ) . .

x (I 1 , - )

+ x ( I2, 1 )

x (I3 , - 1 ) = E= 5 ,

(Li:íS = O,

INFES = 5 ,., ,..,., ,"' )

RECE IVE ( J 2 ) . .

x ( I 1 , J2 )

+ x ( I 2 , J2 )

x (I3 , J 2 ) = E= 2 ,

(LHS = O,

INFES = 2

RECEI\1E (J3 ) ..

x (I 1 , J3 )

(I 2, J3 )

x (I 3,J3 ) = E= 2 ,

(LHS

INFES

X

O,

·' ·' )

. lst file MODE

s

es

BLOCKS OF E UAT'IONS Ei ·CT-