2016-05-11 4 views
0

Ich versuche, eine IloNumArray in eine Datei unter Verwendung fprintf() zu drucken. Das Problem ist, dass ich die Länge des Arrays nicht kenne, da es durch eine getValues() Methode innerhalb eines Incumbent Callbacks gefüllt wird.Drucken Sie ein IloNumArray auf eine Datei in einem Incumbent Callback (C++)

Der Code des Rückrufs, wo ich das Problem habe, ist die folgende:

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"); 
    } 
} 

Danke für die Hilfe!

Antwort

0

IloNumArray hat ein Element getSize(), das Ihnen sagen soll, wie viele Elemente darin enthalten sind.