Resources

Getting Started Example (ga0)


/***************************************************************/
/*                                                             */
/*          S A S   S A M P L E   L I B R A R Y                */
/*                                                             */
/*    NAME: ga0                                                */
/*   TITLE: Getting Started Example (ga0)                      */
/* PRODUCT: OR                                                 */
/*  SYSTEM: ALL                                                */
/*    KEYS: OR                                                 */
/*   PROCS: GA                                                 */
/*    DATA:                                                    */
/*                                                             */
/* SUPPORT:                             UPDATE:                */
/*     REF:                                                    */
/*    MISC: Example from the Getting Started section of the    */
/*          GA chapter of Local Search Optimization.           */
/*                                                             */
/***************************************************************/

proc ga seed = 12 maxiter = 30;
/* the objective function to be optimized */
function shubert(selected[*]);
   array x[2] /nosym;
   call ReadMember(selected,1,x);
   x1 = x[1];
   x2 = x[2];
   sum1 = 0;
   do i = 1 to 5;
      sum1 = sum1 + i * cos((i+1)* x1 + i);
   end;
   sum2 = 0;
   do i = 1 to 5;
      sum2 = sum2 + i * cos((i+1) * x2 + i);
   end;
   result = sum1 * sum2;
   return(result);
endsub;
/* Set the problem encoding */
call SetEncoding('R2');
/* Set upper and lower bounds on the solution components */
array LowerBound[2] /nosym (-10 -10);
array UpperBound[2] /nosym (10 10);
call SetBounds(LowerBound, UpperBound);
/* Set the objective function */
call SetObjFunc('shubert',0);
/* Set the crossover parameters */
call SetCrossProb(0.65);
call SetCross('Heuristic');
/* Set the mutation parameters */
call SetMutProb(0.15);
array del[2] /nosym (0.2 0.2);
call SetMut('Delta','nchange', 1, 'delta',del);
/* Set the selection criteria */
call SetSel('tournament','size', 2);
call SetElite(2);
/* Initialize the first generation, with 120 random solutions  */
call Initialize('DEFAULT',120);
/* Now execute the Genetic Algorithm */
run;
quit;