GAMS indexing issues

Problems with syntax of GAMS
Post Reply
robertcarlsson
User
User
Posts: 1
Joined: 2 months ago

GAMS indexing issues

Post by robertcarlsson » 2 months ago

Im completely new to GAMS and I am having some issues with trying to implement my model. I am trying to code a New Economic Geography optimisation model where 3 sets of non-linear equations that are interdependent need to be solved using an optimisation criteria. In the model there are n regions (for simplicity lets assume we have 2 regions. The equations that set out the problems are:

y(i) = lambda(i)*delta*w(i) + 0.5*(1-delta)
p(i) = ( sum(i,2, lambda(i) * (w(i)^(1-epsilon)) * (T(i)^(1-epsilon)) ))^(1/(1-epsilon))
w(i) = ( sum(i,2, y(i) * (p(i)^(epsilon-1)) * (T(i)^(1-epsilon)) ))^(1/epsilon)

and the goal function we want to maximise is: z = sum(i, y(i))

Which leads to 2*n+1 = 7 equations.

The code I have written is:

Set
i 'regions' / A, B /;

Parameter
T(i) 'transportation cost' /A 1
B 1/
lambda(i) 'fraction of labourers in region' / A 0.4
B 0.6 /;
Scalar
delta 'fraction of income spent on manufactured goods' / 0.7 /
epsilon 'substitutability' / 1.5 /;

VariablePositive Variable y(i),w(i),p(i);

Equation
incomeEquation(i) 'income level in region i'
wageEquation(i) 'wage level in region i'
priceEquation(i) 'prive level in region i'
GDP 'total income of economy';
z 'total income'
y(i) 'income level'
w(i) 'wage level'
p(i) 'price level';

GDP.. z =e= sum(i,y(i));
incomeEquation(i).. y(i) =e= (lambda(i)*delta*w(i) + 0.5*(1-delta));
wageEquation.. w(i) =e=(sum(i,y(i)*(T(i)**(1-epsilon))*(p(i)**(epsilon-1))))**(1/epsilon);
priceEquation.. p(i) =e= (sum(i, lambda(i)*(w(i)**(1-epsilon))*(T(i)**(1-epsilon))))**(1/(1-epsilon));

Model neecge / all /;

solve neg using nlp maximizing z;

The error codes I get are 148 and 149 (The identifier is referenced with more or less indexed sets than in the declaration. AND The set is not controlled, neither by an indexed operation like sum, nor by an equation definition, nor by a loop or similar.)

I understand the error, that I have used the set indices twice but I am not sure how to implement the self referencing equations using the GAMS syntax. Any ideas? Any help would be useful and please remember that I am completely new to this:).

Thank you.

User avatar
bussieck
Moderator
Moderator
Posts: 330
Joined: 2 years ago

Re: GAMS indexing issues

Post by bussieck » 1 week ago

If you need a second i index in your equation logic use ALIAS. There were lots of other compilation errors, but this one compiles and produces an optimum solution. Not sure if this is what you had in mind. BTW, for code there a nice code section syntax.

-Michael

Code: Select all

Set
i 'regions' / A, B /;

Parameter
T(i) 'transportation cost' /A 1
B 1/
lambda(i) 'fraction of labourers in region' / A 0.4
B 0.6 /;
Scalar
delta 'fraction of income spent on manufactured goods' / 0.7 /
epsilon 'substitutability' / 1.5 /;

variables
z 'total income'
y(i) 'income level'
w(i) 'wage level'
p(i) 'price level';

Positive Variable y(i),w(i),p(i);

Equation
incomeEquation(i) 'income level in region i'
wageEquation(i) 'wage level in region i'
priceEquation(i) 'prive level in region i'
GDP 'total income of economy';

alias (i,i2);
GDP.. z =e= sum(i,y(i));
incomeEquation(i).. y(i) =e= (lambda(i)*delta*w(i) + 0.5*(1-delta));
wageEquation(i).. w(i) =e=(sum(i2,y(i2)*(T(i2)**(1-epsilon))*(p(i2)**(epsilon-1))))**(1/epsilon);
priceEquation(i).. p(i) =e= (sum(i2, lambda(i2)*(w(i2)**(1-epsilon))*(T(i2)**(1-epsilon))))**(1/(1-epsilon));

Model neecge / all /;
p.lo(i) = 1e-6;
w.lo(i) = 1e-6;
y.l(i) = 1;
p.l(i) = 1;
w.l(i) = 1;

solve neecge using nlp maximizing z;

Post Reply