メインコンテンツへスキップ

absolute value constraint on vectorised variable setting

回答済み

コメント

4件のコメント

  • 正式なコメント
    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

    Unfortunately, MVar objects cannot currently be used with general constraints. The development team is aware of the limitation. For now, you can use MVar.tolist() (new in Gurobi 9.1) to obtain the list of Var objects associated with the matrix variable(s). These Var objects can be used with Model.addGenConstrAbs()/abs_().

    0
  • afsaneh mastouri
    • Gurobi-versary
    • First Question
    • First Comment

    Thank you Eli for your prompt response. 

    How would you suggest that i implement the abs constraint at matrix setting? 

    Does it mean that I should use AddVar instead of AddMVar?

    Thank you, 

    0
  • Eli Towle
    • Gurobi Staff

    You can use the MVar.tolist() method I mentioned to obtain the list of Var objects associated with the matrix variables. These Var objects can be used in general constraint functions. E.g.:

    import gurobipy as gp

    m = gp.Model()
    x = m.addMVar(3)
    y = m.addMVar(3)

    # MVar objects are not currently integrated with general constraints
    # m.addConstr(y == gp.abs_(x)) does not work

    # Use corresponding Var objects instead
    for vx, vy in zip(x.tolist(), y.tolist()):
    m.addConstr(vy == gp.abs_(vx))

    Alternatively, you could just use Var objects throughout by defining your variables with Model.addVar() or Model.addVars(). However, this would require you to rewrite any code that uses matrix semantics.

    0

投稿コメントは受け付けていません。