I have the following Bird definition:
class Bird:
def __init__(self, swarm, position = None):
if (swarm == None):
raise ValueError("swarm variable should not be None!")
if (not(type(swarm)).__name__ == 'ParticleSwarmOptimization'):
raise TypeError("swarm variable must be of type ParticleSwarmOptimization!")
It is raising error in the last line. In the interpreter it prints:
(type(swarm)).__name__
'instance'
I'd expect it to print "ParticleSwarmOptimization". I'm calling Bird's constructor the following way:
def AddBird(self, position = None):
self.birds += Bird(self, position)
With this I want that every bird has a reference to the main ParticleSwarmOptimization class, and I want to ensure that every time a Bird is created I have in fact a ParticleSwarmOptimization instance reference and not anything else.
Thanks!