Skip to main content

Affine Transformation for objective function

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?.
  • Eli Towle
    • Gurobi Staff

    You can introduce auxiliary variables \( Y \) equal to the difference between \( X \) and the reference matrix \( A \), then minimize \( ||Y||_F^2 \) by slicing the \( Y \) variables appropriately. For example:

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

    n1 = 79
    n2 = 682
    A = np.random.rand(n1, n2)

    m = gp.Model()

    X = m.addMVar(shape=(n1, n2), ub=1.0, name='X')
    Y = m.addMVar(shape=(n1, n2), lb=-GRB.INFINITY, name='Y')

    # set Y = A - X
    m.addConstrs((Y[i, :] == X[i, :] - A[i, :] for i in range(n1)), name='set_Y')

    # "date" constraints
    m.addConstrs((X[i, :].sum() <= 1 for i in range(n1)), name='date')

    # minimize ||Y||_F^2
    m.setObjective(sum(Y[i, :] @ Y[i, :] for i in range(n1)), GRB.MINIMIZE)

    m.optimize()

    Minimizing \( ||Y||_F^2 \) is equivalent to minimizing \( ||Y||_F \).

    0

Post is closed for comments.