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

Binary variable ignored at multiplication

回答済み

コメント

4件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Riley Clement
    • Gurobi Staff

    Hi Zheren,

    It's not quite clear to me what you mean by the value of "a".

    Consider the following minimum reproducible example

    import guropbipy

    m = gp.Model()

    n=1
    M=5

    x = m.addVar(vtype=gp.GRB.BINARY)

    a = n*M*(1-x)


    In this case the variable "a" is assigned a linear expression

    >> type(a)
    gurobipy.LinExpr

    and

    >> a.getValue()
    AttributeError: Index out of range for attribute 'X'

    fails because we have not optimized and found a solution.

    So when you say that "a", or any variable or expression in the model, has a value (prior to model update, and more importantly model optimization) it is not clear what you are referring to.

    Are you able to elaborate more, and use the code above to explain what you mean?

    Thanks

    - Riley

    0
  • Zheren Zhang
    • Gurobi-versary
    • Curious
    • Conversationalist

    Hi Riley

    Thank you for the reply and sorry for my unclear discription. In this case the variable "a" is an gurobipy linear expression which is a sum that every summand of it is expected to contain a gurobi variable.

    I´ve inspected my code once more and I realize that the gurobi variable x of this linear expression is not ignored, just the constant term (n*M) is pushed to the beginning of the expression and the term -n*m*x is at the last position. There must be other wrong implementations that make my code not work as expected.

    Sorry for taking your time because of my carelessness.

    Best regards 

    Zheren

    0
  • Riley Clement
    • Gurobi Staff

    Hi Zheren,

    No need to apologize, it's all part of learning, and happens to the best of us :)

    - Riley

    0

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