comp.lang.ada
 help / color / mirror / Atom feed
From: montgrimpulo <aghte@hotlinemail.com>
Subject: Re: Function definitions
Date: Sat, 21 Jun 2014 05:27:06 -0700 (PDT)
Date: 2014-06-21T05:27:06-07:00	[thread overview]
Message-ID: <2aa95b6a-951f-4e1d-adbb-612521fdbe9e@googlegroups.com> (raw)
In-Reply-To: <610b9d5b-a9a5-464d-9de3-b2f754f58cff@googlegroups.com>

Here is another try to describe my problem.

I want to conduct a genetic optimisation-program. There is a function F (the objective function),
and a function G (the constraint function) which I can define only at runtime. The program handles
individuals within a population. The size of an individual as well as the size of the population are dynamic and only known at runtime. 

The proposed solution to define

generic
with function F (V : Individual) return Float;
with function G (V : Individual; M : Positive);
procedure Search (V : Individual)

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.

Furthermore a population has a number of individuals (Popsize), 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 ?

looking at the proposed record from above:
Would it be OK to define

procedure Search (V : Individual) is
P : Natural := V.P;
Q : Natural := V.Q;
R : Natural := V.R;
Vi : Individual := V;

type population is array (1 .. Popsize) of Individual; -- unconstrained element in array declaration

...
begin
-- fill Vi with distinct values and put it into an array?, container ?, List ?, whatever
-- work on all Vi's within that population
...
end Search;

What I still need is a definition for the population (a collection of Individuals), which size is determined at runtime.




  parent reply	other threads:[~2014-06-21 12:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-20 15:18 Function definitions montgrimpulo
2014-06-20 15:44 ` Adam Beneschan
2014-06-20 16:22 ` montgrimpulo
2014-06-20 16:43   ` Adam Beneschan
2014-06-20 16:52     ` Simon Clubley
2014-06-20 17:05       ` Adam Beneschan
2014-06-20 16:43   ` Simon Clubley
2014-06-22  6:59   ` Shark8
2014-06-20 17:39 ` montgrimpulo
2014-06-20 18:19   ` Adam Beneschan
2014-06-20 18:20     ` Adam Beneschan
2014-06-21 20:56     ` Stephen Leake
2014-06-22 12:27     ` Simon Clubley
2014-06-20 20:39   ` Robert A Duff
2014-06-21 12:27 ` montgrimpulo [this message]
2014-06-21 12:38   ` Simon Clubley
2014-06-21 17:57   ` Jeffrey Carter
2014-06-21 13:40 ` montgrimpulo
replies disabled

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