From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.50.148.1 with SMTP id to1mr13714059igb.0.1404069648366; Sun, 29 Jun 2014 12:20:48 -0700 (PDT) X-Received: by 10.140.41.114 with SMTP id y105mr845qgy.11.1404069648330; Sun, 29 Jun 2014 12:20:48 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!hn18no19137686igb.0!news-out.google.com!a8ni0qaq.1!nntp.google.com!i13no3310323qae.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 29 Jun 2014 12:20:48 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=109.233.148.43; posting-account=ZoAlyAoAAACOOtSiXyaM8n3y8T4ScfeH NNTP-Posting-Host: 109.233.148.43 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Function definitions - with clarification From: montgrimpulo Injection-Date: Sun, 29 Jun 2014 19:20:48 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:20642 Date: 2014-06-29T12:20:48-07:00 List-Id: 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 :=3D new Individual (P=3D>P1,Q=3D>Q1,R=3D>R1); type population is array (1 .. Popsize) of vi;=20 begin V.Y(1) :=3D 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.=20 >=20 >=20 >=20 > I want to conduct a genetic search-program. There is a function F (the ob= jective function),=20 >=20 > and a function G (the constraint function) which I want to define only at= runtime. The search-program handles individuals within a population. The s= ize of an individual as well as the size of the population is dynamic and i= s known at runtime.=20 >=20 >=20 >=20 > There is a proposed solution to define (in search.ads) >=20 >=20 >=20 > ... >=20 > generic=20 >=20 > with function F (V : Individual) return Float;=20 >=20 > with function G (V : Individual; M : Positive) return Float;=20 >=20 > procedure Search (V : Individual);=20 >=20 >=20 >=20 > which seems to be an appropriate solution for that part.=20 >=20 >=20 >=20 > The search program handles individuals from a population.=20 >=20 >=20 >=20 > type x_array is array (positive range <>) of Float;=20 >=20 > type y_array is array (positive range <>) of Integer;=20 >=20 > type z_array is array (positive range <>) of Boolean;=20 >=20 >=20 >=20 > type Individual (P, Q, R) is record=20 >=20 > X : x_array (0..P);=20 >=20 > Y : y_array (0..Q);=20 >=20 > Z : z_array (0..R);=20 >=20 > end record;=20 >=20 >=20 >=20 > P,Q and R are only known at runtime.=20 >=20 >=20 >=20 > A population has a number (Popsize) of individuals (definition see above)= , which is also only known at runtime.=20 >=20 >=20 >=20 > Due to some reading, I learned that dynamic arrays in Ada=20 >=20 >=20 >=20 > - can be declared in blocks, meaning no inheritance=20 >=20 > - by limits passed as parameters in subprograms=20 >=20 > - by use of linked lists=20 >=20 > - by use of containers ?=20 >=20 > - by use of discriminated records ?=20 >=20 >=20 >=20 > Using the proposed record type from above,=20 >=20 > my search-program may look like: (in search.adb) >=20 >=20 >=20 > procedure Search (V : Individual) is=20 >=20 >=20 >=20 > P : Natural :=3D V.P;=20 >=20 > Q : Natural :=3D V.Q;=20 >=20 > R : Natural :=3D V.R;=20 >=20 > Vi : Individual :=3D V;=20 >=20 >=20 >=20 >=20 >=20 > -- type population is array (1 .. Popsize) of Individual;=20 >=20 > -- gives: unconstrained element in array declaration=20 >=20 >=20 >=20 > ...=20 >=20 > begin=20 >=20 > -- fill Vi with distinct values and put it into an (array?, container ?, = List ?, whatever)=20 >=20 > -- to get a population with size Popsize >=20 > -- work on all individuals within that population=20 >=20 > ...=20 >=20 > end Search;=20 >=20 >=20 >=20 > What I still need is a definition for the population (a collection of Ind= ividuals) of size Popsize, which is only defined at runtime. >=20 >=20 >=20 > I want to use my search program for a specific objective- and for a speci= fic 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 mod= ified objective- or constraint-functions.=20 >=20 >=20 >=20 > After I have found a solution or not, I want to use the same search progr= am with a new and different objective- and a new and different constraint f= unction with a different size of an individual and different population si= ze.