Affine Transformation for objective function

Answered

Comments

1 comment

  • Eli Towle

    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
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk