0
我试图使用fprintf()
将IloNumArray
打印到文件中。问题是我不知道Array的长度,因为它在现任回调中被getValues()
方法填充。将IloNumArray打印到现有回调中的文件(C++)
在那里我遇到的问题回调的代码是以下之一:
ILOINCUMBENTCALLBACK3(MyFirstcallback,
IloCplex, cplex,
IloInt, contador,
IloNumVarArray, varenteras){
int i;
int length=0;
IloNum CurrentInc = MAX_COL;
IloNum BestTime = 0;
IloNum BestObj = MAX_COL;
IloNumArray BestSol(varenteras.getEnv());
IloNum FirstTime = 0;
IloNum FirstObj = MAX_COL;
IloNumArray FirstSol(varenteras.getEnv());
if (hasIncumbent()) {
if (contador == 0 || contador == 1){
contador+=1;
FirstObj=getIncumbentObjValue();
getValues(FirstSol,varenteras);
FirstTime=cplex.getTime();
length=sizeof(FirstSol)/sizeof(FirstSol[0]);
//The first issue is here, length should be the size of the solution, and it's not giving it.
printf("El tiempo %lf el valor %lf el largo de la solucion %d \n",FirstTime,FirstObj,length);
FILE* out;
out = fopen("ResultadoPruebaTamanotest.txt","at+");
fprintf(out,"%lf \t %lf \n",FirstTime,FirstObj);
for (i=0;i<length;i++){
fprintf(out,"%d \t",FirstSol[i]);
}
fprintf(out,"\n");
}
}
感谢您的帮助!