-
Notifications
You must be signed in to change notification settings - Fork 7
Flow communication between primary and secondary networks #2556
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
Conversation
|
I stumbled upon a problem when working on this. We determine the demand(s) of a secondary network to the primary network by optimizing within the secondary network, minimizing how much flow is taken from the main network and interpreting the flow into the secondary network from the primary network as the demand of the secondary network. The problem is that with the current formulation it is not possible to split up that demand into the different priorities, the optimization only yields the total flow into the secondary network from the primary network. We can't use a global (multi commodity) water balance type computation for this either, because we allow multiple inlets from the primary network into secondary networks. We can add decision variables per demand priority at each secondary network inlet, but then we need to have a way to constrain those. I cannot quickly come up with a way to do that without adding a new objective per demand priority. |
|
I'm having trouble coming up with something that works within the lexicographic multi-objective optimization. Say we add a flow variable per demand priority for each primary network to secondary network inlet. A naive solution would be to, after optimizing for a certain demand priority when collecting demands in a secondary network, minimize the sum of the inflows variables from the primary network corresponding to this demand priority. Then however the solver can 'abuse' the inlet variables for later priorities to allocate for this priority. I don't see how this can be avoided other than by manually adjusting constraints/bounds in between optimizations. @jarsarasty do you have a clever trick up your sleeve for this? |
|
Looking at the challenge of splitting secondary network demands by priority and making this solution information available to the primary network, I see three possible approaches: Alternative 1: Post-ProcessingCore Idea:Extract priority-based demands from secondary network solutions after optimization but before primary network optimization. Implementation Outline:
Advantages:No additional optimization variables, minimal code changes, maintains solver performance Limitations or disasvantages:The demand priorities may not be acuratelly reconstructed in cases of multiple inlets per secondary network. However, multiple-inlet splitting not be immediately relevant as we are currently not considering this case, as far as I remember. Alternative 2: Priority-indexed flow variablesCore Idea:Add priority-indexed flow variables for primary→secondary connections, letting MOA.jl naturally discover optimal priority distribution. Implementation Outline:
Key Insight: Most of the priority structure already exists in Ribasim - we're just Advantages:Mathematically optimal, handles complex topologies naturally, and works with multiple inlets Limitations or disasvantages:The number of variables would increase in around 20% to 60% in some cases, and this could impact the performance. However, this impact would not be very drastic as the current models are linear. Alternative 3: Dual DecompositionCore Idea:Use Lagrangian relaxation to coordinate between primary and secondary networks through price signals. Implementation Outline:
Advantages:Theoretically elegant, proven convergence under convexity assumption (current situation), handles complex coupling naturally Disadvantages:Most complex to implement, requires dual update tuning, may need many iterations RecommendationGiven that current test models use single inlet per secondary network, I'd suggest starting with Alternative 1 (Post-Processing) for immediate implementation, since:
Alternative 2 would be the best long-term solution for mathematical rigor and extensibility. However, we should evaluate its impact on performance Alternative 3 is more of academic interest at this moment, unless we encounter some limitations with the other approaches. Shall we plan a meeting to discuss these approaches? |
|
Hi @jarsarasty, thank you very much for your elaborate response. Here's my response per alternative: Alternative 1: Post-ProcessingWe do want to support multiple inlets from the primary network to the secondary network (I'm pretty sure this is a requirement for the Dutch schematization). Another disadvantage of this approach is that it does not take the topology and constraints between the demands and secondary network inlets into account. Alternative 2:Here I don't fully understand 4. It looks like generally you want to equate the total allocated flow for a certain priority in a secondary network to the inflow over all inlets from the primary network indexed for that priority. There are some issues with this:
Alternative 3:I don't understand this well enough at the moment to comment |
|
Hi @SouthEndMusic , Regarding your questions about the multi-commotidy formulation (priority-indexed flow variables approach ):
I had not considered that case, but the formulation can easily be extended to include sources within the same network.
Right. Some more elaboration is necessary to make it work with LevelDemands, but the basic concept remains the same. I think the main challenge is the added size of the problem. |
|
The above problem was discussed with @jarsarasty, @simulutions and @gijsber. We came to the conclusion that we can do an approximation of the distribution of the flow from the primary network to the secondary network over the priorities, by:
|
|
Just to add: |
|
More detailed steps on how to proceed @simulutions:
I think that should be it for the demand communication. I also added #2230 and #2383 to the PR description because I think this PR is the last piece needed for those. |
|
Plans have changed again. It was decided that callbacks are not within the scope of
@simulutions I'm probably missing some details here, feel free to reach out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
|
🎉 |
Continues on #2556 and fixes #2632. The allocation between subnetworks and the primary network had was developed in #2556 and tested on a minimal model with a single secondary network and 1 route for the flow. In this PR, a more complex test network was created and showed several bugs which were fixed. In the model below allocation was calculated once as a single network and also as a primary network connected to two secondary networks. The inflow from the flow boundary of 0.9 m3/s was exactly matched by the 3 user demands of 0.3 m3/s. The results of allocation were compared with the single network version and matched very well (atol = 1e-8). <img width="1022" height="679" alt="Screenshot 2025-10-24 at 13 44 25" src="https://github.com/user-attachments/assets/32e50840-8e84-4744-be9e-07545a0b62a2" />
Fixes #2327
Fixes #2230
Fixes #2383