Solving for equilibrium

52 views
Skip to first unread message

Nilu

unread,
Dec 28, 2009, 3:27:22 PM12/28/09
to AMPL Modeling Language
Here is the general structure of the problem i want to solve :-

Suppose there are two programs 1 and 2 each of which solves for A that
is A1 and A2 as functions of some parameter vector p = (p1, p2, p3).
So we now have A1 (p) and A2 (p). Then we need to check whether A1(p)
+ A2(p) = 0. If yes then solve for p and plug it back to get the final
values of A1 and A2.

So basically I am trying to find the equilibrium(Walrasian) and p are
prices, Ai can be thought of as asset demands.

I know only to solve programs in AMPL where the parameter values are
specified and nothing is left parametric. Can anyone suggest some ways
of doing this whole problem ??????

Paul

unread,
Dec 29, 2009, 11:35:22 AM12/29/09
to AMPL Modeling Language

Nilu wrote:
> Here is the general structure of the problem i want to solve :-
>
> Suppose there are two programs

LP? NLP? MILP? MINLP?

> 1 and 2 each of which solves for A

A being the objective function or the variable vector?

> that
> is A1 and A2 as functions of some parameter vector p = (p1, p2, p3).
> So we now have A1 (p) and A2 (p). Then we need to check whether A1(p)
> + A2(p) = 0. If yes then solve for p and plug it back to get the final
> values of A1 and A2.

This last makes no sense -- you obtain A1(p) and A2(p) for a specific
value of p, check the condition on their sum, and if yes there is
nothing left to solve.


>
> So basically I am trying to find the equilibrium(Walrasian) and p are
> prices, Ai can be thought of as asset demands.
>
> I know only to solve programs in AMPL where the parameter values are
> specified and nothing is left parametric. Can anyone suggest some ways
> of doing this whole problem ??????

You will need to be able to infer some rate-of-change information
(gradient, subgradient, something) for A1 and A2 with respect to p.
What you can infer and how you get it depend on the nature of your two
optimization problems. What to do with that information in turn
depends on what information you can get.

/Paul

Nilu

unread,
Dec 30, 2009, 3:05:03 AM12/30/09
to AMPL Modeling Language
Sorry, maybe I was not clear. So the programs are non-linear NLPs.
Think of the two programs as two individuals maximizing their
utilities. So objective function is Utility and not Ai. Ai is the
asset demand for ith individual and Ai(p) is the Asset demand as a
function of p, prices. So A is the variable vector. In AMPL, we use
specific values of the p, but my question is can it be programmed to
get Ai as function of parameter p and then solve for p from the
equation that A1(p) + A2(p) = 0, like we do in the calculation of
Walrasian eqm. Note I am saying that is there a way of programming in
AMPL or using other languages and calling programs from AMPL to solve
for a choice variable as a function of a parameter (asset demand as
function of parameter prices) and then solving for prices from the
total asset demand = asset net supply equation which is precisely A1
(p) + A2(p) = 0.
Thanks.

Paul

unread,
Dec 30, 2009, 11:16:36 AM12/30/09
to AMPL Modeling Language
Nilu wrote:
> Sorry, maybe I was not clear. So the programs are non-linear NLPs.
> Think of the two programs as two individuals maximizing their
> utilities. So objective function is Utility and not Ai. Ai is the
> asset demand for ith individual and Ai(p) is the Asset demand as a
> function of p, prices. So A is the variable vector. In AMPL, we use
> specific values of the p, but my question is can it be programmed to
> get Ai as function of parameter p and then solve for p from the
> equation that A1(p) + A2(p) = 0, like we do in the calculation of
> Walrasian eqm. Note I am saying that is there a way of programming in
> AMPL or using other languages and calling programs from AMPL to solve
> for a choice variable as a function of a parameter (asset demand as
> function of parameter prices) and then solving for prices from the
> total asset demand = asset net supply equation which is precisely A1
> (p) + A2(p) = 0.

What about writing a single model that contains A1, A2 and p as
variables, maximizes the sum of the two individual utility functions,
and contains the constraint A1 + A2 = 0? Other than that one
constraint, the two problems are separable, so if (A1*, A2*, p*) is
the optimal solution to the merged problem, then A1* must maximize
individual 1's utility when p = p* and similarly for A2*.

/Paul

Robert Fourer

unread,
Dec 31, 2009, 11:46:04 AM12/31/09
to am...@googlegroups.com, Nilu

It seems that first you have some known prices, and you want to solve two
optimization problems that maximize utility subject to two different
collections of constraints. Then using the results of those optimizations
you want to solve some related constraints with the prices as variables. Is
that right? This kind of thing can be done by use of an AMPL script. There
are some examples (though not for the application you have in mind) at
www.ampl.com/NEW/LOOP2; see also the discussions of alternating between
models and of named problems in sections 14.4 and 14.5 of the AMPL book.

Bob Fourer
4...@ampl.com

Nilu

unread,
Jan 1, 2010, 1:32:26 AM1/1/10
to AMPL Modeling Language
yes it is something like this. But when I use the repeat command, itis
always giving some errors. SO here is my full model and data:

param N integer;
set States := {1..2^(N+1)};
param d ;
param alpha1 ;
param gamma1 ;
param theta1 {States};
param si {States};
param ehat1 ;
param Lhat1 ;
param Rhat1 ;
var pe := 1 ;
var pR := 1 ;
var qR {States} := 1;
param alpha2 ;
param gamma2 ;
param theta2 {States};
param ehat2 ;
param Lhat2 ;
param Rhat2 ;
#### Variables #####
var e1 >= 0 ;
var T1 >= 0 ;
var L1 {States} >= 0;
var R1 {States} >= 0;
var beta1 {States};
var Ae1;
var AL1;
var AR1;
var yL1 {States};
var yR1 {States};
var e2 >= 0 ;
var T2 >= 0 ;
var L2 {States} >= 0;
var R2 {States} >= 0;
var beta2 {States};
var Ae2;
var AL2;
var AR2;
var yL2 {States};
var yR2 {States};
###### Objective function####
maximize Objective1 : sum {j in States} ((si[j]) * (gamma1) * (L1[j]
^alpha1) * (R1[j]^beta1[j])) ;
###### Constraints #####
subject to Constraint_54 {j in States}: beta1[j] = (1- alpha1) * (e1/
(theta1[j] + e1)) ;
subject to Constraint_55 : e1 = ehat1 + Ae1 - T1 ;
subject to Constraint_56 {j in States}: L1[j] = Lhat1 + AL1 + yL1[j] +
T1 ;
subject to Constraint_57 {j in States}: R1[j] = Rhat1 + AR1 + yR1[j] ;
subject to Constraint_58 : ((pe) * (Ae1)) + AL1 + ((pR) * (AR1)) = 0 ;
subject to Constraint_59 {j in States}: yL1[j] + ((qR[j]) * (yR1[j]))
= 0;


maximize Objective2 : sum {j in States} ((si[j]) * (gamma2) * (L2[j]
^alpha2) * (R2[j]^beta2[j])) ;
###### Constraints #####
subject to Constraint_542 {j in States}: beta2[j] = (1- alpha2) * (e2/
(theta2[j] + e2)) ;
subject to Constraint_552 : e2 = ehat2 + Ae2 - T2 ;
subject to Constraint_562 {j in States}: L2[j] = Lhat2 + AL2 + yL2[j]
+ T2 ;
subject to Constraint_572 {j in States}: R2[j] = Rhat2 + AR2 + yR2
[j] ;
subject to Constraint_582: ((pe) * (Ae2)) + AL2 + ((pR) * (AR2)) = 0 ;
subject to Constraint_592 {j in States}: yL2[j] + ((qR[j]) * (yR2[j]))
= 0;

data :

param N := 2;
param alpha1:= 0.25 ;
param gamma1:= 4.00 ;
param si := 1. 0.0825 2. 0.1675 3. 0.0825 4. 0.1675 5. 0.1675 6.
0.0825 7. 0.1675 8. 0.0825 ;
param theta1 := 1. 1 2. 2 3. 1 4. 2 5. 2 6. 1 7. 2 8. 1 ;
param ehat1 := 3.25;
param Lhat1 := 2.08;
param Rhat1 := 11.57;

param d := 0.1;
param alpha2:= 0.35 ;
param gamma2:= 3.00 ;
param theta2 := 1. 0.75 2. 1.5 3. 1.5 4. 0.75 5. 1.5 6. 1.5 7. 0.75 8.
0.75 ;
param ehat2 := 2.08;
param Lhat2 := 2.47;
param Rhat2 := 8.19;

and the commands:
model ...mod;
data ....dat;
option solver knitro;
problem SOLVE1: Objective1, e1, T1, L1, R1, Ae1, AL1, AR1, yL1, yR1,
Constraint_54, Constraint_55, Constraint_56, Constraint_57,
Constraint_58, Constraint_59 ;
problem SOLVE2: Objective2, e2, T2, L2, R2, Ae2, AL2, AR2, yL2, yR2,
Constraint_542, Constraint_552, Constraint_562, Constraint_572,
Constraint_582, Constraint_592 ;

repeat { solve SOLVE1; solve SOLVE2;
if |Ae1 + Ae2| >= d, |AL1 + AL2| >= d, |AR1 + AR2| >= d, |yL1
+ yL2| >=d, |yR1 + yR2| >= d then { let pe := pe + (0.5)*(Ae1 +
Ae2) , pR := pR + (0.5)*(AR1 + AR2) , qR := qR + (0.5)*(yR1 + yR2) ;}
else break; }

the errors are :
file -
line 1
offset 39
syntax error
file -
line 1
offset 231
extra }
file -
line 1
offset 246
extra }

Any suggestions would be helpful.


On Dec 31 2009, 10:46 am, "Robert Fourer" <4...@ampl.com> wrote:
> It seems that first you have some known prices, and you want to solve two
> optimization problems that maximize utility subject to two different
> collections of constraints.  Then using the results of those optimizations
> you want to solve some related constraints with the prices as variables.  Is
> that right?  This kind of thing can be done by use of an AMPL script.  There

> are some examples (though not for the application you have in mind) atwww.ampl.com/NEW/LOOP2;see also the discussions of alternating between


> models and of named problems in sections 14.4 and 14.5 of the AMPL book.
>
> Bob Fourer
> 4...@ampl.com
>
>
>
> > -----Original Message-----
> > From: am...@googlegroups.com [mailto:am...@googlegroups.com]
> > On Behalf Of Nilu [nilu8...@gmail.com]
> > Sent: Wednesday, December 30, 2009 2:05 AM
> > To: AMPL Modeling Language
> > Subject: [AMPL 3165] Re: Solving for equilibrium
>
> > Sorry, maybe I was not clear. So the programs are non-linear NLPs.
> > Think of the two programs as two individuals maximizing their
> > utilities. So objective function is Utility and not Ai. Ai is the
> > asset demand for ith individual and Ai(p) is the Asset demand as a
> > function of p, prices. So A is the variable vector. In AMPL, we use
> > specific values of the p, but my question is can it be programmed to
> > get Ai as function of parameter p and then solve for p from the
> > equation that A1(p) + A2(p) = 0, like we do in the calculation of
> > Walrasian eqm. Note I am saying that is there a way of programming in
> > AMPL or using other languages and calling programs from AMPL to solve
> > for a choice variable as a function of a parameter (asset demand as
> > function of parameter prices) and then solving for prices from the
> > total asset demand = asset net supply equation which is precisely A1
> > (p) + A2(p) = 0.

> > Thanks.- Hide quoted text -
>
> - Show quoted text -

Robert Fourer

unread,
Jan 2, 2010, 1:30:29 PM1/2/10
to am...@googlegroups.com, Nilu

While the AMPL language is intended to be much like familiar mathematical
notation, the technology has not progressed to the point where the processor
can recongize every notation that a reasonably experienced person might be
expected to be able to interpret. Thus "," and "|...|" are not recognized
as operators, and indexed entities such as yL1 and qR must be followed by a
subscript [...]. I have copied below a guess at how your repeat loop should
look, though it's only a guess since I don't know what you're trying to
test.

Bob Fourer
4...@ampl.com


repeat {
solve SOLVE1;
solve SOLVE2;

if abs(Ae1 + Ae2) >= d and
abs(AL1 + AL2) >= d and
abs(AR1 + AR2) >= d and
(forall {i in States} abs(yL1[i] + yL2[i]) >= d) and
(forall {i in States} abs(yR1[i] + yR2[i]) >= d) then {
let pe := pe + (0.5)*(Ae1 + Ae2);
let pR := pR + (0.5)*(AR1 + AR2);
let {i in States} qR[i] := qR[i] + (0.5)*(yR1[i] + yR2[i]);
}
else break;
};

Nilu

unread,
Jan 4, 2010, 4:39:55 AM1/4/10
to AMPL Modeling Language
Thanks Bob..................i have another question related to
this.......so i want to check each contraint abs(Ae1 + Ae2) >= d ,
abs(AL1 + AL2) >= d etc one by one and then increase the
corresponding prices.
So what I want to do is like this ( for 2 constraint case):-

repeat { solve SOLVE1; solve SOLVE2;

if abs(Ae1+ Ae2) >= d then {let pe := pe + (0.5)*(Ae1 +
Ae2) ; }
else { if abs (AR1 + AR2) >= d then {let pR := pR + (0.5)*
(AR1 + AR2); }
else break ;}} ;


So for more than 2 constraints, I will have many if-else statements.
But my problem is that AMPL stops responding once I enter the above
repeat command. That means that the syntax is okay but there may be
some other problem.

What I am here solving is for the general equilibrium ( Radner eqm ).
So here my approach is to solve for the individual asset demands (as
funstion of prices) and then check for asset dd. = asset ss. condition
and if it is not satisfied then change the price in opposite direction
and solve again and so on. I have many assets and hence many
constraints to check. i was trying to check it one by one and hence
many if-else statements, but AMPL stops responding.
Do you know of any method to solve for GENERAL EQUILIBRIUM ( in
exchange settings) ?????

Thanx

> > atwww.ampl.com/NEW/LOOP2;seealso the discussions of alternating between


> > > models and of named problems in sections 14.4 and 14.5 of the AMPL book.
>
> > > Bob Fourer
> > > 4...@ampl.com
>
> > > > -----Original Message-----
> > > > From: am...@googlegroups.com [mailto:am...@googlegroups.com]
> > > > On Behalf Of Nilu [nilu8...@gmail.com]
> > > > Sent: Wednesday, December 30, 2009 2:05 AM
> > > > To: AMPL Modeling Language
> > > > Subject: [AMPL 3165] Re: Solving for equilibrium
>
> > > > Sorry, maybe I was not clear. So the programs are non-linear NLPs.
> > > > Think of the two programs as two individuals maximizing their
> > > > utilities. So objective function is Utility and not Ai. Ai is the
> > > > asset demand for ith individual and Ai(p) is the Asset demand as a
> > > > function of p, prices. So A is the variable vector. In AMPL, we use
> > > > specific values of the p, but my question is can it be programmed to
> > > > get Ai as function of parameter p and then solve for p from the
> > > > equation that A1(p) + A2(p) = 0, like we do in the calculation of
> > > > Walrasian eqm. Note I am saying that is there a way of programming in
> > > > AMPL or using other languages and calling programs from AMPL to solve
> > > > for a choice variable as a function of a parameter (asset demand as
> > > > function of parameter prices) and then solving for prices from the
> > > > total asset demand = asset net supply equation which is precisely A1
> > > > (p) + A2(p) = 0.

Guilherme P. de Freitas

unread,
Jan 4, 2010, 8:07:48 PM1/4/10
to am...@googlegroups.com
Why don't you try checking the ICE (instute for computational
economics) website:

http://ice.uchicago.edu/

Or contacting the researches involved with ICE. I know they teach
things like that in that workshop, and that they advocate AMPL, so
they probably have code for that.

Without getting in too much detail, do you know if you can use the
Negishi approach in your problem? If not, you might want to try
looking for formulations of the Walrasian equillibrium problem as a
problem with complementarity constraints.

Best,

Guilherme

> --
>
> You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
> To post to this group, send email to am...@googlegroups.com.
> To unsubscribe from this group, send email to ampl+uns...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ampl?hl=en.
>
>
>

--
Guilherme P. de Freitas
http://www.gpfreitas.com

Robert Fourer

unread,
Jan 5, 2010, 11:54:45 AM1/5/10
to am...@googlegroups.com, Nilu

AMPL may stop responding because the solver is taking a very long time,
because an error condition has occurred, or because it is stuck waiting for
more input while in the middle of a command. But to provide more specific
advice I would have to see a transcript of the output that AMPL produced
before it stopped responding, and complete copies of the files that you used
might also be helpful.

Incidentally, you don't need to write {...} after "then" or "else" if it
encloses only one statement. So for example you can write your nested
if-then-else command as

if abs(Ae1+ Ae2) >= d then
let pe := pe + (0.5)*(Ae1 + Ae2);
else if abs (AR1 + AR2) >= d then
let pR := pR + (0.5)*(AR1 + AR2);
else break;

Bob Fourer

Reply all
Reply to author
Forward
0 new messages