BioNrd has asked for the wisdom of the Perl Monks concerning the following question:
i.e. MotherA -> ChildA -> genes within childA; MotherA -> ChildB -> genes within childB; MotherB -> ChildB -> genes within childB
I have a list of mothers and fathers that I am randomly combining by saying: 30 mothers (external) have "n" children (internal) from "n" fathers. The children then get n genes from father and n genes from mother (super internal).
I have a code that works exactly as I would like it to. However, the problem is when the number of mothers, and/or number of offspring per mother (think plants), and/or the number of genes I am tracking gets exceedingly large the run time of the script gets horrendously long. Here is a mock up of the code:
Having gotten this far on my own, I am not sure how to avoid/do away with/restructure/alter/fix this nested loop structure. Is there any way to increase run time by changing the way I am thinking about loops?use strict; use warnings; my $num_of_external = 30; #num moms my @num_of_internal = (30, 40, 20, 30, 40, 30, 40, 20, 30, 40, 30, 40, 20, 30, 40, 30, 40, 20, 30, 40, 30, 40, 20, 30, 40, 30, 40, 20, 30, 40); #num offspring per mom my $num_of_super_internal = 10; #num genes tracked #during shuffle 5 come from dad 5 come from mom for (1 .. $num_of_external) { my $internal = shift @num_of_internal; #additional things here. #i.e. select mother from possible pool for (1 .. $internal) { #select father for each offspring #additional things here. for (1 .. $num_of_super_internal) { #additional things here. #select genes and shuffle around between mom and dad. } } }
Anything you monks can offer would be greatly appreciated by my overheating processor.
Bio
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Nested loops of doom
by dragonchild (Archbishop) on Apr 07, 2008 at 20:41 UTC | |
|
Re: Nested loops of doom
by samtregar (Abbot) on Apr 07, 2008 at 20:29 UTC | |
|
Re: Nested loops of doom
by BrowserUk (Patriarch) on Apr 07, 2008 at 22:54 UTC | |
|
Re: Nested loops of doom
by BioNrd (Monk) on Apr 08, 2008 at 14:08 UTC |