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

AttributeError: 'dict' object has no attribute 'prod'

回答済み

コメント

2件のコメント

  • 正式なコメント
    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.
  • Eli Towle
    • Gurobi Staff

    In the original version of the example, the \(\texttt{buy}\) variables are added using Model.addVars() method. This method returns a tupledict object:

    buy = m.addVars(foods, name="buy")

    In the alternative version, \(\texttt{buy}\) is constructed as a standard Python \(\texttt{dict}\). The values of this dictionary are set to the individual Var objects returned by Model.addVar():

    buy = {}
    for f in foods:
        buy[f] = m.addVar(name=f)

    You can convert \(\text{buy}\) to a tupledict using the tupledict() constructor:

    buy = gp.tupledict(buy)

    This should allow you to use the tupledict.prod() and tupledict.sum() methods.

    0

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