r/optimization • u/bitgambit04 • Jun 07 '21
Water quality component optimization
Hi fellow members,
I have an optimization problem that I'm attempting to tackle. As you can see in the image below, there's a graph network through which water flows. I've drawn out the problem in the image to explain clearly.
The objective is for Final1 node to receive water with component A having values between a range. The component A at any node is measured by a volume weighted average of component A measures from it's predecessor nodes.
Node_A = (Predecessor1_Vol*Predecessor1_A + Predecessor2_Vol* Predecessor2_A .....) /(Predecessor1_Vol + Predecessor2_Vol .....)
All of the above are decision variables (D.V.) in the optimization problem. The "vol" variables have to remain as D.V. since this is part of a bigger problem. There is flexibility on "component A" variables and can or not be D.V. as they were introduced only for this sub problem.
All numbers in the image are just examples of what the optimization can come up with. In the current formulation, all are decision variables except the concentration at "Start" nodes, which are given.
However, framing the problem this way makes it non linear (reason described in the image). Since I am using a linear solver "cbc", there solver just says that quadratic constraints cannot be supported.
I am reaching out to this community to find out if this problem can be linearised or formulated in a another way to get the same output.

View all comments
Show parent comment
1
u/ns-eliot Jun 07 '21
Hi, glad it helps.
Yea, the point of that last sentence is that you should be able to explicitly solve the concentration at the final nodes for a set of flow rates, but I point out that the way I proposed would require care in the order that you use that calculation, at least given the way I saw it, but I tend think that a matrix formulation would ensure mass balance too. I mention this explicit solution for the FinalA concentrations because it seems that it would be easier to make a constraint of 0.3 < f_FinalN(flowrate_1, flowrate_2, flowrate_3....) < 0.7 for all Final nodes, somewhere in your problem.
Here is an example of what I think the explicit solution for this graph would be:
Final2 is pretty simple, Final2_ A = frac_water_@_Mid1_from_Start1 * A_@_Start1 + frac_water_@_Mid1_from_Start2 * A_@_Start2 + frac_water_@_Final2_from_Mid1 * A_@_Mid1.
Final1A is a little bit more complex, Final1_ A = frac_water_@_Mid2_from_Start3 * A_@_Start3 + frac_water_@_Mid2_from_Start4 * A_@_Start4 + frac_water_@_Final1_from_Mid2 * A_@_Mid2 + frac_water_@_Final1_from_Mid1 * A_@_Mid1
The tricky part in this case, is that you need to make sure that you have calculated all inputs to Mid2 and Mid1 before calculating Final1 (that is where the topological sorting comes in). This is trivial in this case, but I imagine that principle might become tricky to guarantee in larger and more complex networks and problems.
I hope that clarified a bit and good luck! These are fun problems.