8
I’m trying to implement the algorithm Hill Climb (Hill Climbing) and this algorithm should return the sequence of cities considered good (with the shortest distance between cities) the problem of the traveling salesman based on an adjacency matrix, however, I’m having difficulty in implementing the methods avaliar()
and sucessor()
, I don’t know what approach I should take to make these methods work as expected.
The implementation is being in Javascript:
let matrizAdjacente = [
[0, 1, 2, 3, 4, 5],
[2, 0, 5, 2, 1, 1],
[1, 8, 0, 2, 3, 4],
[2, 2, 1, 0, 6, 3],
[4, 2, 3, 1, 0, 4],
[3, 1, 3, 2, 2, 0]
];
let sequenciaCidades = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6];
let solucaoInicial = function() {
return [4, 5, 1, 6, 3, 2];
}
let avaliar = function(estado) {
}
let sucessor = function(atual, novo) {
}
let hillClimbing = function() {
let novo = null;
let atual = solucaoInicial();
let valorAvaliadoAtual = avaliar(atual);
let valorAvaliadoNovo = 0;
while (1) {
novo = sucessor(atual, novo);
valorAvaliadoNovo = avaliar(novo);
if (valorAvaliadoNovo < valorAvaliadoAtual) {
atual = novo;
valorAvaliadoAtual = valorAvaliadoAtual;
} else break;
}
return atual;
}
This algorithm consists of examining the successors of the current state and proceeding to the first state that is larger than the current one. However, it is necessary to implement the methods avaliar()
and sucessor()
, the successor method will make an exchange between states and the evaluate method will return a value given a sequence.
Question
So how could I implement the method avaliar()
and sucessor()
of the Slope Rise algorithm?
What the array values represent
sequenciaCidades
? Each city would not have its positioning x,y and distance calculated by Euclidean distance or distance Manhattan ?– Isac
@Isac in relation to this I was in doubt (it was not contextualized in the exercise), but probably are the cities that are linked based on the solution, I think it would not be necessary this array.
– gato
The
avaliar
is one of the arguments of the metaheuristic. On top of this, the hill Climbing makes the decision to continue or to go back one step and try again– Jefferson Quesado
By the way, this matrix is the distance matrix, no the adjacencies. XD
– Jefferson Quesado
@Jeffersonquesado in exercise was marked as adjacency matrix xD
– gato