Ошибка при использовании существующего кода для оптимизации колонии муравьев в python: ошибка dytpe datum not found
Traceback (most recent call last):
File "C:\Users\user54\Desktop\AntColonyOptimizationGist.py", line 230, in <module>
optimize(500, 500, 250, 500000, 25, 10, freq=500, path="Video 8/")
File "C:\Users\user54\Desktop\AntColonyOptimizationGist.py", line 214, in optimize
grid = Grid(height, width, path)
File "C:\Users\user54\Desktop\AntColonyOptimizationGist.py", line 29, in __init__
self.grid = numpy.empty((height, width), dtype=Datum)
TypeError: data type not understood
Код, который я получаю из интернета:
class AntColonyOptimization:
def __init__(self):
pass
class Grid:
def __init__(self, height, width, path, rand_test=True):
"""
This method initializes a grid object. A grid is basically just a 2D array of Datum objects
:param height: this is the height of the grid
:param width: this is the weight of the grid
"""
self.path = path
# Store the dimensions of the grid
self.dim = numpy.array([height, width])
# Initialize an empty numpy matrix of type Datum
self.grid = numpy.empty((height, width), dtype=Datum)
if rand_test:
# This is used to fill the grid randomly
self.rand_grid(0.25)
# This makes the plot redraw
plt.ion()
plt.figure(figsize=(10, 10))
self.max_d = 0.001
def rand_grid(self, sparse):
"""
A method for randomly initializing the grid
:param sparse: the percentage of the grid to fill up
"""
for y in range(self.dim[0]):
for x in range(self.dim[1]):
if random.random() <= sparse:
r = random.randint(0, 1)
if r == 0:
self.grid[y][x] = Datum(nrand.normal(5, 0.25, 10))
elif r == 1:
self.grid[y][x] = Datum(nrand.normal(-5, 0.25, 10))
if __name__ == '__main__':
optimize(500, 500, 250, 500000, 25, 10, freq=500, path="Video 8/")
Кто-нибудь может дать мне решение?