Skip to content

Cache link resources and node links while a model is built - #112

Open
hellemo wants to merge 1 commit into
mainfrom
memo-scoped
Open

hellemo wants to merge 1 commit into
mainfrom
memo-scoped

Conversation

@hellemo

@hellemo hellemo commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

This is the other alternative to #110 (and #111). This version is without adding further dependencies.

Pros:

  • keeps the formulation and should benefit extension packages as well
  • no extra dependency

Cons:

  • a bit more code/complexity to maintain in this package

link_res(l) intersects the resources of the two nodes of a link and was
evaluated for every operational period (index sets of link_in/link_out, the
coupling condition, link constraints); link_sub filtered all links for every
node.  While create_model runs, both are now computed once and then taken
from a cache local to the task, which exists only during create_model, so a
later model sees changed nodes.  No change to the API or to any caller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@JulStraus JulStraus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two clarification comments. I think we have to improve on the description. Regarding the caching: I would prefer if the current lines 58-72 are at the end of the file. That makes the understanding easier.

Comment thread src/structures/link.jl
Comment on lines +61 to +62
# period. The cache is local to the task building the model and exists only while
# `create_model` runs, so a later model sees changed nodes and links. The cached

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see the reason for that. Does that imply we change the case file or is the constant _LINK_CACHE not cleared after the model is created? That is also a comment for the test where we see CO2 as a resource.

Thinking about it, I think the wording is confusing: It essentially says that if we have a changed case, we have a changed model, and hence, the new cached items. I think the wording should be improved.

Comment thread test/test_links.jl

# Outside `create_model`, there is no cache: the resources are computed anew
@test isnothing(EMB._link_cache())
@test EMB.link_res(l) !== EMB.link_res(l)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explanation for this behavior is not clear to me. I can see that the vector could be different, but the resources should remain with the same instance? Otherwise we would have problems.

What would be the result of issetequal?

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants