next up previous
Next: Generated C Code for Up: DARWIN - A Genetic Previous: Specifications


DARWIN Solution to the Sample Problem

% extenal function ;
external function int randomint(int a, int b);
external function int randomfloat(int a, int b);

% genome definition ;
gene TRectangle
{
   int x;
   int y;
   frozen int width;
   frozen int height;
} < evaluator : RectangleEval,  % evaluator moderator 
    init : RectangleInit;	% initializer moderator

chromosome TRectangles
{
   TRectangle rectangles[20]; 
};

population Pop
{
   TRectangles individuals[100];
};

algorithm GA
{
   Pop population;
};

% end of genome definitions ;

% gene TRectangle evaluator moderator ;
function float RectangleEval(TRectangle gene)
{
   if ((gene.x > 255) || (gene.y > 255))
     return 0;
   return 1;
}

% gene TRectangle initializer moderator ;
function RectangleInit(TRectangle gene)
{
   gene.x = random(0,255);
   gene.y = random(0,255);
   gene.width  = random(0, 255-gene.x);
   gene.height = random(0, 255-gene.y);
}



Gokturk Ucoluk 2003-09-15