return cost
size attribute and neighbours_matrix function