I'm writing code for my degree essay based on column generation. I'm having a problem running the code i have written so far. the code is split up into 2 routines:
lin_call() calls a lin keringham algorithm which is already installed on my linux system and asks from the user to input the lin executable location and the input data file formated in .tsp format.
lin_call.c:
Code:
#include<stdio.h>
/******* Lin-Keringham function call **************/
void lin_call(char *exec_path,char *exec_file,char *in_file){
int ret;
ret=execl(exec_path,exec_file,"-o","lin_out",in_file,"..",NULL);
if(ret=-1) perror("execl");
}
lin_to_col() takes the results file from lin_col() and creates a route column using quick sort. it also calculates the final tour cost.
lin_to_col.c:
Code:
#include<stdio.h>
#include<stdlib.h>
int comp(const void *i,const void *j){
return *(int *)i-*(int *)j;
}
void lin_to_col(char *in_file){
FILE *fp;
int i,dum,col_size;
float weight,sum_weight=0;
struct prevnext{
int prev;
int next;
}*col;
fp=fopen(in_file,"r");
fscanf(fp,"%d %d",&col_size,&dum);
col=(int *)calloc(col_size,sizeof(struct prevnext));
for(i=0;i<col_size;++i){
fscanf(fp,"%d %d %f",&col[i].prev,&col[i].next,&weight);
sum_weight+=weight;
}
qsort(col,col_size,sizeof(struct prevnext),comp);
for(i=0;i<col_size;++i){
printf("%d\t%d\n",col[i].prev,col[i].next);
}
printf("\n\n%.2f\n",sum_weight);
fclose(fp);
}
Now note that both procedures run flawlessly when called independentely and with the right order from the main file. the syntax in linux shell is:
suppressing the lin_to_col call:
Code:
gcc main.c lin_call.c -o lin_call
./lin_call (executable path) (input file path)
suppressing the lin_cal call:
Code:
gcc main.c lin_to_col.c -o lin_to_col
./lin_to_call
the code for calling both procedures is shown below:
main.c:
Code:
#include<stdio.h>
int main(char *argc,char *argv[]){
lin_call(argv[1],"linkern",argv[2]);
lin_to_col("lin_out");
return 0;
}
compiling and running the whole program:
Code:
gcc main.c lin_call.c lin_to_col.c -o main
./main (executable path) (input file path)
The problem is when trying to call both procedures in the same time as shown above. this is when main() runs only the first call producing right results but not running the lin_to_col(). is anything wrong to what i'm doing.
any input would be usefull
thanks in advance