From: montgrimpulo <aghte@hotlinemail.com>
Subject: Re: Function definitions - with clarification
Date: Sun, 29 Jun 2014 12:20:48 -0700 (PDT)
Date: 2014-06-29T12:20:48-07:00 [thread overview]
Message-ID: <a87900f0-5afa-47a4-93e2-83222fc667e0@googlegroups.com> (raw)
In-Reply-To: <f12eba4c-2757-4496-861b-101cb7e355d6@googlegroups.com>
I've tried to figure out how my problem could be programmed
using generic functions and access types. Any comments ?
package paradigm is
type 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 : Individual) return Long_Float;
with function G (V : Individual; M : Natural) return Long_Float;
procedure EA (P1, Q1, R1, Popsize : Natural);
end paradigm;
package body paradigm is
procedure EA (P1,Q1,R1,Popsize : Natural) is
type vi is access Individual;
V : vi := new Individual (P=>P1,Q=>Q1,R=>R1);
type population is array (1 .. Popsize) of vi;
begin
V.Y(1) := 1;
end EA;
end paradigm;
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;
>
>
>
>
>
> -- type population is array (1 .. Popsize) of Individual;
>
> -- gives: unconstrained element in array declaration
>
>
>
> ...
>
> 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.
next prev parent reply other threads:[~2014-06-29 19:20 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 [this message]
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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox