 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Thu Mar 29, 2007 6:19 am Post subject: how to solve this problem(hard) |
|
|
I am trying to model how the population reproduce.
I have a structure representing each individual. At each step when the
population reproduce.
Each invidual gives rise to their offspring/s. I want to keep track
of the pedigree relationship between the individuals.
if the structure have a pointer pointing to its ancestor, since each
individual can give rise to a huge number of offsprings(which cannot
know in advance). what is the efficient way of housekeeping?
(ancestors who doesn't have descendents in the current population, I
don't care about them anymore.....)
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
WillerZ Guest
|
Posted: Mon Apr 16, 2007 8:17 pm Post subject: Re: how to solve this problem(hard) |
|
|
queryou (AT) hotmail (DOT) com wrote:
| Quote: | I am trying to model how the population reproduce.
I have a structure representing each individual. At each step when the
population reproduce.
Each invidual gives rise to their offspring/s. I want to keep track
of the pedigree relationship between the individuals.
if the structure have a pointer pointing to its ancestor, since each
individual can give rise to a huge number of offsprings(which cannot
know in advance). what is the efficient way of housekeeping?
(ancestors who doesn't have descendents in the current population, I
don't care about them anymore.....)
|
Simple reference counting should do it.
Stick an integer count into your structure; increment it for each child
produced. When deallocating any structure, decrement the use count of
its parents. If a use count hits zero at any point, deallocate that
instance of the structure.
How is that hard?
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Gordon Burditt Guest
|
Posted: Mon Apr 16, 2007 8:18 pm Post subject: Re: how to solve this problem(hard) |
|
|
| Quote: | I am trying to model how the population reproduce.
I have a structure representing each individual. At each step when the
population reproduce.
Each invidual gives rise to their offspring/s. I want to keep track
of the pedigree relationship between the individuals.
if the structure have a pointer pointing to its ancestor, since each
|
What are you modelling populations *OF*? The higher species reproduce
by sexual reproduction and have a mother AND a father.
| Quote: | individual can give rise to a huge number of offsprings(which cannot
know in advance). what is the efficient way of housekeeping?
|
If you only need the pedigree given a child, two pointers to parents
are sufficient. You can go back more generations from there.
| Quote: | (ancestors who doesn't have descendents in the current population, I
don't care about them anymore.....)
|
Data structures sometimes used in genealogy:
Individual: contains information about a particular person (birth
date, name, death date, burial location, etc.) and an id number.
Family: contains information about a union of two people, which
might produce children. (marriage date and place, divorce date,
etc. and an id number) A union doesn't have to be official and in
Hollywood might last less than 15 minutes.
Cross-references between individuals and families work like this.
The reference might be a pointer to a structure (better for a C
in-memory database) or a record number (better for a SQL on-disk
database). You can also translate a record number to a pointer to
a structure with an array such that foo[n] contains a pointer to
the structure for record n.
An individual record refers to a parent family, and a list of spouse
families.
A family record refers to two parent individuals, which used to be
called "husband" and "wife", and a list of child individuals produced
from the union. This model does not fit well the "extended family"
consisting of biological father, his gay lover, biological mother,
her lesbian lover, adopted father, his gay lover, adopted mother,
and her lesbian lover.
These are like double-linked lists, and a great mess can be made
if the references in both directions aren't consistent. It is
possible to reconstruct the "list of ..." references from the others
going in the other direction. I'd probably implement (for C) a
"list of ..." as a count and a pointer to an array of pointers to
structures or as a count and a pointer to an array of record numbers.
The count indicates how many entries in the list are in use. The
arrays need to be allocated with malloc()/realloc(), since there
are no sensible bounds on the number of individuals or families in
a list.
Any reference may be nil: There are people who aren't married (yet
or ever), people whose parents aren't known, and families that have
no children (yet or ever).
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Thad Smith Guest
|
Posted: Mon Apr 16, 2007 8:18 pm Post subject: Re: how to solve this problem(hard) |
|
|
queryou (AT) hotmail (DOT) com wrote:
| Quote: | I am trying to model how the population reproduce.
I have a structure representing each individual. At each step when the
population reproduce.
Each invidual gives rise to their offspring/s. I want to keep track
of the pedigree relationship between the individuals.
if the structure have a pointer pointing to its ancestor, since each
individual can give rise to a huge number of offsprings(which cannot
know in advance). what is the efficient way of housekeeping?
|
What are the duties of housekeeping that you wish to make efficient?
Are you concerned with memory efficiency or processing efficiency? Why?
What have you considered?
--
Thad
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|