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

problem with adding constraint to the model

回答済み

コメント

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?.
  • Jaromił Najman
    • Gurobi Staff

    Hi Ahmad,

    Variables \(\texttt{Z_var}\) and \(\texttt{y}\) are part of the \(\texttt{model}\) object and not of the \(\texttt{MP_model}\). In order to access them in the most convenient way, you could add

    MP_model = gp.read ( "MP.lp" )
    y = MP_model.getVars() # get all vars as list

    Z_var = 0
    for v in y:
    # this only works because all variable are named y# except for one Z
    if v.VarName == 'Z':
    Z_var = v # save variable Z to Z_var
    y.remove(v) # remove variable Z from the list of y variables
    break

    To be 100% certain, you could also check whether the \(\texttt{y}\) list is in the correct order.

    Best regards,
    Jaromił

    1
  • ahmad alanaqreh
    • Gurobi-versary
    • Conversationalist
    • Investigator

    Dear Jaromil 

    Thank you so much for your help, it's working perfectly :)

    I have another question if you don't mind, I have a model and I am solving the model if it is infeasible, I want to get the unbounded value of each constraint, I do the following :

    SP_model.getConstrByName ( 'one' ).FarkasDual

    and if there is a solution I want the dual value of the constraint :

    SP_model.getConstrByName ( 'one' ).Pi

    I don't know if this is the right way because for Pi it is working normally but with Farkas dual, I got this error message :

    alpha[k] = SP_model.getConstrByName ( 'one' ).FarkasDual
    File "src\gurobipy\constr.pxi", line 67, in gurobipy.Constr.__getattr__
    File "src\gurobipy\constr.pxi", line 95, in gurobipy.Constr.getAttr
    File "src\gurobipy\attrutil.pxi", line 100, in gurobipy.__getattr
    AttributeError: Unable to retrieve attribute 'FarkasDual'

    Thanks a lot 

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi Ahmed,

    FarkasDual values are only available if you set the parameter InfUnbdInfo to 1. This is done to avoid the rather expensive computations connected to FarkasDual values. In you particular case, you will have to set

    SP_model.setParam("InfUnbdInfo",1)
    SP_model.optimize()

    Best regards,
    Jaromił

    1

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