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

model update

回答済み

コメント

4件のコメント

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Krishna,

    I think the following would be more efficient

    FEASIBILITY_TOLERANCE = 1e-08
    cons = [c for c in model.getConstrs() if 0 < c.RHS < FEASIBILITY_TOLERANCE]
    model.setAttr("RHS", cons, 0)

    I could not replicate your issue using your code on another model.  The update() method should result in changes to the printStats() output.  Can you double check your code, and insert another update() just after the line where you import numpy, as one possible explanation is that getConstrs() isn't returning anything - which can happen if the model has been built but not updated.

    - Riley

    0
  • Krishna Jarugumilli
    First Comment
    First Question

    Hi Riley,

    Thank you for your feedback. I executed the same block of code twice. I find that the model does indeed update however doesn't print the updated matrix. I print the length of cons which is 15 in first execution and zero in 2nd execution. (Cells 18 and 19 in screenshots below)

    I also wrote the model to lp file and read it back and still see the RHS coefficients not updated, again no constraints can be found below feasibility tolerance. (Cells 20-23 in screenshot below)

    I am not sure if this is related to size of the matrix. I tried this on a small problem with 10 constraints and see the printStats does update the model.

    Kindly advise if you have anything else I can try. 

     

    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Krishna,

    I'm guessing there may be small negative RHS values.  Can you try with

    cons = [c for c in m.getConstrs() if -FEASIBILITY_TOLERANCE < c.RHS < FEASIBILITY_TOLERANCE]

    - Riley

    0
  • Krishna Jarugumilli
    First Comment
    First Question

    Hi Riley,

    Thank you, this worked and RHS coefficient range did improve substantially. Appreciate your time and feedback!

    Regards,

    Krishna

    0

サインインしてコメントを残してください。