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

ALLOCATE AVAILABLE uses the wrong priority subscript #377

Closed
ToddFincannonEI opened this issue Oct 17, 2023 · 1 comment · Fixed by #590 or #577
Closed

ALLOCATE AVAILABLE uses the wrong priority subscript #377

ToddFincannonEI opened this issue Oct 17, 2023 · 1 comment · Fixed by #590 or #577
Assignees
Labels

Comments

@ToddFincannonEI
Copy link
Collaborator

ALLOCATE AVAILABLE takes a priority profile argument. There is one extra subscript on the profile variable. For instance, if the LHS variable has one subscript, the profile variable has two. See the doc page for an example.

The variable visitor assumes that the profile variable has two subscripts. This is incorrect if the LHS variable has more than on subscript, in which case the profile variable has more than two subscripts. For instance, adding a subscript to the equations in the current test model:

DimA: A1, A2 ~~|
request[region, DimA] = demand[region] ~~|
pp[region, DimA, ptype] = priority vector[region, ptype] ~~|
pp[region, DimA, ppriority] = priority vector[region, ppriority] ~~|
pp[region, DimA, pwidth] = priority vector[region, pwidth] ~~|
pp[region, DimA, pextra] = priority vector[region, pextra] ~~|

a[region, DimA] = ALLOCATE AVAILABLE(request[region, DimA], pp[region, DimA, ptype], total supply available) ~~|
@chrispcampbell
Copy link
Contributor

chrispcampbell commented Dec 13, 2024

I dug into this more a couple weeks ago since it was one of the issues that Hazhir was running into with the model he posted in discussion #557.

It turns out there are problems with how subscripts are handled in the arguments to ALLOCATE AVAILABLE in both the read equations phase and in the code gen phase.

I've implemented fixes for the issues below and added many new tests to cover different combinations of subscripted and non-subscripted arguments for ALLOCATE AVAILABLE. I've also verified that these fixes resolve the issues that were affecting Hazhir's model.

Read equations

In read-equations.js we had code that handles the second (pp) argument of ALLOCATE AVAILABLE calls.

That code failed to get the correct index. It would always access subscripts[1] but it needs to get the last RHS subscript instead.

Additionally, it would use text substitution to determine the correct priority and width refIds, which would result in incorrect references in the variable. For example, in one test case it would generate a reference like '_priority[_boston,undefined]'. This needs to be fixed to use expandedRefIdsForVar to get all relevant refIds.

Code gen

In gen-expr.js, the existing code did not compute the correct C variable reference for the req, pp, and avail arguments. This needs to be fixed so that for the req and pp arguments specifically, we only include subscripts up until the last one, because the implementation function will iterate over the provided array (i.e., the generated reference should be a pointer to an array).

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