Skip to main content

Solution to Optimisation problem

Answered

Comments

4 comments

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Vinzenz,

    I can't seem to reproduce your issue.  Solving the LP file you posted, with Gurobi v11, the running:

    for v in m.getVars():
        print(v.varname, v.X, v.lb)

    I get the following output:

    norm[intersection_1_1] 1.4142135623730931 0.0
    norm[intersection_1_2] 0.0 0.0
    norm[intersection_2_1] 1.4142135603441 0.0

    Can you provide some more details on how you are running this (including Gurobi version)?

    - Riley

    0
  • Vinzenz Tütsch
    Gurobi-versary
    First Comment
    First Question

    Hi Riley, 

    Thanks for your answer. I'm using Gurobi 11.0.0.

    I'll share some code, so you can see what I do exactly. It is not exactly the same problem, but a condensed version that gives me the same error:

    import gurobipy as gp
    from gurobipy import GRB
    import numpy as np

    env = gp.Env(empty=True)
    env.setParam("OutputFlag", 0)
    env.start()

    # Create a new model
    model = gp.Model("norm_objective_example", env=env)

    x1 = np.array([0, 1, 0, 0, 0, 0, 0, 0])
    x2 = np.array([0, 0, 1, 0, 0, 0, 0, 0])
    n = len(x1)

    # Define the variables
    z = model.addVars(n, vtype=GRB.BINARY, name="z")
    diff = model.addVars(2, n, vtype = GRB.CONTINUOUS, lb=-2, ub=2, name="diff")
    norm = model.addVars(2, vtype = GRB.CONTINUOUS, name="norm")

    # Add constraints
    model.addConstr(z.sum() == 1)
    for i in range(n):
        model.addConstr(diff[0, i] == x1[i] - z[i])
        model.addConstr(diff[1, i] == x2[i] - z[i])

    # Add the norm constraint
    model.addGenConstrNorm(norm[0], diff.select(0, "*"), 2.0, "normconstr0")
    model.addGenConstrNorm(norm[1], diff.select(1, "*"), 2.0, "normconstr1")

    # Set the objective
    model.setObjective(norm[0] + norm[1], GRB.MINIMIZE)

    # Optimize the model
    model.optimize()

    print("Z:", [z_val.X for z_val in z.select()])
    print("Diff 1:", [dif.X for dif in diff.select(0, "*")])
    print("Diff 2:", [dif.X for dif in diff.select(1, "*")])
    print("Norm 0:", norm[0].X)
    print("Norm 1:", norm[1].X)
    Z: [-0.0, 0.0, 1.0, -0.0, -0.0, -0.0, -0.0, -0.0]
    Diff 1: [0.0, 1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    Diff 2: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    Norm 0: 1.0
    Norm 1: 0.0
    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Vinzenz,

    Thanks for the simplified model, I can confirm I can replicate your results with v11.

    I note that when output is turned on the log indicates there are issues with the solution:

    Warning: max constraint violation (4.1421e-01) exceeds tolerance
    Warning: max general constraint violation (4.1421e-01) exceeds tolerance
             (model may be infeasible or unbounded - try turning presolve off)

    Setting Presolve=0 as suggested gives the expected answer.  Additionally the mention of "infeasible or unbounded" immediately brings to mind dual reductions and setting DualReductions=0 also resolves the issue.

    But this outcome is still not ideal, and there does not seem to be an issue with v10 so I will open a support request for this, as it will make it easier for us to look into this internally.  You will receive a notification shortly.

    - Riley

    0
  • Vinzenz Tütsch
    Gurobi-versary
    First Comment
    First Question

    Hi Riley, 

    Thanks for opening a request and your help. 

    0

Please sign in to leave a comment.