Exemple #1
0
int main(int argc, char *argv[]){
    int length;
    vector* vertices;
    int* solution;
    int* edges;
    int i, j, k, n = 0;
    int this_x;
    int this_y;
    int this_n;
    FILE *fp;
    if(argc < 3){
        printf("Missing arguments: name of test file, number of lines\n");
        return 0;
    }
    n = atoi(argv[2]);
    length = n;
    vertices = (vector*)malloc(length*sizeof(vector));
    fp = fopen(argv[1], "r");
    if (fp == NULL){
        printf("input file %s not found! Aborting.\n", argv[1]);
        return 0;
    }
    printf("successfully opened file\n");
    while (fscanf(fp, "%i %i %i", &this_n, &this_x, &this_y) == 3){
        //printf("adding vertex # %d coords %d %d\n", this_n, this_x, this_y);
        vertices[k].x = this_x;
        vertices[k].y = this_y;
        vertices[k++].n = this_n;
    }
    //printf("made vertices, now calling distance to make edges\n");
    edges = distance(vertices,length);
    //printf("made edges, now calling chris to make solution\n");
    solution = christofides(edges,length);
    printf("length of Christofides algorithm path: %d\n", solution[0]);

    //free(vertices);
    free(edges);
    free(solution);
}
Exemple #2
0
int getLRSTourFast(vector<ModEdge> lGraph, vector<double> lambda, Graph g, int numNodes)
{
	vector<Edge> tree = lpToEdge(sampleLRTNew(lGraph, true));
	vector<int> tour;
	return (numNodes == tree.size() + 1) ? christofides(&g, tree, tour, true) : INT_MAX;
}