Merge lp:~philsf/mmrrsim/fix-lp-1260122 into lp:mmrrsim

Proposed by Felipe Figueiredo
Status: Merged
Merged at revision: 236
Proposed branch: lp:~philsf/mmrrsim/fix-lp-1260122
Merge into: lp:mmrrsim
Diff against target: 115 lines (+47/-41)
2 files modified
ChangeLog (+4/-0)
lib/MMRRSim.pm (+43/-41)
To merge this branch: bzr merge lp:~philsf/mmrrsim/fix-lp-1260122
Reviewer Review Type Date Requested Status
Felipe Figueiredo Pending
Review via email: mp+198856@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2013-12-11 23:32:10 +0000
3+++ ChangeLog 2013-12-13 01:30:33 +0000
4@@ -1,3 +1,7 @@
5+2013-12-12 Felipe Figueiredo <philsf79@gmail.com>
6+
7+ * lib/MMRRSim.pm (create_population): Fix bug LP:1260122.
8+
9 2013-12-11 Felipe Figueiredo <philsf79@gmail.com>
10
11 * lib/MMRRSim/GridCell.pm: Grid is now a rectangle instead of a
12
13=== modified file 'lib/MMRRSim.pm'
14--- lib/MMRRSim.pm 2013-12-11 23:33:49 +0000
15+++ lib/MMRRSim.pm 2013-12-13 01:30:33 +0000
16@@ -130,56 +130,58 @@
17 ## Determine size of population
18 my $pop_size = $self->pop_size_u + $self->pop_size_m;
19
20+
21+## Retrieve individual attributes from config object and store them in
22+## single a hash
23+ my %individual_attributes;
24+ for my $attr ( qw( longevity survival autonomy flight_mode act_prop delta_flight ) ) {
25+ my $att_value = $self->config->params->{$attr};
26+ if ($att_value) {
27+ $individual_attributes{$attr} = $att_value;
28+ }
29+ }
30+
31+## Loops for the whold population, and use $_ as the individual name
32 for (1..$pop_size) {
33-## Set initial coordinates for everyone (if there's a release point
34-## for marked individuals, its coords will overwrite this)
35+
36+## Set initial random coordinates for every individual. If there's a
37+## release point for marked individuals, its coords will overwrite
38+## this
39 my @coordinates = $self->random_coordinates();
40-
41-## Create random Activity Center
42+ $individual_attributes{coordinates} = \@coordinates;
43+## Set random Activity Center
44 my @act_center = $self->random_coordinates();
45-
46-## FIXME: the following code was made with the pork programming
47-## method. Try to make both cases in one block
48- if ($_ <= $self->pop_size_u ) {
49-##Creates unmarked population
50- $population{$_} = MMRRSim::Mosquito->new('name' => $_,
51- coordinates => \@coordinates,
52- act_center => \@act_center,
53- mark => 0,
54- survival => 1,
55- );
56-## Set parameters from config file, if applicable
57- for my $attr ( qw( longevity autonomy flight_mode act_prop delta_flight ) ) {
58- my $att_value = $self->config->params->{$attr};
59- if ($att_value) {
60- $population{$_}->$attr($att_value);
61- }
62- }
63-## FIXME: be serious and don't copy/paste the same block in two places
64- } else {
65-## Set initial coordinates
66+ $individual_attributes{act_center} = \@act_center;
67+
68+ if ($_ <= $self->pop_size_u ) { # unmarked individuals
69+
70+## Sets unmarked individuals attributes
71+ $individual_attributes{mark} = 0;
72+ $individual_attributes{survival}=1;
73+
74+ } else { # marked individuals
75+
76+## Sets marked individuals attributes
77+ $individual_attributes{mark} = 1;
78+
79+## Sets initial coordinates, if a release point is given
80 if ( @{$self->release_p}) {
81 @coordinates = @{$self->release_p};
82 }
83+ $individual_attributes{coordinates} = \@coordinates;
84+
85+## Sets activity center, if at least one is given
86 if ( @{$self->a_centers}) {
87- @act_center = $self->pick_activity_centers();
88- }
89-
90-##Creates marked population
91+ @act_center = $self->pick_activity_centers();
92+ }
93+ $individual_attributes{act_center} = \@act_center;
94+
95+ }
96+
97+## Create the individual
98 $population{$_} = MMRRSim::Mosquito->new('name' => $_,
99- coordinates => \@coordinates,
100- act_center => \@act_center,
101- mark => 1,
102+ %individual_attributes,
103 );
104-## Set parameters from config file, if applicable
105- for my $attr ( qw( longevity survival autonomy flight_mode act_prop delta_flight ) ) {
106- my $att_value = $self->config->params->{$attr};
107- if ($att_value) {
108- $population{$_}->$attr($att_value);
109- }
110- }
111-## FIXME: be serious and don't copy/paste the same block in two places
112- }
113 }
114
115 ## Set last seen name to pop size, to make sure the next mosquito

Subscribers

People subscribed via source and target branches