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

'<' not supported between instances of 'Var' and 'int'

回答済み

コメント

5件のコメント

  • 正式なコメント
    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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Matthias Miltenberger
    • Gurobi Staff

    Hi Putri,

    Please note that in math programming there are no strict inequalities. You need to model such restrictions by adding a small tolerance, e.g.

    mdl.addConstr(x[i,k] + eps <= d[k])

    You should also not use outer for-loops and then call the \(\texttt{addConstrs}\) method - note the difference between Model.addConstr() and Model.addConstrs(). And you are using the same index \(\texttt{k}\) for both loops - this is not going to work. You should always use dedicated loop indices.

    Cheers,
    Matthias

    0
  • Putri Amalia
    • Gurobi-versary
    • Conversationalist
    • First Question

    Hi Matthias, thanks for your great insight!

    I already put the epsilon:

    mdl.addConstr((x[i,k] + eps <= d[k]) for i,k in arco_qua for k in vehiculos)

    where 

    n  = 11
    nodes = [i for i in range(n)]
    vehiculos = [1,2,3,4]
    arco_qua = [(i,k) for i in nodes for k in vehiculos]
    which result TypeError: unsupported operand type(s) for -: 'generator' and 'NoneType'
    0
  • Matthias Miltenberger
    • Gurobi Staff

    Hi Putri!

    Please review the two links to addConstr and addConstrs that I shared above. You have to use the 's' variant if you want to use Python list comprehensions inside the call. The addConstr method is only going to create a single constraint and cannot be used with an included for loop in the argument.

    And again: please don't re-use the same variable name 'k' in different loops. This is going to create all kinds of issues and you should double check that you really add those constraints that you intend to add. 

    I hope that helps. 

    Cheers,
    Matthias

    0
  • Matthias Miltenberger
    • Gurobi Staff

    You might also want to check out this article about strict inequalities: Why doesn't Gurobi support strict inequality constraints like x < a?

    0

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