Domain Violation Error in GAMSPy Parameter Assignment

Question:

I’m encountering an issue with the following code in GAMSPy when trying to define savings (sav0). The error occurs in the assignment:

sav0= Parameter(m, name="sav0", domain=[investment,privateNAT], description="Savings for IS") 
sav0["CAP", "HH1"] = RA_out["HH1"] - Sum([goods], nom_Cons_sett0[goods, "HH1"])

The privateNAT set is defined as follows:

privateNAT = Set(
    m,
    name="privateNAT",
    domain=consumers,
    records=["NPI", "HH1", "HH2", "HH3", "HH4", "HH5", "HH6", "HH7", "HH8", "HH9", "HH10", "FC", "NFC"],
    description="Private national consumers."
)

Additionally, my RA_out data looks like this:

RA_out privateNAT value
0 NPI 16313.000000
1 HH1 18715.049444
2 HH2 36038.742059
3 HH3 44861.449646
4 HH4 51341.579784
5 HH5 59656.793666
6 HH6 70199.779479
7 HH7 80968.845735
8 HH8 89095.610764
9 HH9 107862.395621
10 HH10 183805.753366
11 FC 30164.000000
12 NFC 202360.000000

However, I receive the following error:

=============  
Error Summary  
=============  
3028  sav0(investment,"HH1") = (RA_out("HH1") - sum(goods,nom_Cons_sett0(goods,"HH1")));  
****                      $170             $170  
**** LINE      3 INPUT      
**** 170  Domain violation for element  
**** 2 ERROR(S)   0 WARNING(S)  

Strangely, similar assignments for savg and savrow work perfectly:

savg = Parameter(m, name="savg", domain=[investment, public], description="Savings for GOV")
savg["CAP", "GOV"] = RA_PA_out["GOV"] - Sum(goods, nom_PubExp_sett0[goods, "GOV"])

savrow = Parameter(m, name="savrow", domain=[investment, PRIVATEnoNAT], description="Savings for ROW")
savrow["CAP", "ROW"] = RA_ROW_out["ROW"] - Sum(goods, Exp_Sett0[goods, "ROW"])  

Given that privateNAT includes "HH1", why is GAMSPy throwing a domain violation error when using RA_out["HH1"] in the sav0 assignment? Any insights on what could be causing this discrepancy would be greatly appreciated!

Hi Marc.

Is it possible to share your script so that we get a better understanding of what’s going on? If not, maybe you can share a minimum reproducible example.

I tried to reproduce it with some dummy data that I made up but I didn’t receive the same error. Here is the example:

from gamspy import Container, Parameter, Set

m = Container()

investment = Set(m, records=["CAP"])
privateNAT = Set(
    m,
    name="privateNAT",
    records=[
        "NPI",
        "HH1",
        "HH2",
        "HH3",
        "HH4",
        "HH5",
        "HH6",
        "HH7",
        "HH8",
        "HH9",
        "HH10",
        "FC",
        "NFC",
    ],
    description="Private national consumers.",
)

RA_out = Parameter(m, name="RA_out", domain=privateNAT)
RA_out.generateRecords()

sav0 = Parameter(
    m,
    name="sav0",
    domain=[investment, privateNAT],
    description="Savings for IS",
)
sav0["CAP", "HH1"] = RA_out["HH1"]

Hi Muhammet,

Unfortunately, I can’t share the full code because it’s very long, more than 2000 lines, and some parts can’t be made public. But basically, the code does what you show in the example. I can share a large part of the script privately if needed.

Anyway, here are all the parts of the code involved in the line that fails:

privateNAT = Set(
    m,
    name="privateNAT",
    domain=consumers,
    records=["NPI", "HH1", "HH2", "HH3", "HH4", "HH5", "HH6", "HH7", "HH8", "HH9", "HH10", "FC", "NFC"],
    description="Private national consumers."
);

investment = Set(
    m,
    name="investment",
    domain=u,
    records=["CAP"],
    description="Investment."
);

* Total income of private NAT sectors
RA_out = Parameter(m, name="RA_out", domain=[privateNAT], description="Total income for private NAT sectors");
RA_out[privateNAT] = (
        Sum(L,RA1_out[privateNAT, L])
        +  Sum(K,RA2_out[privateNAT, K])
        + RA3_out[privateNAT, "GOV"]
        + RA4_out[privateNAT, "ROW"]
        + Sum(privvNAT, RA5_out[privateNAT, privvNAT])
        - Sum(consumers, RA6_out[privateNAT, consumers])
);

RA_out:

privateNAT value
NPI 16313.000000
HH1 18715.049444
HH2 36038.742059
HH3 44861.449646
HH4 51341.579784
HH5 59656.793666
HH6 70199.779479
HH7 80968.845735
HH8 89095.610764
HH9 107862.395621
HH10 183805.753366
FC 30164.000000
NFC 202360.000000

SAVING

sav0= Parameter(m, name="sav0", domain=[investment,privateNAT], description="Savings for IS");
sav0["CAP","HH1"] = RA_out["HH1"] - Sum([goods], nom_Cons_sett0[goods, "HH1"]); 

Error Summary

pgsql

3024  sav0("CAP","HH1") = (RA_out("HH1") - sum(goods,nom_Cons_sett0(goods,"HH1")));
****                 $170             $170
**** LINE      3 INPUT      
**** 170  Domain violation for element

**** 2 ERROR(S)   0 WARNING(S)

COMPILATION TIME     =        0.000 SECONDS      6 MB  48.4.0 d74fe9ea WEX-WEI

All I want is to store this result in an object like the one I define in sav0. If there is any alternative, that works too, but I don’t see how another part of the code could be causing the error when RA_out has the expected format.

I could share more details privately if needed.

Best regards.

The snippets you share look okay to me. I don’t think I can help much without getting a minimum reproducible example or doing a call to go over your code. You can reach me at msoyturk@gams.com or support@gams.com.