Skip to content

example - network.py #96

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anilrajibm
Copy link

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.

Copy link

@PhilippeCouronne PhilippeCouronne left a comment

Choose a reason for hiding this comment

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

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).

@PhilippeCouronne PhilippeCouronne self-assigned this Apr 17, 2025
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