0

I'm having this problem when I clearly use init function to declare the parameters. Link my code there:

class Node:
def _init_(self,pieza,turno,listaAsignados,parent,costeCamino,coste):#Initialize a Node 
    self.pieza = pieza
    self.turno = turno
    self.listaAsignados = listaAsignados
    self.parent = parent
    self.costeCamino = costeCamino
    self.costeNodo = costeNodo

def calculateCost(C, i, j, listaPadre,M):  #Calculate Cost of the next element
    initCost = 0
    cost = 0
    listaDisponibles = [1]*M
    for i in range(i,M-1):
        minNum = 9999999999
        minIndex = -1
        for j in range(j,M-1):
            if(not listaPadre[j] and listaDisponibles[j] and C[i][j]< minNum ):
                minIndex = j
                minNumber = costMatrix[i][j]
    cost = cost+ minNumber
    return cost 



import heapq
def branch_bound(C):
"""
   -C  = Matrix of costs
"""

items=[]
priorityQueue = []
heapq.heapify(priorityQueue)
listaAsignados = [0]*M#Asigned list for the matrix
raiz = Node(-1,-1,listaAsignados,None,0,0)
heapq.heappush(listaAsignados,[raiz.cost,raiz])

while (priorityQueue):
    examinateNode = heapq.heappop(priorityQueue)
    examinateNode = examinateNode[1]
    i = examinateNode.pieza+1
    if (i == M):
        return examinateNode.cost
    for j in range(0,M-1):
        if(examinateNode.listaAsignados[j] == 0):
            costeCamino = examinateNode.pathCost+ C[i][j]
            costeHijo = costeCamino+ calculateCost(C, i, j, examinateNode.listaAsignados,M)
            nodoHijo = Node(i,j,examinateNode.listaAsignados,examinateNode,costeCamino,costeHijo)

            heapq.heappush(listaAsignados,[nodoHijo.cost,nodoHijo])

return items   

If someone can explain me why this error is going on I will appreciate it. I don't know why if I have a constructor the error is going on:

<ipython-input-10-8d5dfd71f776> in branch_bound(C)
 11     heapq.heapify(priorityQueue)
 12     listaAsignados = [0]*M
 13     raiz = Node(-1,-1,listaAsignados,None,0,0)<-------
 14     heapq.heappush(listaAsignados,[raiz.cost,raiz])
 15 

TypeError: object() takes no parameters

1
  • 1
    Your pasted code has only single underscores by "init". Python methods are by convention double underscores (affectionately called "dunder" methods). Can you confirm if this was a paste error (and if not try to use double underscores). Commented Dec 22, 2018 at 20:43

1 Answer 1

1

You need to write __init__ instead of _init_.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.