简体   繁体   中英

Python “object() takes no parameters” error

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

您需要编写__init__而不是_init_

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM