The error is not related to the naming of the columns and rows of the distance matrix. The problem lies in the ga() function.
Here’s a revised version of your code:
popSize = 100
res <- ga(
type = "permutation",
fitness = fitness,
distMatrix = D_perm,
lower = 1,
upper = nrow(D_perm),
mutation = mutation(nrow(D_perm), fixed_points),
crossover = gaperm_pmxCrossover,
suggestions = feasiblePopulation(nrow(D_perm), popSize, fixed_points),
popSize = popSize,
maxiter = 5000,
run = 100
)
colnames(D_perm)[res@solution[1,]]
In this code, I have reduced the population size to 100. You can try different values and see if it works for you.
Additionally, consider using a smaller population size, as suggested in the comments. A larger population size doesn’t necessarily lead to better results, but rather increases the computation time.
If you still encounter errors, it might be due to other factors such as the fitness function or the mutation function not working correctly. In that case, try debugging these functions and see if they produce any meaningful results.
Lastly, consider using a different optimization algorithm or technique if the Genetic Algorithm is not producing satisfactory results. Other algorithms like Simulated Annealing, or techniques like Local Search could be worth considering.
Last modified on 2024-03-15