Changeset 1062 for trunk/packages/optimizer/src
- Timestamp:
- Jun 24, 2008, 6:13:41 PM (16 years ago)
- Location:
- trunk/packages/optimizer/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/optimizer/src/fitfunc/ff_helper_modules_for_curves.c
r1008 r1062 11 11 #include<stdlib.h> 12 12 #include<time.h> 13 //#include <tcl.h> 13 14 14 15 #define EPSILON 0.005 … … 20 21 #define INVALID_SLOPE 99999.9999 21 22 #define TOLERANCE 1e-5 23 #define BLOCK_SIZE 160 22 24 23 25 typedef struct Curve{ … … 39 41 double *yvals; 40 42 double *xvals; 41 int no_of_actual_max_or_mins; 43 int no_of_actual_max_or_mins; 44 int size_allotted; //While using the structure, be sure you initialize this to the amount of memory malloc'ed, else there is no way to keep track of memory allocated dynamically 42 45 }MaxOrMinList; 43 46 … … 63 66 } 64 67 break; 65 case 3://Y = EXP(-x)*SIN C(X);68 case 3://Y = EXP(-x)*SIN(10X); 66 69 // init = -5; 67 70 for(index=0;index<NO_OF_POINTS;index++){ … … 190 193 if(slope_at_prev_point>0 && slope_at_point<=0){ 191 194 ++no_of_actual_max; 192 if(no_of_actual_max>1){ 193 buffer->xvals = realloc(buffer->xvals,(sizeof(double))*(no_of_actual_max)); 194 buffer->yvals = realloc(buffer->yvals,(sizeof(double))*(no_of_actual_max)); 195 if(no_of_actual_max>((buffer->size_allotted)/sizeof(double))){ 196 buffer->size_allotted*=2; 197 buffer->xvals = realloc(buffer->xvals,buffer->size_allotted); 198 buffer->yvals = realloc(buffer->yvals,buffer->size_allotted); 199 if(buffer->xvals==NULL || buffer->yvals==NULL){ 200 printf("\nError: Reallocation for buffer failed while populating local maxima list"); 201 return NULL; 202 } 195 203 } 196 204 buffer->yvals[no_of_actual_max-1]=Y_Axis_Values[i]; … … 223 231 if(slope_at_prev_point<0 && slope_at_point>=0){ 224 232 ++no_of_actual_min; 225 if(no_of_actual_min>1){ 226 buffer->xvals = realloc(buffer->xvals,(sizeof(double))*(no_of_actual_min)); 227 buffer->yvals = realloc(buffer->yvals,(sizeof(double))*(no_of_actual_min)); 233 if(no_of_actual_min>((buffer->size_allotted)/sizeof(double))){ 234 buffer->size_allotted*=2; 235 buffer->xvals = realloc(buffer->xvals,buffer->size_allotted); 236 buffer->yvals = realloc(buffer->yvals,buffer->size_allotted); 237 if(buffer->xvals==NULL || buffer->yvals==NULL){ 238 printf("\nError: Reallocation for buffer failed while populating local maxima list"); 239 return NULL; 240 } 228 241 } 229 242 buffer->yvals[no_of_actual_min-1]=Y_Axis_Values[i]; … … 247 260 double temp_glob_max; 248 261 if(buffer!=NULL){ 249 local_max_list_buffer.xvals = malloc(sizeof(double)); 250 local_max_list_buffer.yvals = malloc(sizeof(double)); 262 //size_allotted must be specified, or you sow what you reap... 263 local_max_list_buffer.xvals = malloc(BLOCK_SIZE); 264 local_max_list_buffer.yvals = malloc(BLOCK_SIZE); 265 local_max_list_buffer.size_allotted = BLOCK_SIZE; 251 266 if(local_max_list_buffer.xvals!=NULL && local_max_list_buffer.yvals!=NULL){ 252 267 local_max_list = get_local_max_list(&local_max_list_buffer); … … 258 273 buffer->no_of_actual_max_or_mins = 1; 259 274 no_of_actual_global_max=1; 260 if(local_max_list->no_of_actual_max_or_mins == 1){ 261 return buffer; 262 } 263 for(i=1;i<local_max_list->no_of_actual_max_or_mins;i++){ 264 if(fabs(temp_glob_max-local_max_list->yvals[i])<TOLERANCE){ 265 ++no_of_actual_global_max; 266 }else{ 267 if(temp_glob_max < local_max_list->yvals[i]){ 268 no_of_actual_global_max =1; 269 temp_glob_max = local_max_list->yvals[i]; 275 if(local_max_list->no_of_actual_max_or_mins == 1){ 276 return buffer; 277 } 278 for(i=1;i<local_max_list->no_of_actual_max_or_mins;i++){ 279 if(fabs(temp_glob_max-local_max_list->yvals[i])<TOLERANCE){ 280 ++no_of_actual_global_max; 270 281 }else{ 271 continue; 272 } 273 } 274 if(no_of_actual_global_max>1){ 275 //Reallocate space if necessary... 276 buffer->yvals = realloc(buffer->yvals,no_of_actual_global_max*sizeof(double)); 277 buffer->xvals = realloc(buffer->xvals,no_of_actual_global_max*sizeof(double)); 278 if(buffer->xvals == NULL || buffer->yvals == NULL){ 279 printf("\nError: Could not Reallocate space for the Global Maxima List.\n"); 280 return NULL; 281 } 282 } 283 buffer->yvals[no_of_actual_global_max-1] = temp_glob_max; 284 buffer->xvals[no_of_actual_global_max-1] = local_max_list->xvals[i]; 285 buffer->no_of_actual_max_or_mins = no_of_actual_global_max; 286 } 282 if(temp_glob_max < local_max_list->yvals[i]){ 283 no_of_actual_global_max =1; 284 temp_glob_max = local_max_list->yvals[i]; 285 }else{ 286 continue; 287 } 288 } 289 if(no_of_actual_global_max>((buffer->size_allotted)/sizeof(double))){ 290 printf("Buffer Size allotted for Global Max list = %d", buffer->size_allotted); 291 //Reallocate space if necessary... 292 buffer->size_allotted*=2; 293 buffer->yvals = realloc(buffer->yvals,buffer->size_allotted); 294 buffer->xvals = realloc(buffer->xvals,buffer->size_allotted); 295 if(buffer->xvals == NULL || buffer->yvals == NULL){ 296 printf("\nError: Could not Reallocate space for the Global Maxima List.\n"); 297 return NULL; 298 } 299 } 300 buffer->yvals[no_of_actual_global_max-1] = temp_glob_max; 301 buffer->xvals[no_of_actual_global_max-1] = local_max_list->xvals[i]; 302 buffer->no_of_actual_max_or_mins = no_of_actual_global_max; 303 } 287 304 }else{ 288 305 printf("\nThere are no Local Maxima, consequently a Global Maxima List cannot be generated\n"); … … 313 330 double temp_glob_min; 314 331 if(buffer!=NULL){ 315 local_min_list_buffer.xvals = malloc(sizeof(double)); 316 local_min_list_buffer.yvals = malloc(sizeof(double)); 332 //size_allotted must be specified, or you sow what you reap... 333 local_min_list_buffer.xvals = malloc(BLOCK_SIZE); 334 local_min_list_buffer.yvals = malloc(BLOCK_SIZE); 335 local_min_list_buffer.size_allotted = BLOCK_SIZE; 317 336 if(local_min_list_buffer.xvals!=NULL && local_min_list_buffer.yvals!=NULL){ 318 337 local_min_list = get_local_min_list(&local_min_list_buffer); … … 324 343 buffer->no_of_actual_max_or_mins = 1; 325 344 no_of_actual_global_min=1; 326 if(local_min_list->no_of_actual_max_or_mins == 1){ 327 return buffer; 328 } 329 for(i=1;i<local_min_list->no_of_actual_max_or_mins;i++){ 330 if(fabs(temp_glob_min-local_min_list->yvals[i])<TOLERANCE){ 331 ++no_of_actual_global_min; 332 }else{ 333 if(temp_glob_min > local_min_list->yvals[i]){ 334 no_of_actual_global_min =1; 335 temp_glob_min = local_min_list->yvals[i]; 345 if(local_min_list->no_of_actual_max_or_mins == 1){ 346 return buffer; 347 } 348 for(i=1;i<local_min_list->no_of_actual_max_or_mins;i++){ 349 if(fabs(temp_glob_min-local_min_list->yvals[i])<TOLERANCE){ 350 ++no_of_actual_global_min; 336 351 }else{ 337 continue; 338 } 339 } 340 if(no_of_actual_global_min>1){ 341 //Reallocate space if necessary... 342 buffer->yvals = realloc(buffer->yvals,no_of_actual_global_min*sizeof(double)); 343 buffer->xvals = realloc(buffer->xvals,no_of_actual_global_min*sizeof(double)); 344 if(buffer->xvals == NULL || buffer->yvals == NULL){ 345 printf("\nError: Could not Reallocate space for the Global Minima List.\n"); 346 return NULL; 347 } 348 } 349 buffer->yvals[no_of_actual_global_min-1] = temp_glob_min; 350 buffer->xvals[no_of_actual_global_min-1] = local_min_list->xvals[i]; 351 buffer->no_of_actual_max_or_mins = no_of_actual_global_min; 352 } 352 if(temp_glob_min > local_min_list->yvals[i]){ 353 no_of_actual_global_min =1; 354 temp_glob_min = local_min_list->yvals[i]; 355 }else{ 356 continue; 357 } 358 } 359 if(no_of_actual_global_min>((buffer->size_allotted)/sizeof(double))){ 360 //Reallocate space if necessary... 361 printf("Buffer Size allotted for Global Max list = %d", buffer->size_allotted); 362 buffer->size_allotted*=2; 363 buffer->yvals = realloc(buffer->yvals,buffer->size_allotted); 364 buffer->xvals = realloc(buffer->xvals,buffer->size_allotted); 365 if(buffer->xvals == NULL || buffer->yvals == NULL){ 366 printf("\nError: Could not Reallocate space for the Global Minima List.\n"); 367 return NULL; 368 } 369 } 370 buffer->yvals[no_of_actual_global_min-1] = temp_glob_min; 371 buffer->xvals[no_of_actual_global_min-1] = local_min_list->xvals[i]; 372 buffer->no_of_actual_max_or_mins = no_of_actual_global_min; 373 } 353 374 }else{ 354 375 printf("\nThere are no Local Minima, consequently a Global Minima List cannot be generated\n"); … … 399 420 if(slope_at_prev_point>0 && slope_at_point<=0){ 400 421 ++no_of_actual_max; 401 if(no_of_actual_max>1){ 402 buffer->xvals = realloc(buffer->xvals,(sizeof(double))*(no_of_actual_max)); 403 buffer->yvals = realloc(buffer->yvals,(sizeof(double))*(no_of_actual_max)); 422 if(no_of_actual_max>((buffer->size_allotted)/sizeof(double))){ 423 buffer->size_allotted*=2; 424 buffer->xvals = realloc(buffer->xvals,buffer->size_allotted); 425 buffer->yvals = realloc(buffer->yvals,buffer->size_allotted); 426 if(buffer->xvals == NULL || buffer->yvals == NULL){ 427 printf("\nError: Could not Reallocate space for the Global Minima List.\n"); 428 return NULL; 429 } 404 430 } 405 431 buffer->yvals[no_of_actual_max-1]=Y_Axis_Values[i]; … … 446 472 if(slope_at_prev_point<0 && slope_at_point>=0){ 447 473 ++no_of_actual_min; 448 if(no_of_actual_min>1){ 449 buffer->xvals = realloc(buffer->xvals,(sizeof(double))*(no_of_actual_min)); 450 buffer->yvals = realloc(buffer->yvals,(sizeof(double))*(no_of_actual_min)); 474 if(no_of_actual_min>((buffer->size_allotted)/sizeof(double))){ 475 buffer->size_allotted*=2; 476 buffer->xvals = realloc(buffer->xvals,buffer->size_allotted); 477 buffer->yvals = realloc(buffer->yvals,buffer->size_allotted); 478 if(buffer->xvals == NULL || buffer->yvals == NULL){ 479 printf("\nError: Could not Reallocate space for the Global Minima List.\n"); 480 return NULL; 481 } 451 482 } 452 483 buffer->yvals[no_of_actual_min-1]=Y_Axis_Values[i]; … … 474 505 int i; 475 506 double xval1,xval2; 476 list.xvals = malloc(sizeof(double)); 477 list.yvals = malloc(sizeof(double)); 507 list.xvals = malloc(BLOCK_SIZE); 508 list.yvals = malloc(BLOCK_SIZE); 509 list.size_allotted =BLOCK_SIZE; 478 510 if(list.xvals!=NULL && list.yvals!=NULL){ 479 511 buffer = get_local_max_list(&list); -
trunk/packages/optimizer/src/fitfunc/ff_modules_for_discrete_params.c
r1010 r1062 7 7 #include<stdlib.h> 8 8 #include<time.h> 9 10 //I think this structure needs to be included with PGAPACK code. A list of current gene values can be maintained and 11 //before each evaluation the gene values can be updated. 12 typedef struct Gene{ 13 int geneID; 14 double weight; 15 double value; 16 double rangemin; 17 double rangemax; 18 }Gene; 9 #include "pgapack.h" 10 #include "rp_optimizer.h" 19 11 20 12 … … 23 15 * is not yet complete. 24 16 */ 25 double get_gene( int geneID){17 double get_gene(char* name){ 26 18 return 0; 27 19 } 28 20 29 21 /* 30 * Return the actual values of all the genes in the current string22 * Return the actual values of all the genes in the currently evaluated chromosome 31 23 */ 32 24 double* get_all_genes(){ … … 35 27 36 28 /* 37 * Return the gene value raised to a power29 * The way to go about doing this is to fetch 38 30 */ 39 double gene_value_raised_to_power(int geneID){31 double weighted_sum_of_variances(double* array_of_current_values, double* array_of_desired_values){ 40 32 return 0; 41 33 } 42 34 43 /*44 * Return the absolute value of a gene.45 */46 47 double gene_abs_value(int geneID){48 return 0;49 }50 51 double weighted_sum_of_genes(){52 return 0;53 }54 35 55 /* 56 * I need to verify this yet. 57 */ 58 double weighted_sum_of_nth_power_distances(){ 59 return 0; 36 double abs_nth_power_distance(double actual_value, double desired_value,double power){ 37 return pow(fabs(actual_value-desired_value),power); 60 38 } 61 39 62 40 int main(){ 41 double actual=5,desired=30,power=0.2; 42 printf("Actual - %lf, Desired - %lf, (Actual-Desired)^ %lf is %lf\n", actual,desired,power,abs_nth_power_distance(actual,desired,power)); 63 43 return 0; 64 44 } -
trunk/packages/optimizer/src/plugin_pgapack.c
r986 r1062 24 24 } PgapackData; 25 25 26 26 27 RpCustomTclOptionParse RpOption_ParseOper; 27 28 RpCustomTclOptionGet RpOption_GetOper; … … 35 36 "pga_poprepl", RpOption_ParsePopRepl, RpOption_GetPopRepl, NULL 36 37 }; 38 39 typedef struct PgapackRuntimeDataTable{ 40 double **data; /*Actual data per sample, like values of the genes, fitness of a sample, etc*/ 41 int num_of_rows; /*Number of rows alloced..should be constant for a run*/ 42 int no_of_samples_evaled; /*Number of samples evaluated so far*/ 43 int no_of_columns; /*Number of columns allocated to the data table so far*/ 44 }PgapackRuntimeDataTable; 37 45 38 46 RpTclOption PgapackOptions[] = { … … 58 66 static RpOptimEnv* PgapGetEnvForContext _ANSI_ARGS_((PGAContext *ctx)); 59 67 static void PgapUnlinkContext2Env _ANSI_ARGS_((PGAContext *ctx)); 60 61 68 void PGARuntimeDataTableInit _ANSI_ARGS_((RpOptimEnv *envPtr)); 69 void PGARuntimeDataTableDeInit(); 70 void GetSampleInformation _ANSI_ARGS_((char *buffer, int sampleNumber)); 71 void PGARuntimeDataTableSetSampleValue _ANSI_ARGS_((RpOptimParam *chrom, double fitness)); 72 static PgapackRuntimeDataTable table; 62 73 /* 63 74 * ---------------------------------------------------------------------- … … 144 155 PGARun(ctx, PgapEvaluate); 145 156 PGADestroy(ctx); 146 147 157 PgapUnlinkContext2Env(ctx); 148 158 … … 168 178 int p; /* sample #p being run */ 169 179 int pop; /* identifier for this population */ 180 170 181 { 171 182 double fit = 0.0; … … 173 184 RpOptimParam *paramPtr; 174 185 RpOptimStatus status; 175 176 186 envPtr = PgapGetEnvForContext(ctx); 177 187 paramPtr = (RpOptimParam*)PGAGetIndividual(ctx, p, pop)->chrom; 178 179 188 status = (*envPtr->evalProc)(envPtr, paramPtr, envPtr->numParams, &fit); 180 189 181 190 if (pgapack_abort) { 182 191 fprintf(stderr, "==WARNING: run aborted!"); … … 188 197 PgapPrintString(ctx, stderr, p, pop); 189 198 } 190 199 200 /*populate the table with this sample*/ 201 PGARuntimeDataTableSetSampleValue(paramPtr,fit); 191 202 return fit; 192 203 } … … 518 529 } 519 530 531 532 520 533 /* 521 534 * ---------------------------------------------------------------------- … … 707 720 } 708 721 } 722 /*--------------------------------------------------------------------------------- 723 * PGARuntimeDTInit(): It initializes the runtime data table. 724 * The table is organized slightly counter-intuitively 725 * Instead of a 726 * param1|param2|param3 |param4... 727 * val11 |val12 |val13 |val14... 728 * val12 |val22 |val23 |val24.... 729 * orientation, it is organized as 730 * param1|val11|val12 731 * param2|val21|val22 732 * param3|val31|val32 733 * param4|val41|val42 734 * Reallocating for additional columns is easier than reallocating additional rows and then 735 * reallocating for columns 736 * -------------------------------------------------------------------------------- 737 */ 738 739 void PGARuntimeDataTableInit(envPtr) 740 RpOptimEnv *envPtr; 741 { 742 int i; 743 if(envPtr != NULL){ 744 table.num_of_rows = (envPtr->numParams)+1; 745 table.data = malloc((table.num_of_rows)*sizeof(double*)); 746 if(table.data == NULL){ 747 panic("\nAllocation for Runtime Data Table failed\n"); 748 } 749 for(i=0;i<table.num_of_rows;i++){ 750 table.data[i] = malloc(PGAPACK_RUNTIME_TABLE_DEFAULT_SIZE*sizeof(double)); 751 if(table.data[i] == NULL){ 752 panic("\nAllocation for Runtime Data Table failed\n"); 753 } 754 } 755 table.no_of_samples_evaled = 0; 756 table.no_of_columns = PGAPACK_RUNTIME_TABLE_DEFAULT_SIZE; 757 758 }else{ 759 panic("\nError: NULL Environment variable OR Table pointer passed to Data Table Init\n"); 760 } 761 } 762 763 void PGARuntimeDataTableDeInit() 764 { 765 int i; 766 if((&table) == NULL){ 767 panic("Error: Table not present, therefore cannot free memory.."); 768 } 769 for(i=0;i<table.num_of_rows;i++){ 770 free(table.data[i]); 771 } 772 free(table.data); 773 } 774 775 void PGARuntimeDataTableSetSampleValue(chrom,fitness) 776 RpOptimParam *chrom; 777 double fitness; 778 { 779 int i; 780 printf("\nSetting sample value.......................\n"); 781 if(chrom!=NULL && (&table)!=NULL){ 782 (table.no_of_samples_evaled)+=1; 783 if((table.no_of_samples_evaled) > table.no_of_columns){ 784 /* then Reallocate space for more columns)*/ 785 (table.no_of_columns)+=(table.no_of_columns); 786 //TODO GTG: Delete printing stuff 787 for(i=0;i<(table.num_of_rows);i++){ 788 table.data[i] = realloc(table.data[i],table.no_of_columns); 789 if(table.data[i]==NULL){ 790 panic("\nError: Could not Reallocate more space for the table"); 791 } 792 } 793 }else{ 794 if(chrom->type == RP_OPTIMPARAM_NUMBER){ 795 for(i=0;i<(table.num_of_rows);i++){ 796 if(i==0){ 797 table.data[i][(table.no_of_samples_evaled)-1] = fitness; 798 printf("\nSample Number %d:- Fitness: %lf\t",table.no_of_samples_evaled,fitness); 799 }else{ 800 table.data[i][(table.no_of_samples_evaled)-1] = chrom[i-1].value.dval; 801 printf("Param %d %lf\t",i,table.data[i][(table.no_of_samples_evaled)-1]); 802 } 803 } 804 }else{ 805 panic("\n Chromosome value is RP_OPTIMPARAM_STRING\n"); 806 //GTG TODO: find out what happens in this case. Will we be better off handling Tcl_objects? 807 } 808 } 809 }else{ 810 panic("\nError:Either Chromosome, or table passed to PGARuntimeDataTableSetSampleValue() is NULL\n"); 811 } 812 813 } 814 815 void GetSampleInformation(buffer,sampleNumber) 816 char *buffer; 817 int sampleNumber; 818 { 819 int i; 820 char tempBuff[50]; 821 printf("\nFetching sample information.........................\n"); 822 if((&table) == NULL){ 823 panic("Table uninitialized"); 824 } 825 if(sampleNumber<=0){ 826 sprintf(buffer,"\nNumber of Samples Evaluated so far: %d\n",(table.no_of_samples_evaled)+1); 827 return; 828 } 829 if(((table.num_of_rows)-1)*10>SINGLE_SAMPLE_DATA_BUFFER_DEFAULT_SIZE){ 830 buffer = realloc(buffer,50+25*(table.num_of_rows)); 831 //resizing the buffer, keeping 50 for display related jazz, around 12-15 characs for param names 832 //and 10 characs for Fl.pt. display of the value 833 if(buffer == NULL){ 834 panic("\nError: Could not reallocate space for sample data buffer"); 835 } 836 } 837 for(i=0;i<(table.num_of_rows);i++){ 838 if(i==0){ 839 sprintf(buffer,"\nSample Number %d ----> Fitness: %lf ",sampleNumber,table.data[i][sampleNumber-1]); 840 }else{ 841 sprintf(tempBuff,"Param %d: %lf ",i,table.data[i][sampleNumber-1]); 842 strcat(buffer,tempBuff); 843 } 844 } 845 strcat(buffer,"\n"); 846 } -
trunk/packages/optimizer/src/rp_optimizer.h
r899 r1062 24 24 #include <malloc.h> 25 25 #include "rp_tcloptions.h" 26 27 #define PGAPACK_RUNTIME_TABLE_DEFAULT_SIZE 5000 /*Approx Number of Samples in a run*/ 28 #define SINGLE_SAMPLE_DATA_BUFFER_DEFAULT_SIZE 5000 26 29 27 30 /* … … 140 143 EXTERN void RpOptimDelete _ANSI_ARGS_((RpOptimEnv *envPtr)); 141 144 145 142 146 #endif -
trunk/packages/optimizer/src/rp_optimizer_tcl.c
r986 r1062 71 71 72 72 extern int pgapack_abort; 73 extern void PGARuntimeDataTableInit(); 74 extern void PGARuntimeDataTableDeInit(); 75 extern void GetSampleInformation(); 73 76 74 77 int … … 224 227 toolDataPtr->updateCmdPtr = NULL; 225 228 envPtr->toolData = (ClientData)toolDataPtr; 226 227 229 Tcl_CreateObjCommand(interp, name, RpOptimInstanceCmd, 228 230 (ClientData)envPtr, (Tcl_CmdDeleteProc*)RpOptimCmdDelete); 229 230 231 Tcl_SetResult(interp, name, TCL_VOLATILE); 231 232 return TCL_OK; … … 250 251 ClientData paramdata; 251 252 253 PGARuntimeDataTableDeInit();/*Free space allocated to data table here*/ 252 254 if (envPtr->toolData) { 253 255 toolDataPtr = (RpOptimToolData*)envPtr->toolData; … … 290 292 * ?-updatecommand <varName>? 291 293 * <name> using 294 * <name> samples ?number? 292 295 * 293 296 * The "add" command is used to add various parameter types to the 294 297 * optimizer context. The "perform" command kicks off an optimization 295 * run. 298 * run. The "samples" command displays sample info during an optimization run. 296 299 * ------------------------------------------------------------------------ 297 300 */ … … 313 316 RpTclOption *optSpecPtr; 314 317 Tcl_Obj *rval, *rrval, *toolPtr, *updateCmdPtr; 315 318 316 319 if (objc < 2) { 317 320 Tcl_WrongNumArgs(interp, 1, objv, "option ?args...?"); … … 580 583 /* no -updatecommand by default */ 581 584 updateCmdPtr = NULL; 582 585 586 PGARuntimeDataTableInit(envPtr);/*Initialize Data table here....*/ 587 583 588 n = 2; 584 589 while (n < objc) { … … 632 637 toolDataPtr->updateCmdPtr = updateCmdPtr; 633 638 } 634 639 635 640 /* call the main optimization routine here */ 636 641 status = (*envPtr->pluginDefn->runProc)(envPtr, 637 642 RpOptimizerPerformInTcl, fitnessExpr); 638 639 fprintf(stderr, ">>>status=%d\n", status);643 644 fprintf(stderr, ">>>status=%d\n", status); 640 645 641 646 Tcl_DecrRefCount(toolPtr); … … 682 687 return TCL_OK; 683 688 } 689 690 else if(*option == 's' && strcmp(option,"samples") == 0){ 691 int sampleNumber = -1; /*initing sampnum to -1, use it when no sample number is specified*/ 692 char *sampleDataBuffer; 693 if(objc>3){ 694 Tcl_WrongNumArgs(interp, 2, objv, "?sampleNumber?"); 695 return TCL_ERROR; 696 } 697 698 if(objc == 3){ 699 if(Tcl_GetIntFromObj(interp,objv[2],&sampleNumber) != TCL_OK){ 700 return TCL_ERROR; 701 } 702 sampleDataBuffer = malloc(sizeof(char)*SINGLE_SAMPLE_DATA_BUFFER_DEFAULT_SIZE); 703 }else{ 704 sampleDataBuffer = malloc(sizeof(char)*50); 705 } 706 707 if(sampleDataBuffer == NULL){ 708 panic("Error: Could not allocate memory for sample data buffer."); 709 } 710 GetSampleInformation(sampleDataBuffer,sampleNumber); 711 fprintf(stdout,sampleDataBuffer);/**TODO GTG check if this should be fprintf or something else*/ 712 free(sampleDataBuffer); 713 return TCL_OK; 714 715 } 684 716 685 717 else { 686 718 Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), 687 719 "bad option \"", option, "\": should be add, configure, " 688 "get, perform, using ", (char*)NULL);720 "get, perform, using, samples", (char*)NULL); 689 721 return TCL_ERROR; 690 722 }
Note: See TracChangeset
for help on using the changeset viewer.