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.58.219.105 with SMTP id pn9mr22548302vec.30.1404134616078; Mon, 30 Jun 2014 06:23:36 -0700 (PDT) X-Received: by 10.140.109.199 with SMTP id l65mr2326qgf.32.1404134616027; Mon, 30 Jun 2014 06:23:36 -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!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!w8no3873006qac.0!news-out.google.com!a8ni1qaq.1!nntp.google.com!w8no3873003qac.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 30 Jun 2014 06:23:35 -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: <01fb15d2-d063-44e6-9ebc-aa3b90a3c7a0@googlegroups.com> Subject: Re: Function definitions - with clarification From: montgrimpulo Injection-Date: Mon, 30 Jun 2014 13:23:36 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 6308 X-Received-Body-CRC: 4293040960 Xref: news.eternal-september.org comp.lang.ada:20646 Date: 2014-06-30T06:23:35-07:00 List-Id: 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; =20 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 :=3D new Individual (P=3D>P1,Q=3D>Q1,R=3D>R1); type population is array (1 .. Popsize) of vi; Fr, Gr : Long_Float; begin V.Y(1) :=3D 1; Fr :=3D F(V); Gr :=3D 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 :=3D 1.0; begin Put_Line ("in F"); return Flf; end F; function G (V : vi; M : Natural) return Long_Float is Glf : Long_Float :=3D 0.0; begin Put_Line ("in G"); return Glf; end G; procedure EA1 is new EA (F, G); begin P2 :=3D 0; Q2 :=3D 1; R2 :=3D 0; Popsize2 :=3D 20; M2 :=3D 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.=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 >=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.