Rework activity limits code #971
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I'm on leave this afternoon and it's unlikely that I'll be back until after paternity leave at this point, so I thought I'd open a PR for this, even though it's broken 😢. The example models now all fail to run because there is unmet demand and I'm not sure why: the constraints should now be less restrictive!
I'm just going to leave this here in draft. Feel free to fix it up and merge or you can wait until I'll I'm back. I think that #957 is a pretty important bug to fix and this is a fairly big refactor, so if we leave it there will be merge conflicts. On the other hand, fixing merge conflicts might be the right level of task for my sleep-deprived brain when I get back 😆, so I don't mind if you'd rather not clean up my mess.
I figured that it wouldn't be too painful to refactor things to fix up #957, but I was wrong. We rely on activity limits being specified as time slices all over the place (e.g. in
investment.rsandgraph.rsfor validation). It actually ended up being easier to do #958 and #743 at the same time while I was reworking things.As part of this, I changed the
ProcessActivityLimitsMapso that the limits aren't pre-multiplied by duration. (I made this change beforehand and things still worked at this point.) I created a newPerYeartype to represent this, which means thatAsset::get_activity_limits()returns anActivityPerYearvalue (for example). To use it, you obviously need to multiply by a duration later on.I think it's nearly there. The problem might be to do with the way I'm doing the activity constraints now. For one thing, there now should be an additional requirement that the activity for each individual time slice shouldn't exceed the maximum allowable for that time slice (otherwise the whole year's activity could happen in one time slice). I don't think adding that will fix things by itself though.
Fixes #957. Closes #958. Closes #743.
Type of change
Key checklist
$ cargo test$ cargo docFurther checks