Skip to main content

Confusion about the network flow example in Python tutorial

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Jaromił Najman
    • Gurobi Staff

    Hi Yui,

    Why the m.setObjective() could be ignored? As network problem is not a feasibility problem (it is minimizing the cost of transportation rather than find feasible decision variables), is the Gurobi minimizing something implicitly?

    In the netflow.py example, the coefficients of the variables in the objective function are set in the call to addVars(). The \(\texttt{obj}\) argument sets the corresponding coefficients in the objective function. The objective function is minimized by default.

    Is try...except... syntax preferred or not? It seems to me the practice of network.py (i.e. using something like if m.status == GRB.OPTIMAL) is better as it causes less hassle about indentation.

    It depends on your application. If you rather have a small script where you expect that no error occurs due to its simplicity, then omitting the \(\texttt{try - except}\) syntax is fine. However, it is often better to be double safe and just use the \(\texttt{try - except}\) syntax. You can always build the \(\texttt{try - except}\) block around one outsourced function in order to avoid the indentation issue.

    Note that

    if (m.status == GRB.OPTIMAL)

    does not save you from possible other errors which may occur during the execution of your code.

    Best regards,
    Jaromił

    0

Post is closed for comments.