/*****************************************************************************
*     FILE: get.c: This file contains routines to return values from the
*                  context variable and other structures.
*
*     Authors: David M. Levine, Philip L. Hallstrom, David M. Noelle
*****************************************************************************/
#include "pgapack.h"


/*U***************************************************************************
   PGAGetDataType - Returns the data type specified.

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      Returns the integer corresponding to the symbolic constant
      used to specify the data type.

   Example:
      PGAContext *ctx;
      int datatype;
      :
      datatype = PGAGetDataType(ctx);
      switch (datatype) {
      case PGA_DATATYPE_BINARY:
          printf("Data Type = PGA_DATATYPE_BINARY\n");
          break;
      case PGA_DATATYPE_INTEGER:
          printf("Data Type = PGA_DATATYPE_INTEGER\n");
          break;
      case PGA_DATATYPE_REAL:
          printf("Data Type = PGA_DATATYPE_REAL\n");
          break;
      case PGA_DATATYPE_USER:
          printf("Data Type = PGA_DATATYPE_USER\n");
          break;
      }

***************************************************************************U*/
int PGAGetDataType (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetDataType", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetDataType", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.datatype);
}

/*U***************************************************************************
   PGAGetOptDir - Returns the direction of optimization

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      Returns the integer corresponding to the symbolic constant
      used to specify the  direction of optimization

   Example:
      PGAContext *ctx;
      int optdir;
      :
      optdir = PGAGetOptDir(ctx);
      switch (optdir) {
      case PGA_MAXIMIZE:
          printf("Optimization direction = PGA_MAXIMIZE\n");
          break;
      case PGA_MINIMIZE:
          printf("Optimization direction = PGA_MINIMIZE\n");
          break;
      }

***************************************************************************U*/
int PGAGetOptDir (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetOptDir", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetOptDir", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.optdir);
}

/*U***************************************************************************
   PGAGetPopSize - Returns the population size

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      The population size

   Example:
      PGAContext *ctx;
      int popsize;
      :
      popsize = PGAGetPopSize(ctx);

***************************************************************************U*/
int PGAGetPopSize (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetPopSize", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetPopSize", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.PopSize);
}

/*U***************************************************************************
   PGAGetStringLen - Returns the string length

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      The string length

   Example:
      PGAContext *ctx;
      int stringlen;
      :
      stringlen = PGAGetStringLen(ctx);

***************************************************************************U*/
int PGAGetStringLen (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetStringLen", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetStringLen", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.StringLen);
}

/*U***************************************************************************
   PGAGetStoppingRule - Returns the termination criteria

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      Returns an integer which is an ANDed mask of the symbolic constants
      used to specify the stopping rule(s)

   Example:
      PGAContext *ctx;
      int stop;
      :
      stop = PGAGetStoppingRule(ctx);
      for (mask = PGA_STOP_MAXITER; mask <= PGA_STOP_TOOSIMILAR;
           mask <<= 1)
          if ((stop & mask) == mask)
          switch (mask) {
          case PGA_STOP_MAXITER:
              printf("Stopping Rule = PGA_STOP_MAXITER\n");
              break;
          case PGA_STOP_NOCHANGE:
              printf("Stopping Rule = PGA_STOP_NOCHANGE\n");
              break;
          case PGA_STOP_TOOSIMILAR:
              printf("Stopping Rule = PGA_STOP_TOOSIMILAR\n");
              break;
          }

***************************************************************************U*/
int PGAGetStoppingRule (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetStoppingRule", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetStoppingRule", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.StoppingRule);
}

/*U***************************************************************************
   PGAGetMaxIter - Returns the maximum number of iterations to run

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      The maximum number of iterations to run (if PGA_STOP_MAXITER
      has been set as one of the stopping rules)

   Example:
      PGAContext *ctx;
      int maxiter;
      :
      maxiter = PGAGetMaxIter(ctx);

***************************************************************************U*/
int PGAGetMaxIter (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetMaxIter", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetMaxIter", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.MaxIter);
}

/*U***************************************************************************
   PGAGetNumReplace - Returns the maximum number number of strings to replace
                      each generation

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      The maximum number number of strings to replace each generation

   Example:
      PGAContext *ctx;
      int numreplace;
      :
      numreplace = PGAGetNumReplace(ctx);

***************************************************************************U*/
int PGAGetNumReplace (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetNumReplace", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetNumReplace", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.NumReplace);
}

/*U***************************************************************************
   PGAGetCrossoverType - Returns the type of crossover selected

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      Returns the integer corresponding to the symbolic constant
      used to specify the crossover type

   Example:
      PGAContext *ctx;
      int crosstype;
      :
      crosstype = PGAGetCrossoverType(ctx);
      switch (crosstype) {
      case PGA_CROSSOVER_ONEPT:
          printf("Crossover Type = PGA_CROSSOVER_ONEPT\n");
          break;
      case PGA_CROSSOVER_TWOPT:
          printf("Crossover Type = PGA_CROSSOVER_TWOPT\n");
          break;
      case PGA_CROSSOVER_UNIFORM:
          printf("Crossover Type = PGA_CROSSOVER_UNIFORM\n");
          break;
      }

***************************************************************************U*/
int PGAGetCrossoverType (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetCrossoverType", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetCrossoverType", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.CrossoverType);
}

/*U***************************************************************************
   PGAGetSelectType - Returns the type of selection selected

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      Returns the integer corresponding to the symbolic constant
      used to specify the type of selection specified

   Example:
      PGAContext *ctx;
      int selecttype;
      :
      selecttype = PGAGetSelectType(ctx);
      switch (selecttype) {
      case PGA_SELECT_PROPORTIONAL:
          printf("Selection Type = PGA_SELECT_PROPORTIONAL\n");
          break;
      case PGA_SELECT_SUS:
          printf("Selection Type = PGA_SELECT_SUS\n");
          break;
      case PGA_SELECT_TOURNAMENT:
          printf("Selection Type = PGA_SELECT_TOURNAMENT\n");
          break;
      case PGA_SELECT_PTOURNAMENT:
          printf("Selection Type = PGA_SELECT_PTOURNAMENT\n");
          break;
      }

***************************************************************************U*/
int PGAGetSelectType (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetSelectType", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetSelectType", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.SelectType);
}

/*U***************************************************************************
   PGAGetFitnessType - Returns the type of fitness transformation used

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      Returns the integer corresponding to the symbolic constant
      used to specify the type of fitness transformation used 

   Example:
      PGAContext *ctx;
      int fittype;
      :
      fittype = PGAGetFitnessType(ctx);
      switch (fittype) {
      case PGA_FITNESS_RAW:
          printf("Fitness Type = PGA_FITNESS_RAW\n");
          break;
      case PGA_FITNESS_NORMAL:
          printf("Fitness Type = PGA_FITNESS_NORMAL\n");
          break;
      case PGA_FITNESS_RANKING:
          printf("Fitness Type = PGA_FITNESS_RANKING\n");
          break;
      }

***************************************************************************U*/
int PGAGetFitnessType (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetFitnessType", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetFitnessType", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.FitnessType);
}

/*U***************************************************************************
   PGAGetFitnessMinType - Returns the type of fitness transformation used
                          for minimization problems

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      Returns the integer corresponding to the symbolic constant
      used to specify the type of fitness transformation used 
      for minimization problems

   Example:
      PGAContext *ctx;
      int fitmintype;
      :
      fitmintype = PGAGetFitnessMinType(ctx);
      switch (fitmintype) {
      case PGA_FITNESSMIN_RECIPROCAL:
          printf("Fitness Minimization Type = PGA_FITNESSMIN_RECIPROCAL\n");
          break;
      case PGA_FITNESSMIN_CMAX:
          printf("Fitness Minimization Type = PGA_FITNESSMIN_CMAX\n");
          break;
      }

***************************************************************************U*/
int PGAGetFitnessMinType (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetFitnessMinType", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetFitnessMinType", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.FitnessMinType);
}

/*U***************************************************************************
   PGAGetMutationType - Returns the type of mutation used

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      Returns the integer corresponding to the symbolic constant
      used to specify the type of mutation specified

   Example:
      PGAContext *ctx;
      int mutatetype;
      :
      mutatetype = PGAGetMutationType(ctx);
      switch (mutatetype) {
      case PGA_MUTATION_FIXED:
          printf("Mutation Type = PGA_MUTATION_FIXED\n");
          break;
      case PGA_MUTATION_STRINGLEN:
          printf("Mutation Type = PGA_MUTATION_STRINGLEN\n");
          break;
      case PGA_MUTATION_HAMMING:
          printf("Mutation Type = PGA_MUTATION_HAMMING\n");
          break;
      case PGA_MUTATION_UNIFORM:
          printf("Mutation Type = PGA_MUTATION_UNIFORM\n");
          break;
      case PGA_MUTATION_GAUSSIAN:
          printf("Mutation Type = PGA_MUTATION_GAUSSIAN\n");
          break;
      }

***************************************************************************U*/
int PGAGetMutationType (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetMutationType", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetMutationType", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.MutationType);
}

/*U***************************************************************************
   PGAGetMutateOnlyNoCross - Returns true/false if only strings not from 
                             crossover are being mutated

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      Returns PGATRUE if only strings that do not undergo crossover
      are mutated.  Otherwise, returns PGAFALSE

   Example:
      PGAContext *ctx;
      int mutatetype;
      :
      mutatetype = PGAGetMutateOnlyNoCross(ctx);
      switch (mutatetype) {
      case PGATRUE:
          printf("Only mutating strings not undergoing crossover\n");
          break;
      case PGAFALSE:
          printf("Mutating strings after crossover\n");
          break;
      }

***************************************************************************U*/
int PGAGetMutateOnlyNoCross (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetMutateOnlyNoCross",
                   "Entered", PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetMutateOnlyNoCross",
                   "Exit", PGA_VOID, NULL );

    return(ctx->ga.MutateOnlyNoCross);
}

/*U***************************************************************************
   PGAGetMutateRealVal - Returns the value of the multiplier used to mutate
                         Real strings with

   Category: Mutation
                          
   Inputs:
      ctx - context variable
      
   Outputs:
      The value of the multiplier used to mutate Real strings with

   Example:
      PGAContext *ctx;
      double val;
      :
      val = PGAGetMutateRealVal(ctx);

***************************************************************************U*/
double PGAGetMutateRealVal (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetMutateRealVal", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetMutateRealVal", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.MutateRealVal);
}


/*U***************************************************************************
   PGAGetMutateIntegerVal - Returns the value of the multiplier used to mutate
                            Integer strings with

   Category: Mutation
                          
   Inputs:
      ctx - context variable
      
   Outputs:
      The value of the multiplier used to mutate integer strings with

   Example:
      PGAContext *ctx;
      int ival;
      :
      ival = PGAGetMutateIntegerVal(ctx);

***************************************************************************U*/
int PGAGetMutateIntegerVal (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetMutateIntegerVal", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetMutateIntegerVal", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.MutateIntegerVal);
}


/*U***************************************************************************
   PGAGetNoDuplicates - Returns true/false if duplicate strings
                        are allowed

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      Returns PGATRUE if duplicate strings are not allowed in the
      population. Otherwise, returns PGAFALSE

   Example:
      PGAContext *ctx;
      int nodups;
      :
      nodups = PGAGetNoDuplicates(ctx);
      switch (nodups) {
      case PGATRUE:
          printf("Duplicate strings not allowed in population\n");
          break;
      case PGAFALSE:
          printf("Duplicate strings allowed in population\n");
          break;
      }

***************************************************************************U*/
int PGAGetNoDuplicates (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetNoDuplicates", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetNoDuplicates", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.NoDuplicates);
}

/*U***************************************************************************
   PGAGetMutationProb - Returns the starting mutation probability

   Category: Mutation
                          
   Inputs:
      ctx - context variable
      
   Outputs:
      The mutation probability

   Example:
      PGAContext *ctx;
      double pm;
      :
      pm = PGAGetMutateProb(ctx);

***************************************************************************U*/
double PGAGetMutationProb (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetMutationProb", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetMutationProb", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.MutationProb);
}

/*U***************************************************************************
   PGAGetCrossoverProb - Returns the crossover probability

   Category: Crossover
                          
   Inputs:
      ctx - context variable
      
   Outputs:
      The crossover probability

   Example:
      PGAContext *ctx;
      double pc;
      :
      pc = PGAGetCrossoverProb(ctx);

***************************************************************************U*/
double PGAGetCrossoverProb (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetCrossoverProb", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetCrossoverProb", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.CrossoverProb);
}

/*U***************************************************************************
   PGAGetUniformCrossProb - returns the probability of a bit being selected
                            from the first child string in uniform crossover

   Category: Crossover

   Inputs:
      ctx - context variable
      
   Outputs:
      The uniform crossover probability

   Example:
      PGAContext *ctx;
      double pu;
      :
      pu = PGAGetUniformCrossProb(ctx);

***************************************************************************U*/
double PGAGetUniformCrossProb (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetUniformCrossProb", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetUniformCrossProb", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.UniformCrossProb);
}

/*U***************************************************************************
   PGAGetFitnessRankMax - returns the MAX value used in rank-based fitness

   Category: Fitness

   Inputs:
      ctx - context variable
      
   Outputs:
      The value of MAX used in rank-based fitness

   Example:
      PGAContext *ctx;
      double max;
      :
      max = PGAGetFitnessRankMax(ctx);

***************************************************************************U*/
double PGAGetFitnessRankMax (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetFitnessRankMax", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetFitnessRankMax", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.FitnessRankMax);
}

/*U***************************************************************************
   PGAGetPopReplace - returns the method used to choosing strings from the
                      old population to copy to the new population

   Category: Generation

   Inputs:
      ctx - context variable
      
   Outputs:
      Returns the method used to choosing strings from the
      old population to copy to the new population

   Example:
      PGAContext *ctx;
      int popreplace;
      :
      popreplace = PGAGetPopReplace(ctx);
      switch (popreplace) {
      case PGA_POPREPL_BEST:
          printf("Data Type = PGA_POPREPL_BEST\n");
          break;
      case PGA_POPREPL_RANDOM_REP:
          printf("Data Type = PGA_POPREPL_RANDOM_REP\n");
          break;
      case PGA_POPREPL_RANDOM_NOREP:
          printf("Data Type = PGA_POPREPL_RANDOM_NOREP\n");
          break;
      }

****************************************************************************U*/
int PGAGetPopReplace (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetPopReplace", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetPopReplace", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.PopReplace);
}

/*U***************************************************************************
   PGAGetIter - returns the number of the current genetic algorithm generation 

   Category: Generation
   
   Inputs:
      ctx - context variable
      
   Outputs:
      The genetic algorithm generation number

   Example:
      PGAContext *ctx;
      int g;
      :
      g = PGAGetIter(ctx);

***************************************************************************U*/
int PGAGetIter (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetIter", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetIter", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->ga.iter);
}

/*U***************************************************************************
   PGAGetMaxInt - returns the largest integer of the given machine

   Category: System
   
   Inputs:
      ctx - context variable
      
   Outputs:
      The largest integer of the given machine

   Example:
      PGAContext *ctx;
      int intmax;
      :
      intmax = PGAGetMaxInt(ctx);

***************************************************************************U*/
int PGAGetMaxInt (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetMaxInt", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetMaxInt", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->sys.PGAMaxInt);
}

/*U***************************************************************************
   PGAGetMaxInt - returns the smallest integer of the given machine

   Category: System
   
   Inputs:
      ctx - context variable
      
   Outputs:
      The smallest integer of the given machine

   Example:
      PGAContext *ctx;
      int intmin;
      :
      intmin = PGAGetMinInt(ctx);

***************************************************************************U*/
int PGAGetMinInt (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetMinInt", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetMinInt", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->sys.PGAMinInt);
}

/*U***************************************************************************
   PGAGetMaxDouble - returns the largest double of the given machine

   Category: System
   
   Inputs:
      ctx - context variable
      
   Outputs:
      The largest double of the given machine

   Example:
      PGAContext *ctx;
      double big;
      :
      big = PGAGetMaxDouble(ctx);

***************************************************************************U*/
double PGAGetMaxDouble (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetMaxDouble", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetMaxDouble", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->sys.PGAMaxDouble);
}

/*U***************************************************************************
   PGAGetMaxDouble - returns the smallest double of the given machine

   Category: System
   
   Inputs:
      ctx - context variable
      
   Outputs:
      The smallest double of the given machine

   Example:
      PGAContext *ctx;
      double small;
      :
      small = PGAGetMinDouble(ctx);

***************************************************************************U*/
double PGAGetMinDouble (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetMinDouble", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetMinDouble", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->sys.PGAMinDouble);
}

/*U***************************************************************************
   PGAGetPrintFreq - returns how often to print statistics reports

   Category: Reporting
   
   Inputs:
      ctx - context variable
      
   Outputs:
      The frequency of printing output

   Example:
      PGAContext *ctx;
      int freq;
      :
      freq = PGAGetPrintFreq(ctx);

***************************************************************************U*/
int PGAGetPrintFreq (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetPrintFreq", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetPrintFreq", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->rep.PrintFreq);
}

/*U***************************************************************************
   PGAGetRandomInit - returns true/false to indicate flag whether to
                      randomly initialize strings

   Category: Initialization

   Inputs:
      ctx - context variable
      
   Outputs:
      Returns PGATRUE if strings are randomly initialized.
      Otherwise, returns PGAFALSE

   Example:
      PGAContext *ctx;
      int raninit;
      :
      raninit = PGAGetRandomInit(ctx);
      switch (raninit) {
      case PGATRUE:
          printf("Population is randomly initialized\n");
          break;
      case PGAFALSE:
          printf("Population initialized to zero\n");
          break;
      }

***************************************************************************U*/
int PGAGetRandomInit (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetRandomInit", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetRandomInit", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->init.RandomInit);
}

/*U***************************************************************************
   PGAGetBinaryInitProb - Returns the probability that a bit will be
                          randomly initialized to one

   Category: Initialization
                          
   Inputs:
      ctx - context variable
      
   Outputs:
      The probability that a bit will be randomly initialized to one

   Example:
      PGAContext *ctx;
      double prob;
      :
      prob = PGAGetBinaryInitProb(ctx);

***************************************************************************U*/
double PGAGetBinaryInitProb (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetBinaryInitProb", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetBinaryInitProb", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->init.BinaryProbability);
}

/*U***************************************************************************
   PGAGetIntegerType - returns the type of scheme used to randomly initialize
                       strings of data type Integer

   Category: Initialization
   
   Inputs:
      ctx - context variable
      
   Outputs:
      Returns the integer corresponding to the symbolic constant
      used to specify the scheme used to initialize integer strings
      
   Example:
      PGAContext *ctx;
      int inittype;
      :
      inittype = PGAGetIntegerType(ctx);
      switch (inittype) {
      case PGA_PERMUTE:
          printf("Data Type = PGA_PERMUTE\n");
          break;
      case PGA_RANGE:
          printf("Data Type = PGA_RANGE\n");
          break;
      }
      
***************************************************************************U*/
int PGAGetIntegerType (PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetIntegerType", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetIntegerType", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->init.IntegerType);
}

/*U***************************************************************************
   PGAGetInitIntegerMin - returns the minimum of the range of integers used
                          to randomly initialize integer strings

   Category: Initialization
   
   Inputs:
      ctx - context variable
      
   Outputs:
      The minimum of the range of integers used to randomly initialize
      integer strings

   Example:
      PGAContext *ctx;
      int min;
      :
      min = PGAGetInitIntegerMin(ctx);

***************************************************************************U*/
int PGAGetInitIntegerMin (PGAContext *ctx, int i)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetInitIntegerMin", "Entered", 
                   PGA_VOID, NULL );

    if (i < 0 || i >= ctx->ga.StringLen)
	 PGAError(ctx, "PGAGetInitIntegerMin: Index out of range:", PGA_FATAL,
		  PGA_INT, (int *) &i);

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetInitIntegerMin", "Exit", 
                   PGA_VOID, NULL );

    return ctx->init.IntegerMin[i];
}

/*U***************************************************************************
   PGAGetInitIntegerMax - returns the maximum of the range of integers used
                          to randomly initialize integer strings

   Category: Initialization
   
   Inputs:
      ctx - context variable
      
   Outputs:
      The maximum of the range of integers used to randomly initialize
      integer strings

   Example:
      PGAContext *ctx;
      int max;
      :
      max = PGAGetInitIntegerMax(ctx);

***************************************************************************U*/
int PGAGetInitIntegerMax (PGAContext *ctx, int i)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetInitIntegerMax", "Entered", 
                   PGA_VOID, NULL );

    if (i < 0 || i >= ctx->ga.StringLen)
	 PGAError(ctx, "PGAGetInitIntegerMax: Index out of range:", PGA_FATAL,
		  PGA_INT, (int *) &i);
    

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetInitIntegerMax", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->init.IntegerMax[i]);
}

/*U***************************************************************************
   PGAGetInitRealMin - returns the minimum value used to randomly initialize
                       real strings

   Category: Initialization
   
   Inputs:
      ctx - context variable
      
   Outputs:
      The minimum value used to randomly initialize real strings
   Example:
      PGAContext *ctx;
      int min;
      :
      min = PGAGetInitRealMin(ctx);

***************************************************************************U*/
double PGAGetInitRealMin (PGAContext *ctx, int i)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetInitRealMin", "Entered", 
                   PGA_VOID, NULL );

    if (i < 0 || i >= ctx->ga.StringLen)
	 PGAError(ctx, "PGAGetInitRealMin: Index out of range:", PGA_FATAL,
		  PGA_INT, (int *) &i);

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetInitRealMin", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->init.RealMin[i]);
}

/*U***************************************************************************
   PGAGetInitRealMax - returns the maximum value used to randomly initialize
                       real strings

   Category: Initialization
   
   Inputs:
      ctx - context variable
      
   Outputs:
      The maximum value used to randomly initialize real strings
   Example:
      PGAContext *ctx;
      int max;
      :
      max = PGAGetInitRealMax(ctx);

***************************************************************************U*/
double PGAGetInitRealMax (PGAContext *ctx, int i)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetInitRealMax", "Entered", 
                   PGA_VOID, NULL );

    if (i < 0 || i >= ctx->ga.StringLen)
	 PGAError(ctx, "PGAGetInitRealMax: Index out of range:", PGA_FATAL,
		  PGA_INT, (int *) &i);

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetInitRealMax", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->init.RealMax[i]);
}
/*U***************************************************************************
   PGAGetRandomSeed - returns the integer to seed random numbers with

   Category: Random
   
   Inputs:
      ctx - context variable
      
   Outputs:
      The seed for the random number generator

   Example:
      PGAContext *ctx;
      int seed;
      :
      seed = PGAGetRandomSeed(ctx);

***************************************************************************U*/
int PGAGetRandomSeed(PGAContext *ctx)
{
    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetRandomSeed", "Entered", 
                   PGA_VOID, NULL );

    PGADebugPrint( ctx, PGADEBUG_EXIT,    "PGAGetRandomSeed", "Exit", 
                   PGA_VOID, NULL );

    return(ctx->init.RandomSeed);
}

/*U***************************************************************************
   PGAGetEvaluate - returns the evaluation function value for
                    string p in population pop

   Category: Fitness
   
   Inputs:
      ctx - context variable
      p   - string index
      pop - symbolic constant of the population the string is in

   Outputs:
      The evaluation function value for string p in population pop

   Example:
      PGAContext *ctx;
      double eval;
      :
      eval = PGAGetEvaluate(ctx);

***************************************************************************U*/
double PGAGetEvaluate ( PGAContext *ctx, int p, int pop )
{
    PGAIndividual *ind;

    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetEvaluate", "Entered", 
                   PGA_VOID, NULL );
    PGADebugPrint( ctx, PGADEBUG_PRINTVAR,"PGAGetEvaluate", "p = ", 
                   PGA_INT, (void *) &p );
    PGADebugPrint( ctx, PGADEBUG_PRINTVAR,"PGAGetEvaluate", "pop = ", 
                   PGA_INT, (void *) &pop );
    
    ind               = PGAGetIndividual ( ctx, p, pop );
    PGADebugPrint( ctx, PGADEBUG_EXIT, "PGAGetEvaluate", "Exit",
                   PGA_VOID, NULL );
    return(ind->evalfunc);

}

/*U***************************************************************************
   PGAGetFitness - returns the fitness value for string p in population pop

   Category: Fitness
   
   Inputs:
      ctx - context variable
      p   - string index
      pop - symbolic constant of the population the string is in

   Outputs:
      The fitness value for string p in population pop

   Example:
      PGAContext *ctx;
      double fit;
      :
      fit = PGAGetFitness(ctx);

***************************************************************************U*/
double PGAGetFitness ( PGAContext *ctx, int p, int pop )
{
    PGAIndividual *ind;

    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetFitness", "Entered", 
                   PGA_VOID, NULL );
    PGADebugPrint( ctx, PGADEBUG_PRINTVAR,"PGAGetFitness", "p = ", 
                   PGA_INT, (void *) &p );
    PGADebugPrint( ctx, PGADEBUG_PRINTVAR,"PGAGetFitness", "pop = ", 
                   PGA_INT, (void *) &pop );
    
    ind               = PGAGetIndividual ( ctx, p, pop );
    PGADebugPrint( ctx, PGADEBUG_EXIT, "PGAGetFitness", "Exit",
                   PGA_VOID, NULL );
    return(ind->evalfunc);

}

/*U***************************************************************************
   PGAGetEvalUpToDate - returns true/false to indicate whether the evaluate
                        function value is up to date

   Category: Fitness
   
   Inputs:
      ctx - context variable
      p   - string index
      pop - symbolic constant of the population the string is in

   Outputs:
      Returns PGATRUE if the evaluate function value is up to date.
      Otherwise, returns PGAFALSE

   Example:
      PGAContext *ctx;
      int uptodate;
      :
      uptodate = PGAGetEvalUpToDate(ctx);
      switch (uptodate) {
      case PGATRUE:
          printf("Evaluation function value current\n");
          break;
      case PGAFALSE:
          printf("Evaluation function value out-of-date\n");
          break;
      }

***************************************************************************U*/
int PGAGetEvalUpToDate ( PGAContext *ctx, int p, int pop )
{
    PGAIndividual *ind;

    PGADebugPrint( ctx, PGADEBUG_ENTERED, "PGAGetEvalUpToDate", "Entered", 
                   PGA_VOID, NULL );
    PGADebugPrint( ctx, PGADEBUG_PRINTVAR,"PGAGetEvalUpToDate", "p = ", 
                   PGA_INT, (void *) &p );
    PGADebugPrint( ctx, PGADEBUG_PRINTVAR,"PGAGetEvalUpToDate", "pop = ", 
                   PGA_INT, (void *) &pop );
    
    ind               = PGAGetIndividual ( ctx, p, pop );
    PGADebugPrint( ctx, PGADEBUG_EXIT, "PGAGetEvalUpToDate", "Exit",
                   PGA_VOID, NULL );
    return(ind->evaluptodate);

}

/*U***************************************************************************
  PGAGetWorst - returns the index of the string with the worst evaluation
  function value in population pop

  Category: Reporting
   
  Inputs:
     ctx - context variable
     pop - symbolic constant of the population to find the worst string in
      
  Outputs:
     Index of the string with the worst evaluation function value

  Example:
     PGAContext *ctx;
     int worst;
     :
     worst = PGAGetWorst(ctx,PGA_OLDPOP);

***************************************************************************U*/
int PGAGetWorst(PGAContext *ctx, int pop)
{
     int p, worst_indx = 0;
     double eval, worst_eval;

     for (p = 0; p < ctx->ga.PopSize; p++)
	  if (!PGAGetEvalUpToDate(ctx, p, pop))
	       PGAError(ctx, "PGAGetWorst: Evaluate function not up to date:",
			PGA_FATAL, PGA_INT, (void *) &p);

     worst_eval = PGAGetEvaluate(ctx, 0, pop);
     for (p = 1; p < ctx->ga.PopSize; p++)
     {
	  eval = PGAGetEvaluate(ctx, p, pop);

	  switch (PGAGetOptDir(ctx))
	  {
	  case PGA_MAXIMIZE :
	       if (eval < worst_eval)
	       {
		    worst_indx = p;
		    worst_eval = eval;
	       }
	       break;
	  case PGA_MINIMIZE :
	       if (eval > worst_eval)
	       {
		    worst_indx = p;
		    worst_eval = eval;
	       }
	       
	  }
     }
     return worst_indx;
}

/*U***************************************************************************
  PGAGetBest - returns the index of the string with the best evaluation
  function value in population pop

  Category: Reporting
   
  Inputs:
     ctx - context variable
     pop - symbolic constant of the population to find the best string in
      
  Outputs:
     Index of the string with the best evaluation function value

  Example:
     PGAContext *ctx;
     int best;
     :
     best = PGAGetBest(ctx,PGA_OLDPOP);

***************************************************************************U*/
int PGAGetBest(PGAContext *ctx, int pop)
{
     int p, Best_indx = 0;
     double eval, Best_eval;

     for (p = 0; p < ctx->ga.PopSize; p++)
	  if (!PGAGetEvalUpToDate(ctx, p, pop))
	       PGAError(ctx, "PGAGetBest: Evaluate function not up to date:",
			PGA_FATAL, PGA_INT, (void *) &p);

     Best_eval = PGAGetEvaluate(ctx, 0, pop);
     for (p = 1; p < ctx->ga.PopSize; p++)
     {
	  eval = PGAGetEvaluate(ctx, p, pop);

	  switch (PGAGetOptDir(ctx))
	  {
	  case PGA_MAXIMIZE :
	       if (eval > Best_eval)
	       {
		    Best_indx = p;
		    Best_eval = eval;
	       }
	       break;
	  case PGA_MINIMIZE :
	       if (eval < Best_eval)
	       {
		    Best_indx = p;
		    Best_eval = eval;
	       }
	       
	  }
     }
     return Best_indx;
}

/*U***************************************************************************
   PGAGetPTournamentProb - returns the probability of selecting the best 
                           string in a probabilistic binary tournament

   Category: Selection

   Inputs:
      ctx - context variable
      
   Outputs:
      The probabilistic binary tournament selection probability

   Example:
      PGAContext *ctx;
      double pt;
      :
      pt = PGAGetPTournamentProb(ctx);

***************************************************************************U*/
double PGAGetPTournamentProb(PGAContext *ctx)
{
     PGADebugPrint(ctx, PGADEBUG_ENTERED, "PGAGetPTournamentProb", "Entered",
		   PGA_VOID, NULL);

     PGADebugPrint(ctx, PGADEBUG_ENTERED, "PGAGetPTournamentProb", "Entered",
		   PGA_VOID, NULL);

     return ctx->ga.PTournamentProb;
}

      
