comp.lang.ada
 help / color / mirror / Atom feed
From: montgrimpulo <aghte@hotlinemail.com>
Subject: Re: Function definitions - with clarification
Date: Mon, 30 Jun 2014 06:23:35 -0700 (PDT)
Date: 2014-06-30T06:23:35-07:00	[thread overview]
Message-ID: <01fb15d2-d063-44e6-9ebc-aa3b90a3c7a0@googlegroups.com> (raw)
In-Reply-To: <f12eba4c-2757-4496-861b-101cb7e355d6@googlegroups.com>

I have slightly changed the structure:

package paradigm is

   type Individual;
   type vi is access Individual;
   type Rvp is array (Positive range <>) of Long_Float;
   type Ivq is array (Positive range <>) of Long_Integer;
   type Bvr is array (Positive range <>) of Natural range 0 .. 1;
   type Lux is array (Positive range <>, Positive range <>) of Long_Float;
   type Luy is array (Positive range <>, Positive range <>) of Long_Integer;
   type Individual (P, Q, R : Natural) is record
      X : Rvp (1 .. P);
      Y : Ivq (1 .. Q);
      Z : Bvr (1 .. R);
   end record;
   
   generic
   with function F (V : vi) return Long_Float;
   with function G (V : vi; M : Natural) return Long_Float;
   procedure EA (P1, Q1, R1, M1, Popsize : Natural);

end paradigm;

package body paradigm is

   procedure EA (P1,Q1,R1,M1,Popsize : Natural) is
      V : vi := new Individual (P=>P1,Q=>Q1,R=>R1);
      type population is array (1 .. Popsize) of vi;
      Fr, Gr : Long_Float;
   begin
      V.Y(1) := 1;
      Fr := F(V);
      Gr := G(V,M1);
   end EA;

end paradigm;

with paradigm;    use paradigm;
with Ada.Text_IO; use Ada.Text_IO;

procedure paratest is
   P2, Q2, R2, Popsize2, M2 : Natural;
   function F (V : vi) return Long_Float is
      Flf : Long_Float := 1.0;
   begin
      Put_Line ("in F");
      return Flf;
   end F;
   function G (V : vi; M : Natural) return Long_Float is
      Glf : Long_Float := 0.0;
   begin
      Put_Line ("in G");
      return Glf;
   end G;
   procedure EA1 is new EA (F, G);
begin
   P2       := 0;
   Q2       := 1;
   R2       := 0;
   Popsize2 := 20;
   M2       := 1;
   EA1 (P2, Q2, R2, M2, Popsize2);
end paratest;

Hopefully it will work. Any comments ?

On Sunday, June 22, 2014 1:34:09 PM UTC+2, montgrimpulo wrote:
> Here is another try to describe my problem. 
> 
> 
> 
> I want to conduct a genetic search-program. There is a function F (the objective function), 
> 
> and a function G (the constraint function) which I want to define only at runtime. The search-program handles individuals within a population. The size of an individual as well as the size of the population is dynamic and is known at runtime. 
> 
> 
> 
> There is a proposed solution to define (in search.ads)
> 
> 
> 
> ...
> 
> generic 
> 
> with function F (V : Individual) return Float; 
> 
> with function G (V : Individual; M : Positive) return Float; 
> 
> procedure Search (V : Individual); 
> 
> 
> 
> which seems to be an appropriate solution for that part. 
> 
> 
> 
> The search program handles individuals from a population. 
> 
> 
> 
> type x_array is array (positive range <>) of Float; 
> 
> type y_array is array (positive range <>) of Integer; 
> 
> type z_array is array (positive range <>) of Boolean; 
> 
> 
> 
> type Individual (P, Q, R) is record 
> 
> X : x_array (0..P); 
> 
> Y : y_array (0..Q); 
> 
> Z : z_array (0..R); 
> 
> end record; 
> 
> 
> 
> P,Q and R are only known at runtime. 
> 
> 
> 
> A population has a number (Popsize) of individuals (definition see above), which is also only known at runtime. 
> 
> 
> 
> Due to some reading, I learned that dynamic arrays in Ada 
> 
> 
> 
> - can be declared in blocks, meaning no inheritance 
> 
> - by limits passed as parameters in subprograms 
> 
> - by use of linked lists 
> 
> - by use of containers ? 
> 
> - by use of discriminated records ? 
> 
> 
> 
> Using  the proposed record type from above, 
> 
> my search-program may look like: (in search.adb)
> 
> 
> 
> procedure Search (V : Individual) is 
> 
> 
> 
> P : Natural := V.P; 
> 
> Q : Natural := V.Q; 
> 
> R : Natural := V.R; 
> 
> Vi : Individual := V; 
> 
> 
> 
> 
> ... 
> 
> begin 
> 
> -- fill Vi with distinct values and put it into an (array?, container ?, List ?, whatever) 
> 
> -- to get a population with size Popsize
> 
> -- work on all individuals within that population 
> 
> ... 
> 
> end Search; 
> 
> 
> 
> What I still need is a definition for the population (a collection of Individuals) of size Popsize, which is only defined at runtime.
> 
> 
> 
> I want to use my search program for a specific objective- and for a specific constraint-function with a certain size for an individual and a certain size of population. If I do not find a solution then I want to change some elements, eg. size of the population, size of an individual, or to try modified objective- or constraint-functions. 
> 
> 
> 
> After I have found a solution or not, I want to use the same search program with a new and different objective- and a new and different constraint function with a different size of an individual and  different population size.

      parent reply	other threads:[~2014-06-30 13:23 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-22 11:34 Function definitions - with clarification montgrimpulo
2014-06-22 12:04 ` Simon Clubley
2014-06-22 14:25 ` montgrimpulo
2014-06-22 15:30 ` Georg Bauhaus
2014-06-22 17:29 ` montgrimpulo
2014-06-22 17:45 ` Shark8
2014-06-22 18:03   ` montgrimpulo
2014-06-22 18:45     ` Simon Clubley
2014-06-22 19:28       ` montgrimpulo
2014-06-22 21:04         ` Simon Wright
2014-06-22 21:17       ` Jeffrey Carter
2014-06-22 19:55     ` Shark8
2014-06-23 16:26 ` Adam Beneschan
2014-06-29 15:31 ` cotswold
2014-06-29 19:20 ` montgrimpulo
2014-06-30  9:29   ` G.B.
2014-06-30 17:55     ` Shark8
2014-07-01  8:58       ` Georg Bauhaus
2014-07-04  6:45         ` J-P. Rosen
2014-06-30 13:23 ` montgrimpulo [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox