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

Fix time indices for representative temporal blocks #1015

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

nnhjy
Copy link
Collaborator

@nnhjy nnhjy commented May 18, 2024

A perhaps provisional fix for the cases where we need representative temporal blocks and constraints concerning unit state transitions.

Fixes # (issue)

Checklist before merging

  • Documentation is up-to-date
  • Unit tests have been added/updated accordingly
  • Code has been formatted according to SpineOpt's style
  • Unit tests pass

@nnhjy nnhjy requested a review from manuelma May 18, 2024 14:04
# the model can't find a mapping to representative blocks for the outside time indices.
if !(explicit_representative_temporal_block(temporal_block=blk)) || tb in time_slice(
m; temporal_block=members(blk)
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will damage performance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same concern. I've created issue #1018 to explain the problem. This change attempts for option 1. The latest commit ca43ceb attempts for option 2 and should be more efficient, but it couldn't pass all tests.

merge!(vars, Dict(ind => coeff * vars[ref_ind] for (ind, (ref_ind, coeff)) in ind_map))
# A ref_ind may not be covered by keys(vars) unless
# the ind_map is carefully designed in specific variable adding functions.
merge!(vars, Dict(ind => coeff * vars[ref_ind] for (ind, (ref_ind, coeff)) in ind_map if haskey(vars, ref_ind)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This haskey introduce an extra lookup for every iteration of the comprehension and might also damage performance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! The haskey check now goes outside the iteration (commit 2cefffa).

@manuelma
Copy link
Collaborator

@nnhjy thanks a lot for this, seems to be coming along nicely. Perhaps you can describe in more detail the issue this is trying to solve? Also if you need help or if you want someone to review it before you merge it please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants