Python interpreter error, x takes no arguments (1 given)
Solution 1:
Python implicitly passes the object to method calls, but you need to explicitly declare the parameter for it. This is customarily named self
:
def updateVelocity(self):
Solution 2:
Make sure, that all of your class methods (updateVelocity
, updatePosition
, ...) take at least one positional argument, which is canonically named self
and refers to the current instance of the class.
When you call particle.updateVelocity()
, the called method implicitly gets an argument: the instance, here particle
as first parameter.
Solution 3:
Your updateVelocity()
method is missing the explicit self
parameter in its definition.
Should be something like this:
def updateVelocity(self):
for x in range(0,len(self.velocity)):
self.velocity[x] = 2*random.random()*(self.pbestx[x]-self.current[x]) + 2 \
* random.random()*(self.gbest[x]-self.current[x])
Your other methods (except for __init__
) have the same problem.