Skip to main content

TypeError: unsupported operand type(s) for *: 'float' and 'tupledict'

Answered

Comments

1 comment

  • Riley Clement
    • Gurobi Staff

    Hi Tao,

    The error message is not being produced by the code you have pasted.  The culprit should be a line containing the * symbol, as per the error message.

    The following code, for example, runs without problem:

    m = gp.Model()
    ramda = m.addMVar((2, 6, 6, 6), name='ramda')
    v = [1]*6
    for j in range(1,5):
        m.addConstr(ramda[:, j, 0:j, :].sum() + ramda[:, j, j + 1:, :].sum() - v[j] <= 0)

    Note you will need to handle j = 0 and j = 5 separately since

    ramda[:, j, 0:0, :].sum()

    and

    ramda[:, 5, 6:, :].sum()

    will raise an error (the MVar slice contains no variables).

    - Riley

    0

Please sign in to leave a comment.