Parameter value assignment based on a loop and conditional statements

Archive of Gamsworld Google Group
Post Reply
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Parameter value assignment based on a loop and conditional statements

Post by Archiver »


Hello,

I have a problem coming up with a code for a loop command to populate a parameter based on conditional statements comparing the values from two other parameters.

Assume I have a price and quantity (supply) data as p(i) and qs(i) defined over set i. I manage to build a cumulative curve based on the sorted values of these parameters. Now I have data on a fictitious demand, qadj(i) defined over the same set. My objective is to determine the "intersection" with the cumulative supply, qscum(i), and based on that I determine a new set of prices I want to store in a parameter padj(i). In other words, I want to create a "loop" statement that does the following:

For each element in set i,

if qd(i) >= qscum(i)

peq(i) = psorted(i)

And so, the objective is to repeat this procedure until every single element for peq(i) is defined. I have attached a .gms file I created to illustrate the problem I am facing. Of course, I am looking actually to do this with real data in a model of price determination for forest feedstock in Sweden, which is geographically explicit in the sense that each element in set i represent a gridcell with corresponding data on harvest cost, supply, and potential demand.

I would really appreciate the help and if the description is somewhat convoluted, please forgive the inconvenience.

Best
Ismail

--
Attachments
Untitled_3.gms
(1.08 KiB) Downloaded 334 times
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: Parameter value assignment based on a loop and conditional statements

Post by Archiver »


Ismail: The file you sent does exactly that. What is the problem ?

You say: "the objective is to repeat this procedure until every single element for peq(i) is defined"

Nevertheless, you are only providing a definition for those members of i for which qd(i) is greater or equal than qscum(i).
What should be the definition for the rest (qd(i) =qscum(i))+other_value$(qd(i) wrote:

Hello,

I have a problem coming up with a code for a loop command to populate a parameter based on conditional statements comparing the values from two other parameters.

Assume I have a price and quantity (supply) data as p(i) and qs(i) defined over set i. I manage to build a cumulative curve based on the sorted values of these parameters. Now I have data on a fictitious demand, qadj(i) defined over the same set. My objective is to determine the "intersection" with the cumulative supply, qscum(i), and based on that I determine a new set of prices I want to store in a parameter padj(i). In other words, I want to create a "loop" statement that does the following:

For each element in set i,

if qd(i) >= qscum(i)

peq(i) = psorted(i)

And so, the objective is to repeat this procedure until every single element for peq(i) is defined. I have attached a .gms file I created to illustrate the problem I am facing. Of course, I am looking actually to do this with real data in a model of price determination for forest feedstock in Sweden, which is geographically explicit in the sense that each element in set i represent a gridcell with corresponding data on harvest cost, supply, and potential demand.

I would really appreciate the help and if the description is somewhat convoluted, please forgive the inconvenience.

Best
Ismail

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.


--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: Parameter value assignment based on a loop and conditional statements

Post by Archiver »


It does not really do what I have in mind. My code basically assigns a value to peq(i) from psorted(i) by comparing qd(i) and qscum(i) for each i = 1...10, i.e. it moves one step at a time through the set i by comparing each element. Given qscum(i) and psorted(i), I build a supply curve. Now, for each qd(i), I want to determine where it lies on the supply curve and derive a peq(i) as that point of intersection. In other words, I want to pick qd(i) one at a time, compare it to all the values of qscum(i), once it hit the value I specify by my condition, I get the corresponding psorted(i) associated with it and assign to peq(i). Hence, the process needs to be iterated for qd(i+1) again in the same fashion. Hence me pointing out that a loop statement would be necessary to achieve this.

Regards
Ismail

On Monday, March 7, 2016 at 7:54:33 AM UTC+1, Claudio Delpino wrote:

Ismail: The file you sent does exactly that. What is the problem ?

You say: "the objective is to repeat this procedure until every single element for peq(i) is defined"

Nevertheless, you are only providing a definition for those members of i for which qd(i) is greater or equal than qscum(i).
What should be the definition for the rest (qd(i) =qscum(i))+other_value$(qd(i) wrote:

Hello,

I have a problem coming up with a code for a loop command to populate a parameter based on conditional statements comparing the values from two other parameters.

Assume I have a price and quantity (supply) data as p(i) and qs(i) defined over set i. I manage to build a cumulative curve based on the sorted values of these parameters. Now I have data on a fictitious demand, qadj(i) defined over the same set. My objective is to determine the "intersection" with the cumulative supply, qscum(i), and based on that I determine a new set of prices I want to store in a parameter padj(i). In other words, I want to create a "loop" statement that does the following:

For each element in set i,

if qd(i) >= qscum(i)

peq(i) = psorted(i)

And so, the objective is to repeat this procedure until every single element for peq(i) is defined. I have attached a .gms file I created to illustrate the problem I am facing. Of course, I am looking actually to do this with real data in a model of price determination for forest feedstock in Sweden, which is geographically explicit in the sense that each element in set i represent a gridcell with corresponding data on harvest cost, supply, and potential demand.

I would really appreciate the help and if the description is somewhat convoluted, please forgive the inconvenience.

Best
Ismail

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.


--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: Parameter value assignment based on a loop and conditional statements

Post by Archiver »


Ismail:

Something like this ? It should give you ideas:


On Wed, Mar 9, 2016 at 6:04 AM, Ismail OURAICH wrote:

It does not really do what I have in mind. My code basically assigns a value to peq(i) from psorted(i) by comparing qd(i) and qscum(i) for each i = 1...10, i.e. it moves one step at a time through the set i by comparing each element. Given qscum(i) and psorted(i), I build a supply curve. Now, for each qd(i), I want to determine where it lies on the supply curve and derive a peq(i) as that point of intersection. In other words, I want to pick qd(i) one at a time, compare it to all the values of qscum(i), once it hit the value I specify by my condition, I get the corresponding psorted(i) associated with it and assign to peq(i). Hence, the process needs to be iterated for qd(i+1) again in the same fashion. Hence me pointing out that a loop statement would be necessary to achieve this.

Regards
Ismail

On Monday, March 7, 2016 at 7:54:33 AM UTC+1, Claudio Delpino wrote:

Ismail: The file you sent does exactly that. What is the problem ?

You say: "the objective is to repeat this procedure until every single element for peq(i) is defined"

Nevertheless, you are only providing a definition for those members of i for which qd(i) is greater or equal than qscum(i).
What should be the definition for the rest (qd(i) =qscum(i))+other_value$(qd(i) wrote:

Hello,

I have a problem coming up with a code for a loop command to populate a parameter based on conditional statements comparing the values from two other parameters.

Assume I have a price and quantity (supply) data as p(i) and qs(i) defined over set i. I manage to build a cumulative curve based on the sorted values of these parameters. Now I have data on a fictitious demand, qadj(i) defined over the same set. My objective is to determine the "intersection" with the cumulative supply, qscum(i), and based on that I determine a new set of prices I want to store in a parameter padj(i). In other words, I want to create a "loop" statement that does the following:

For each element in set i,

if qd(i) >= qscum(i)

peq(i) = psorted(i)

And so, the objective is to repeat this procedure until every single element for peq(i) is defined. I have attached a .gms file I created to illustrate the problem I am facing. Of course, I am looking actually to do this with real data in a model of price determination for forest feedstock in Sweden, which is geographically explicit in the sense that each element in set i represent a gridcell with corresponding data on harvest cost, supply, and potential demand.

I would really appreciate the help and if the description is somewhat convoluted, please forgive the inconvenience.

Best
Ismail

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.


--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.


--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: Parameter value assignment based on a loop and conditional statements

Post by Archiver »


(Sorry, accidentally sent)

alias(i,j);
loop(i,
loop(j,
if(qd(i)>= qscum(j),
peq(i) = psorted(j);)
);
);

Not intended to do exactly what you want (because I don't get it yet, see PS), but it will hopefully get you on track.


PS: I'm not an economic modeller so words like "cumulative supply curve" have no meaning to me other than I can identify they belong in economic modelling :) .

On Wed, Mar 9, 2016 at 9:21 AM, Claudio Delpino wrote:

Ismail:

Something like this ? It should give you ideas:


On Wed, Mar 9, 2016 at 6:04 AM, Ismail OURAICH wrote:

It does not really do what I have in mind. My code basically assigns a value to peq(i) from psorted(i) by comparing qd(i) and qscum(i) for each i = 1...10, i.e. it moves one step at a time through the set i by comparing each element. Given qscum(i) and psorted(i), I build a supply curve. Now, for each qd(i), I want to determine where it lies on the supply curve and derive a peq(i) as that point of intersection. In other words, I want to pick qd(i) one at a time, compare it to all the values of qscum(i), once it hit the value I specify by my condition, I get the corresponding psorted(i) associated with it and assign to peq(i). Hence, the process needs to be iterated for qd(i+1) again in the same fashion. Hence me pointing out that a loop statement would be necessary to achieve this.

Regards
Ismail

On Monday, March 7, 2016 at 7:54:33 AM UTC+1, Claudio Delpino wrote:

Ismail: The file you sent does exactly that. What is the problem ?

You say: "the objective is to repeat this procedure until every single element for peq(i) is defined"

Nevertheless, you are only providing a definition for those members of i for which qd(i) is greater or equal than qscum(i).
What should be the definition for the rest (qd(i) =qscum(i))+other_value$(qd(i) wrote:

Hello,

I have a problem coming up with a code for a loop command to populate a parameter based on conditional statements comparing the values from two other parameters.

Assume I have a price and quantity (supply) data as p(i) and qs(i) defined over set i. I manage to build a cumulative curve based on the sorted values of these parameters. Now I have data on a fictitious demand, qadj(i) defined over the same set. My objective is to determine the "intersection" with the cumulative supply, qscum(i), and based on that I determine a new set of prices I want to store in a parameter padj(i). In other words, I want to create a "loop" statement that does the following:

For each element in set i,

if qd(i) >= qscum(i)

peq(i) = psorted(i)

And so, the objective is to repeat this procedure until every single element for peq(i) is defined. I have attached a .gms file I created to illustrate the problem I am facing. Of course, I am looking actually to do this with real data in a model of price determination for forest feedstock in Sweden, which is geographically explicit in the sense that each element in set i represent a gridcell with corresponding data on harvest cost, supply, and potential demand.

I would really appreciate the help and if the description is somewhat convoluted, please forgive the inconvenience.

Best
Ismail

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.


--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.



--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Post Reply