Unknown identifier entered as set

i am having trouble writing out the following KKT condition
Screenshot 2022-04-06 at 15.48.03.png
If i type the following code in it works (provisionally) fine:
Screenshot 2022-04-06 at 15.54.03.png
but ideally, i would not like to have a separate variable mu_Russia. I would like to define mu over the set players1: mu(players1). Then type it into the equation. However, if I do this, this annoying error comes up:
Screenshot 2022-04-06 at 15.53.15.png
How do i solve this? In this example, it is not crucial because I can work around it. But for other KKT conditions, I face similar problems (that are harder to explain) without an obvious workaround.

Sorry for posting twice in three days but no one answered my first post. Hopefully, this post is better explained and I would be very grateful for a response.

My dissertation is about modelling coking coal markets.

Hi there,

It seems like you might need a mapping set that will link the mine to the country it is in… something like this:

set mine / mine1*mine3 /;
set country / Russia, Germany /;
set mine2country(mine,country) /
	mine1.Russia
	mine2.Russia
	mine3.Germany /;

Then you could probably do something like this to flexibly define your KKTs (slightly stylized code):

Variable mu(country);
Parameter lambda(mine);

KKT_2(mine).. s_coefs(mine,"c") + lambda(mine) - sum(mine2country(mine,country), mu(country)) =g= 0;

The error you are seeing is because you input Russia directly as if it were a set. You could get around this error by hard coding…

mu("Russia")

Or, even more fun… you could create a singleton set (which allows you to avoid putting in the summation as we had to do above)…

set countries "all the countries in your model" / Germany, France, Russia /;
singleton set Russia(countries) / Russia /;
...
KKT_2(Rus_mines).. s_coefs(Rus_mines,"c") + lambda(Rus_mines) - mu(Russia) =g= 0;

Hi achristensen

thanks so much for your reply, it was very helpful. I initially tried

mu("Russia")

since this seemed like the most straightforward approach and it got rid of the error messages. But it didn’t work with the model statement i think because my dimensions were still a bit messed up. So i did the approach of creating a set map which took a while (there are like 200 mines in the data set). That worked and the results it gives out are very reasonable. However, the prices are a bit lower and the quantity a bit higher than i was expecting. I also programmed the same problem as a MCP with only 2 KKT conditions, much simpler… but not possible to extend to a Stackelberg model. Here are the results side by side:
Screenshot 2022-04-07 at 01.11.25.png
Screenshot 2022-04-07 at 01.11.40.png
Most countries have the same production because they are maxing out their capacity in both cases but Australia and US have different productions and trade flows for some reason.
Since today’s model has more complex lines of programming, i think it’s likely I’ve made an error on today’s model. Are there any obvious errors that stand out to you in my KKT conditions?

KKT_1(players1,j)..    tc(players1,j)-p(j)+ d_coefs(j,"eta")*s(players1,j)+mu(players1) =g=0;

KKT_2(n)..              s_coefs(n,"c") + lambda(n) - sum(mine2players1(n,players1), mu(players1)) =g= 0;

KKT_3(n)..              s_coefs(n,"cap")-z(n) =g= 0   ;

KKT_4(players1)..      sum(mine2players1(n,players1), z(n)) -sum(j,s(players1, j)) =g= 0;

.

Here are the KKT conditions in original form from Lorenczik and Panke (2016)
Screenshot 2022-04-07 at 01.14.23.png
Screenshot 2022-04-07 at 01.15.31.png
Anyways thanks for helping. I think tomorrow i might get my pen and paper out and start calculating first-order conditions to see in which model Australia is failing to maximises it’s profits (the optimal amount to ship to Asia has to be 32 million tonnes or 24 million tonnes, can’t be both).
~$April6.gms (15.9 KB)
Screenshot 2022-04-07 at 01.21.10.png
Screenshot 2022-04-07 at 01.24.48.png
Screenshot 2022-04-07 at 01.11.03.png