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.JumpOffParameters;
20  
21  /**
22   * Handles calculations for the jump-off sub-populations.
23   * 
24   * Created on July 16, 2006
25   * 
26   * @author Christina Bohk
27   * @author Roland Ewald
28   * 
29   */
30  public class JumpOffPopulation extends
31      AbstractPopulation<JumpOffParameters, BasicResults> {
32  
33    @Override
34    public BasicResults calculatePopulation(String subPopName, int generation,
35        JumpOffParameters parameters) {
36  
37      BasicResults results = new BasicResults(subPopName, generation,
38          parameters.getNumOfYears(), parameters.getMaxAge());
39  
40      // Storing start year populations to results
41      results.getEndXm().assignColumn(0, parameters.getPEndSYm().toArray()[0]);
42      results.getEndXf().assignColumn(0, parameters.getPEndSYf().toArray()[0]);
43  
44      calculateSurvivalProbabilities(parameters, results);
45  
46      for (int year = 1; year < parameters.getNumOfYears(); year++) {
47  
48        // Mean female population
49        calculateByMultMin1(1, parameters.getMaxAge(), year, results.getMeanXf(),
50            results.getEndXf(), results.getP2f());
51  
52        // Get number of children born in current year
53        double numOfChilds = getNumOfChilds(results.getMeanXf(),
54            parameters.getFertX(), year);
55  
56        calculateRestOfMeanPopulation(results.getMeanXf(), results.getEndXf(),
57            results.getP2f(), parameters.getSurviveProbO100f(),
58            parameters.getFemalePropLiveBirth(), year, numOfChilds,
59            parameters.getMaxAge());
60  
61        // Female end population
62        calculateByMult(0, parameters.getMaxAge(), year, results.getEndXf(),
63            results.getMeanXf(), results.getP1f());
64  
65        results.getEndXf().setQuick(
66            parameters.getMaxAge(),
67            year,
68            results.getMeanXf().get(parameters.getMaxAge(), year)
69                * parameters.getSurviveProbO100f().get(year, 0));
70  
71        // Mean male population
72        calculateByMultMin1(1, parameters.getMaxAge(), year, results.getMeanXm(),
73            results.getEndXm(), results.getP2m());
74  
75        calculateRestOfMeanPopulation(results.getMeanXm(), results.getEndXm(),
76            results.getP2m(), parameters.getSurviveProbO100m(),
77            parameters.getMalePropLiveBirth(), year, numOfChilds,
78            parameters.getMaxAge());
79  
80        // Male end population
81        calculateByMult(0, parameters.getMaxAge(), year, results.getEndXm(),
82            results.getMeanXm(), results.getP1m());
83  
84        results.getEndXm().setQuick(
85            parameters.getMaxAge(),
86            year,
87            results.getMeanXm().get(parameters.getMaxAge(), year)
88                * parameters.getSurviveProbO100m().get(year, 0));
89  
90      }
91  
92      return results;
93    }
94  }