example - network.py#96
Conversation
There was a problem hiding this comment.
Thanks for your contribution, I will review it . At first glance it seems to me model building time could be improved.
- add constrainnts in batch instead of one by one
- an if-then-else constraint between two boolean vriables such as if_then_else(b1==1, b2==1) could be simplified as a pure linear constraint (b1 <= b2) . Works the same but creates less artefacts
- Calls to mdl.solve_details return a tuple, it has no effect unless you print it
- Consider printing the solve log. Modify solve as solve(log_output=True)
In addition, the modeling code is incorrect. The line
load_ab[(a,b)] = mdl.max(...)
does not post any constraint to cplex, it only overwrites the (a,b) slot of the load variable array with an expression. Any further reference to load[a,b] will use the MAX expression, NOT the variable (which is unreachable by then).
Hence the max capacity constraint which comes next, constrains the MAX expression, and NOT the "load[a,b]" variable.
One solution is to add a constraint to link the variable to the MAX as in:
mdl.add( load[a,b] == max(...))
There is a better way. Instead of computing the exact max, which creates under the hood binaries, it suffices to state that
load[a,b] is greater than the two sums arguments of MAX.
The fact that load[a,b] is in th eobjective with a positive coefficient ensures CPLEX will automatically assign the minimum possible value to load[a,b]
Actually this might not be true if the Variable Cost was 0. This could be fixed by adding a minimal cost to all loads (say 1e-4).
…ear, printed mdl.solve with log true, Corrected load_ad mistake, Included minimal cost to all loads
|
Thanks for the comments, I did the modifications. Pls check |
Given source-destination pairs with specified flow requirements, information must travel along a single path per pair, with at most I intermediate nodes. This example of communications Network Design problem involves determining the optimal physical network to transmit information between a given set of nodes. The objective is to minimize the total cost, which includes a fixed cost for each active link and a linear cost based on capacity, while ensuring that capacity limits are not exceeded.