type error: unhashable type: 'simpleparam'

77 views
Skip to first unread message

Augusto Ferraro Raigada

unread,
May 13, 2016, 10:54:21 AM5/13/16
to Pyomo Forum
I need help with this type of error, I couldnt generate a constraint. Thanks in advance. The code is this:

def makespan_rule(model,j):
return model.C[model.n,j,model.m] + model.r[j, model.m] <= model.Cmax
model.cmax_constraint = Constraint(model.J,rule=makespan_rule)

William Hart

unread,
May 13, 2016, 1:46:01 PM5/13/16
to pyomo...@googlegroups.com

I think you need to provide more context for the error.  What are model.n and model.m?

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Augusto Ferraro Raigada

unread,
May 13, 2016, 10:39:49 PM5/13/16
to pyomo...@googlegroups.com
Thank you for your response, model.m and model.n are both non negative integer parameters.

Here is the entire code:

from __future__ import division
from pyomo.environ import *

model = AbstractModel()

#---------------------------------------------------
#
# DEFINICIoN DE SETS Y PARAMETROS
#
#---------------------------------------------------

# m es el numero de maquinas del flow-shop, y N el numero de productos disponible
model.m = Param(within=NonNegativeIntegers)
model.N = Param(within=NonNegativeIntegers)

# J es el conjunto de los indices de las maquinas, K es el conjunto de los indices de los productos
model.J = RangeSet(1.0, model.N)
model.K = RangeSet(1.0, model.m)

# n es el vector que tiene por componentes, el numero de sublotes de cada lote
model.n = Param(within=NonNegativeIntegers)

# I es el conjunto de los indices de los sublotes
model.I = RangeSet(1.0, model.n)

# p es la matriz de los tiempos de produccion: en las filas estan los lotes y en las columnas estan las maquinas.
model.p = Param(model.J, model.K)

# U es el vector que tiene por componentes, el numero de items de cada lote
model.U = Param(model.J)

# t es la matriz de los tiempos de preparacion: en las filas estan los lotes y en las columnas estan las maquinas.
model.t = Param(model.J, model.K)

# r es la matriz de los tiempos de remocion: en las filas estan los lotes y en las columnas estan las maquinas.
model.r = Param(model.J, model.K)

# FT y VT es el tiempo fijo y unitario de transferencia, correspondientemente, de un lote
model.FT = Param(model.J)
model.VT = Param(model.J)

model.G = Param()

#S es la cantidad de cada sublote, C es el tiempo de finalizacion, y es la variable binaria de precedencia, Cmax es el makespan
model.s = Var(model.I,model.J,domain=NonNegativeIntegers)
model.C = Var(model.I,model.J,model.K,domain=NonNegativeIntegers)
model.y = Var(model.J,model.J,domain=Binary)
model.Cmax = Var(domain=NonNegativeIntegers)

#---------------------------------------------------
#
# DEFINICION DE OBJETIVO
#
#---------------------------------------------------

def obj_expression(model):
return model.Cmax
model.OBJ = Objective(rule=obj_expression)

#---------------------------------------------------
#
# DEFINICION DE RESTRICCIONES
#
#---------------------------------------------------

def item_allocation_rule(model,j):
return sum(model.s[w,j] for w in model.I) == model.U[j]
model.allocation = Constraint(model.J,rule=item_allocation_rule)

def makespan_rule(model,j):
return model.C[model.n,j,model.m] + model.r[j, model.m] <= model.Cmax
model.cmax_constraint = Constraint(model.J,rule=makespan_rule)

def seq_pr_constraint_rule(model,i,j,k):
if (k < model.m):
if (i == 1.0):
return model.c[i,j,(k+1.0)] - model.p[j,(k+1.0)]*model.s[i,j] >= model.c[i,j,k] + model.t[j,(k+1.0)] + model.FT[j] + model.VT[j]*model.s[i,j]
else:
return model.c[i,j,(k+1.0)] - model.p[j,(k+1.0)]*model.s[i,j] >= model.c[i,j,k] + model.FT[j] + model.VT[j]*model.s[i,j]
model.seq_ol_rule = Constraint(model.I,model.J,model.K,rule=seq_pr_constraint_rule)

def station_capacity_rule(model,i,j,k):
if (k == 1):
if (i == 1):
return model.c[i,j,k] - model.p[j,k]*model.s[i,j] >= model.t[j,k]
else:
return model.c[i,j,k] - model.p[j,k]*model.s[i,j] == model.c[(i-1.0),j,k]
else:
return model.c[i,j,k] - model.p[j,k]*model.s[i,j] >= model.c[(i-1.0),j,k]
model.capacity = Constraint(model.I,model.J,model.K,rule=station_capacity_rule)

def nointerm_rule1(model,i,j,m,n,k):
if (j<>n):
return model.c[m,n,k] - model.p[n,k]*model.s[m,n] - (model.c[i,j,k] - model.p[j,k]*model.s[i,j]) + model.G*(1.0-model.y[j,n]) >= (model.U[j] - sum(model.s[u,j] for u in model.I if u <= (i-1.0)))*model.p[j,k] + model.r[j,k] + model.t[n,k] + model.p[m,k]*sum(model.s[u,n] for u in model.I if u <= (m-1.0))
model.intermingling1 = Constraint(model.I,model.J,model.I,model.J,model.K,rule=nointerm_rule1)
def nointerm_rule2(model,i,j,m,n,k):
if (j<>n):
return model.c[m,n,k] - model.p[n,k]*model.s[m,n] - (model.c[i,j,k] - model.p[j,k]*model.s[i,j]) + model.G*model.y[j,n] >= (model.U[j] - sum(model.s[u,j] for u in model.I and u <= (i-1.0)))*model.p[j,k] + model.r[j,k] + model.t[n,k] + model.p[m,k]*sum(model.s[u,n] for u in model.I and u <= (m-1.0))
model.intermingling2 = Constraint(model.I,model.J,model.I,model.J,model.K,rule=nointerm_rule2)

Gabriel Hackebeil

unread,
May 13, 2016, 11:18:01 PM5/13/16
to pyomo...@googlegroups.com
We can not be much help when you provide an AbstractModel without any data to instantiate it with.

Can you give us any information about the error you encounter? For instance, the user in this post provides a full stack trace for the TypeError they encountered. This usually gives us all of the context we need to help you figure out the problem.

Gabe

On May 13, 2016, at 7:39 PM, Augusto Ferraro Raigada <augusto.fer...@hotmail.com> wrote:

Thank you for your response model.m and model.n are both non integer parameters.

Augusto Ferraro Raigada

unread,
May 13, 2016, 11:26:04 PM5/13/16
to Pyomo Forum
Sure. The error is this:

ERROR: Rule failed when generating expression for constraint cmax_constraint with index 1.0:
                      TypeError: unhashable type: 'SimpleParam'
ERROR: Constructing component 'cmax_constraint' from data=None failed:
                      TypeError: unhashable type: 'SimpleParam'

Regards

Gabriel Hackebeil

unread,
May 14, 2016, 12:04:42 AM5/14/16
to pyomo...@googlegroups.com
Can you add “-c” to the end of the pyomo command? It will output more information about the error traceback.

Gabe

Augusto Ferraro Raigada

unread,
May 14, 2016, 12:09:00 AM5/14/16
to Pyomo Forum

here it is.

Gabriel Hackebeil

unread,
May 14, 2016, 12:17:14 AM5/14/16
to pyomo...@googlegroups.com
Thanks. It looks like you are using a Param as an index to another Pyomo component. I thought we supported this, so maybe the developer in charge of Param will need to look into this.

However, you can avoid this error (and other related errors) by always making sure to wrap the param object in value(…) anywhere you use it outside of a constraint or objective expression. E.g., 

model.p = Param()

def some_rule(…):
    if value(model.p) == …:
        return model.x[value(model.p)] * ...

Gabe

Augusto Ferraro Raigada

unread,
May 14, 2016, 12:30:39 AM5/14/16
to Pyomo Forum
Thank you so much. That was my mistake. Regards
Reply all
Reply to author
Forward
0 new messages