View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
3    *  
4    * Licensed under the Apache License, Version 2.0 (the "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at 
7    *  
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *  
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License. 
15   */
16  package p3j.simulation.calculation.deterministic;
17  
18  import p3j.experiment.results.BasicResults;
19  import p3j.simulation.calculation.deterministic.parameters.NativeParameters;
20  
21  /**
22   * Handles calculations for the native population.
23   * 
24   * Created on July 16, 2006
25   * 
26   * @author Christina Bohk
27   * @author Roland Ewald
28   * 
29   */
30  public class NativePopulation extends
31      AbstractPopulation<NativeParameters, BasicResults> {
32  
33    @Override
34    public BasicResults calculatePopulation(NativeParameters parameters) {
35  
36      BasicResults results = new BasicResults(parameters.getNumOfYears(),
37          parameters.getMaxAge());
38  
39      // Storing start year populations to results
40      results.getEndXm().assignColumn(0, parameters.getPEndSYm().toArray()[0]);
41      results.getEndXf().assignColumn(0, parameters.getPEndSYf().toArray()[0]);
42  
43      calculateSurvivalProbabilities(parameters, results);
44  
45      for (int year = 1; year < parameters.getNumOfYears(); year++) {
46  
47        // Mean female population
48        calculateByMultMin1(1, parameters.getMaxAge(), year, results.getMeanXf(),
49            results.getEndXf(), results.getP2f());
50  
51        // Get number of children born in current year
52        double numOfChilds = getNumOfChilds(results.getMeanXf(), parameters
53            .getFertX(), year);
54  
55        calculateRestOfMeanPopulation(results.getMeanXf(), results.getEndXf(),
56            results.getP2f(), parameters.getSurviveProbO100f(), parameters
57                .getFemalePropLiveBirth(), year, numOfChilds, parameters
58                .getMaxAge());
59  
60        // Female end population
61        calculateByMult(0, parameters.getMaxAge(), year, results.getEndXf(),
62            results.getMeanXf(), results.getP1f());
63  
64        results.getEndXf().setQuick(
65            parameters.getMaxAge(),
66            year,
67            results.getMeanXf().get(parameters.getMaxAge(), year)
68                * parameters.getSurviveProbO100f().get(year, 0));
69  
70        // Mean male population
71        calculateByMultMin1(1, parameters.getMaxAge(), year, results.getMeanXm(),
72            results.getEndXm(), results.getP2m());
73  
74        calculateRestOfMeanPopulation(results.getMeanXm(), results.getEndXm(),
75            results.getP2m(), parameters.getSurviveProbO100m(), parameters
76                .getMalePropLiveBirth(), year, numOfChilds, parameters
77                .getMaxAge());
78  
79        // Male end population
80        calculateByMult(0, parameters.getMaxAge(), year, results.getEndXm(),
81            results.getMeanXm(), results.getP1m());
82  
83        results.getEndXm().setQuick(
84            parameters.getMaxAge(),
85            year,
86            results.getMeanXm().get(parameters.getMaxAge(), year)
87                * parameters.getSurviveProbO100m().get(year, 0));
88  
89      }
90  
91      return results;
92    }
93  }