Skip to main content

Model optimized to 0 & all constraints removed by presolve

Answered

Comments

5 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jaromił Najman
    • Gurobi Staff

    Executing your code results in

    Traceback (most recent call last):
      File "test.py", line 103, in <module>
        model.addConstr(gp.quicksum(C[i, r, 'u', t] + C[i, r, 'v1', t]) <= population[i][r], name=f"c3_r{r}_t{t}_i{i}")
      File "src/gurobipy/gurobi.pxi", line 3706, in gurobipy.quicksum
    TypeError: 'gurobipy.LinExpr' object is not iterable

    which points to the constraint

    # Constraint 3 - unvaccinated and vaccinated people in region r not more than population in region r at every time t
    for r in range(num_regions):
        for t in range(num_time_periods):
            for i in range(num_age_groups):
                model.addConstr(gp.quicksum(C[i, r, 'u', t] + C[i, r, 'v1', t]) <= population[i][r], name=f"c3_r{r}_t{t}_i{i}")

    There is a \(\texttt{for}\) statement missing inside of the \(\texttt{gp.quicksum}\) call.

    0
  • Rosa Muijderman
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Jaromil,

    Thanks for looking at my code! You’re right, I forgot to remove the quicksum. Unfortunately I still run into the same problem after I fix this error. The constraints are not considered, which makes the code return 0 as the optimal value. Do you have any idea how I could fix this? Or some tips as to how I can figure it out?

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi Rosa,

    I think the best way to find out what is wrong is to write the model to an LP file and inspect it.

    # Usage
    model.write("myLP.lp")
    model.optimize()

    You can open the \(\texttt{myLP.lp}\) file in any standard text editor and analyze your model. From what I can see is that the current version of your model is a small purely continuous model with a couple of equality constraints which all can be used for substitution. Setting all variables to \(0\) is a feasible point and it's simultaneously the optimal solution because all objective coefficients are non-negative. There is no constraint which would force any of the variable to be \(>0\).

    Best regards, 
    Jaromił

    0
  • Rosa Muijderman
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Jaromil,

    Thanks for the tip! I figured out what the problem was. The initial value for C_i_r_u_0 was not set correctly, which ended in an optimal value of 0. I now added a constraint to ensure the correct initial value.

    Kind regards,
    Rosa

    0

Post is closed for comments.