Christofides Algorithm - TSP, Problem in transforming AGM into a graph with all vertices of even degree

4

I'm implementing the Christofides algorithm and I'm getting the data from TSPLIB. the Christofides Algorithm has the following steps:

  • Finding the Minimum Generation Tree
  • Find all odd vertices (an even number of vertices)
  • Find the perfect minimum marriage of odd degree vertices
  • Add the edges of the perfect wedding in AGM
  • Find an Eulerian path within this graph
  • I was doing the algorithm and I got to step 5, however, only then I realized that the marriage of the vertices I was finding was not the perfect one, which is done in the following code:

    int** adicionar_CM_na_AGM(int **m, int **agm, int qVgi, int *vGi,int n){
    int menor =99999,v1=0,v2=0,verticeMenor;
    int *aux = (int *) calloc(qVgi, sizeof(int));
    for(int i=0; i<qVgi; i++)
    {
        for(int j=0; j<qVgi; j++)
        {
            if(vGi[i] != vGi[j] && menor > m[vGi[i]][vGi[j]] && aux[vGi[i]] != 1 && aux[vGi[j]] != 1)
            {
                printf("%d O %d\n", i, m[vGi[i]][vGi[j]]);
                v1 = vGi[i];
                v2 = vGi[j];
                menor = m[vGi[i]][vGi[j]];
            }
        }
        aux[v1]= 1;//cria a situação de já visitados
        aux[v2]= 1;
        agm[v1][v2] = m[v1][v2];//adiciona na AGM as arestas dos vGi
        agm[v2][v1] = m[v2][v1];
        menor =9999;
    }
    return agm;
    

    where: m: adjacency matrix with the distances of the vertices

    agm: AGM adjacency matrix of m

    qVgi: integer representing the number of odd-degree vertices

    vGi: vector containing vertex numbers that have odd degrees

    n: integer that represents the total vertex number of the matrix m

    I would like to know if anyone would have ideas so that I can find the perfect minimum marriage of the odd grade vertices of my graph.

        
    asked by anonymous 07.06.2018 / 17:25

    0 answers