Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand references to vars with three separated dimensions #111

Closed
ToddFincannon opened this issue Sep 15, 2021 · 1 comment · Fixed by #112 or #190
Closed

Expand references to vars with three separated dimensions #111

ToddFincannon opened this issue Sep 15, 2021 · 1 comment · Fixed by #112 or #190
Assignees
Labels
Milestone

Comments

@ToddFincannon
Copy link
Collaborator

When an array variable with separated dimensions occurs on the RHS, we must expand the simple var name reference into a list of subscripted refIds over all the separated indices. This comes up when initializing an array with constant lists or reading a data variable from a file, both of which separate the variable into individual variables. For instance, the variable a in this model:

DimA: A1, A2 ~~|
DimB: B1, B2 ~~|
DimC: C1, C2 ~~|

p[A1, B1, C1] = 111 ~~|
p[A1, B1, C2] = 112 ~~|
p[A1, B2, C1] = 121 ~~|
p[A1, B2, C2] = 122 ~~|
p[A2, B1, C1] = 211 ~~|
p[A2, B1, C2] = 212 ~~|
p[A2, B2, C1] = 221 ~~|
p[A2, B2, C2] = 222 ~~|

r[DimA, DimB] = SUM(a[DimA, DimB, DimC!]) ~~|

is separated on all three dimensions because of the const list. When it occurs in the SUM function, we need to expand all three dimensions into the separated variables, giving refIds such as _p[_a1,_b1,_c1].

The EquationReader.visitSubscriptList method is responsible for expanding the references, but it only handles one or two dimensions. To handle this case, it needs to handle three dimensions.

@ToddFincannon ToddFincannon added this to the 0.6.0 milestone Sep 15, 2021
@ToddFincannon ToddFincannon self-assigned this Sep 15, 2021
@ToddFincannon
Copy link
Collaborator Author

I generalized the EquationReader.visitSubscriptList method to handle any number of separated dimensions by flattening the nested loops into a cartesian product. I added tests to cover this case plus the cases with two separated dimension with and without an additional unseparated dimension. This was done inside the SUM function on the RHS, but should apply to any function that takes subscripted variable arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment