Skip to main content

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

Answered

Comments

1 comment

  • Eli Towle
    Gurobi Staff 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

Please sign in to leave a comment.