Changeset 1062 for trunk


Ignore:
Timestamp:
Jun 24, 2008 6:13:41 PM (16 years ago)
Author:
liveletlive
Message:

Committing changes related to command <name> samples ?number?

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  
    1111#include<stdlib.h>
    1212#include<time.h>
     13//#include <tcl.h>
    1314
    1415#define EPSILON 0.005
     
    2021#define INVALID_SLOPE 99999.9999
    2122#define TOLERANCE 1e-5
     23#define BLOCK_SIZE 160
    2224
    2325typedef struct Curve{
     
    3941        double *yvals;
    4042        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
    4245}MaxOrMinList;
    4346
     
    6366                        }
    6467                        break;
    65                 case 3://Y = EXP(-x)*SINC(X);
     68                case 3://Y = EXP(-x)*SIN(10X);
    6669//                      init = -5;
    6770                        for(index=0;index<NO_OF_POINTS;index++){
     
    190193                                        if(slope_at_prev_point>0 && slope_at_point<=0){
    191194                                                ++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                                                        }
    195203                                                }
    196204                                                buffer->yvals[no_of_actual_max-1]=Y_Axis_Values[i];
     
    223231                                        if(slope_at_prev_point<0 && slope_at_point>=0){
    224232                                                ++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                                                        }
    228241                                                }
    229242                                                buffer->yvals[no_of_actual_min-1]=Y_Axis_Values[i];
     
    247260        double temp_glob_max;
    248261        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;
    251266                if(local_max_list_buffer.xvals!=NULL && local_max_list_buffer.yvals!=NULL){
    252267                        local_max_list = get_local_max_list(&local_max_list_buffer);
     
    258273                                                buffer->no_of_actual_max_or_mins = 1;
    259274                                                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;
    270281                                                        }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                                                }
    287304                                }else{
    288305                                        printf("\nThere are no Local Maxima, consequently a Global Maxima List cannot be generated\n");
     
    313330        double temp_glob_min;
    314331        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;
    317336                if(local_min_list_buffer.xvals!=NULL && local_min_list_buffer.yvals!=NULL){
    318337                        local_min_list = get_local_min_list(&local_min_list_buffer);
     
    324343                                                buffer->no_of_actual_max_or_mins = 1;
    325344                                                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;
    336351                                                        }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                                                }
    353374                                }else{
    354375                                        printf("\nThere are no Local Minima, consequently a Global Minima List cannot be generated\n");
     
    399420                                        if(slope_at_prev_point>0 && slope_at_point<=0){
    400421                                                ++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                                                        }
    404430                                                }
    405431                                                buffer->yvals[no_of_actual_max-1]=Y_Axis_Values[i];
     
    446472                                        if(slope_at_prev_point<0 && slope_at_point>=0){
    447473                                                ++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                                                        }
    451482                                                }
    452483                                                buffer->yvals[no_of_actual_min-1]=Y_Axis_Values[i];
     
    474505        int i;
    475506        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;
    478510        if(list.xvals!=NULL && list.yvals!=NULL){
    479511                buffer = get_local_max_list(&list);
  • trunk/packages/optimizer/src/fitfunc/ff_modules_for_discrete_params.c

    r1010 r1062  
    77#include<stdlib.h>
    88#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"
    1911
    2012
     
    2315* is not yet complete.
    2416*/
    25 double get_gene(int geneID){
     17double get_gene(char* name){
    2618        return 0;
    2719}
    2820
    2921/*
    30  * Return the actual values of all the genes in the current string
     22 * Return the actual values of all the genes in the currently evaluated chromosome
    3123 */
    3224double* get_all_genes(){
     
    3527
    3628/*
    37  * Return the gene value raised to a power
     29 * The way to go about doing this is to fetch 
    3830 */
    39 double gene_value_raised_to_power(int geneID){
     31double weighted_sum_of_variances(double* array_of_current_values, double* array_of_desired_values){
    4032        return 0;
    4133}
    4234
    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 }
    5435
    55 /*
    56  * I need to verify this yet.
    57  */
    58 double weighted_sum_of_nth_power_distances(){
    59         return 0;
     36double abs_nth_power_distance(double actual_value, double desired_value,double power){
     37        return pow(fabs(actual_value-desired_value),power);
    6038}
    6139
    6240int 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));
    6343        return 0;
    6444}
  • trunk/packages/optimizer/src/plugin_pgapack.c

    r986 r1062  
    2424} PgapackData;
    2525
     26
    2627RpCustomTclOptionParse RpOption_ParseOper;
    2728RpCustomTclOptionGet RpOption_GetOper;
     
    3536    "pga_poprepl", RpOption_ParsePopRepl, RpOption_GetPopRepl, NULL
    3637};
     38
     39typedef 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;
    3745
    3846RpTclOption PgapackOptions[] = {
     
    5866static RpOptimEnv* PgapGetEnvForContext _ANSI_ARGS_((PGAContext *ctx));
    5967static void PgapUnlinkContext2Env _ANSI_ARGS_((PGAContext *ctx));
    60 
    61 
     68void PGARuntimeDataTableInit _ANSI_ARGS_((RpOptimEnv *envPtr));
     69void PGARuntimeDataTableDeInit();
     70void GetSampleInformation _ANSI_ARGS_((char *buffer, int sampleNumber));
     71void PGARuntimeDataTableSetSampleValue _ANSI_ARGS_((RpOptimParam *chrom, double fitness));
     72static PgapackRuntimeDataTable table;
    6273/*
    6374 * ----------------------------------------------------------------------
     
    144155    PGARun(ctx, PgapEvaluate);
    145156    PGADestroy(ctx);
    146 
    147157    PgapUnlinkContext2Env(ctx);
    148158
     
    168178    int p;            /* sample #p being run */
    169179    int pop;          /* identifier for this population */
     180   
    170181{
    171182    double fit = 0.0;
     
    173184    RpOptimParam *paramPtr;
    174185    RpOptimStatus status;
    175 
    176186    envPtr = PgapGetEnvForContext(ctx);
    177187    paramPtr = (RpOptimParam*)PGAGetIndividual(ctx, p, pop)->chrom;
    178 
    179188    status = (*envPtr->evalProc)(envPtr, paramPtr, envPtr->numParams, &fit);
    180 
     189       
    181190    if (pgapack_abort) {
    182191        fprintf(stderr, "==WARNING: run aborted!");
     
    188197        PgapPrintString(ctx, stderr, p, pop);
    189198    }
    190 
     199       
     200        /*populate the table with this sample*/
     201        PGARuntimeDataTableSetSampleValue(paramPtr,fit);
    191202    return fit;
    192203}
     
    518529}
    519530
     531
     532
    520533/*
    521534 * ----------------------------------------------------------------------
     
    707720    }
    708721}
     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
     739void PGARuntimeDataTableInit(envPtr)
     740RpOptimEnv *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
     763void 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
     775void PGARuntimeDataTableSetSampleValue(chrom,fitness)
     776RpOptimParam *chrom;
     777double 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
     815void 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  
    2424#include <malloc.h>
    2525#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
    2629
    2730/*
     
    140143EXTERN void RpOptimDelete _ANSI_ARGS_((RpOptimEnv *envPtr));
    141144
     145
    142146#endif
  • trunk/packages/optimizer/src/rp_optimizer_tcl.c

    r986 r1062  
    7171
    7272extern int pgapack_abort;
     73extern void PGARuntimeDataTableInit();
     74extern void PGARuntimeDataTableDeInit();
     75extern void GetSampleInformation();
    7376
    7477int
     
    224227    toolDataPtr->updateCmdPtr = NULL;
    225228    envPtr->toolData = (ClientData)toolDataPtr;
    226 
    227229    Tcl_CreateObjCommand(interp, name, RpOptimInstanceCmd,
    228230        (ClientData)envPtr, (Tcl_CmdDeleteProc*)RpOptimCmdDelete);
    229 
    230231    Tcl_SetResult(interp, name, TCL_VOLATILE);
    231232    return TCL_OK;
     
    250251    ClientData paramdata;
    251252
     253    PGARuntimeDataTableDeInit();/*Free space allocated to data table here*/
    252254    if (envPtr->toolData) {
    253255        toolDataPtr = (RpOptimToolData*)envPtr->toolData;
     
    290292 *                     ?-updatecommand <varName>?
    291293 *      <name> using
     294 *      <name> samples ?number?
    292295 *
    293296 *  The "add" command is used to add various parameter types to the
    294297 *  optimizer context.  The "perform" command kicks off an optimization
    295  *  run.
     298 *  run. The "samples" command displays sample info during an optimization run.
    296299 * ------------------------------------------------------------------------
    297300 */
     
    313316    RpTclOption *optSpecPtr;
    314317    Tcl_Obj *rval, *rrval, *toolPtr, *updateCmdPtr;
    315 
     318   
    316319    if (objc < 2) {
    317320        Tcl_WrongNumArgs(interp, 1, objv, "option ?args...?");
     
    580583        /* no -updatecommand by default */
    581584        updateCmdPtr = NULL;
    582 
     585               
     586                PGARuntimeDataTableInit(envPtr);/*Initialize Data table here....*/
     587               
    583588        n = 2;
    584589        while (n < objc) {
     
    632637            toolDataPtr->updateCmdPtr = updateCmdPtr;
    633638        }
    634 
     639               
    635640        /* call the main optimization routine here */
    636641        status = (*envPtr->pluginDefn->runProc)(envPtr,
    637642            RpOptimizerPerformInTcl, fitnessExpr);
    638 
    639         fprintf(stderr, ">>>status=%d\n", status);
     643               
     644                fprintf(stderr, ">>>status=%d\n", status);
    640645
    641646        Tcl_DecrRefCount(toolPtr);
     
    682687        return TCL_OK;
    683688    }
     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    }
    684716
    685717    else {
    686718        Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
    687719            "bad option \"", option, "\": should be add, configure, "
    688             "get, perform, using", (char*)NULL);
     720            "get, perform, using, samples", (char*)NULL);
    689721        return TCL_ERROR;
    690722    }
Note: See TracChangeset for help on using the changeset viewer.