Declaring equations over subset - Equation definition condition

Hi everyone,

I have an issue with creating a model in GAMSPy.

## Holdings balance equation
holdings_balance = Equation(
    m,
    name="holdings_balance",
    domain=[stocks, time],
    description="Observes holdings of each stock at each time"
)
holdings_balance[stocks, subtime] = (
    x[stocks, subtime] == x[stocks, subtime-1] + b[stocks, subtime] - s[stocks, subtime]
)

The above is a GAMSPy equation declaration over the superset time, with the equations being defined specifically for the subset subtime. The subset is the same as the superset, except it does not contain the first item in the set, as that is labelled ‘0’ and I want a specific equation for the first time index. Within the equation, there is a reference to x[stocks, subtime-1]. When subtime is equal to ‘1’ - then that particular variable disappears when viewing the generated equations. This is because apparently, x[stocks, 0] does not exist as the ‘0’ index is not explicitly present in the subset subtime, even though it is in the superset time.

Due to this error, my equations are not being registered properly. I’ve tried several things to resolve this issue, but I was unable to in the end. In the original GAMS Studio, you could create equations with conditionals applied to the domain using the dollar sign. Such a provision does not seem available for the Python version of GAMS. Normally, I would have gotten rid of the subset altogether and applied a conditional declaration of equations for all t values above 0.

How would I achieve this in GAMSPy?

Dollar conditions are available with .where[...] syntax in Python. See https://gamspy.readthedocs.io/en/latest/user/basics/assignments.html for more details. The comparison is as follows:

GAMS syntax

symbol(domain) $ (condition) = <definition>

GAMSPy syntax:

symbol[domain].where[condition] = <definition>

I hope this helps.