1 : |
agomez |
1 |
#include "intvector.h" |
2 : |
|
|
#include "popinfomatrix.h" |
3 : |
|
|
#include "popinfoindexvector.h" |
4 : |
|
|
#include "agebandmatrix.h" |
5 : |
|
|
#include "mathfunc.h" |
6 : |
|
|
|
7 : |
|
|
AgeBandMatrix::AgeBandMatrix(const AgeBandMatrix& initial)
|
8 : |
|
|
: minage(initial.minAge()), nrow(initial.Nrow()) {
|
9 : |
|
|
|
10 : |
|
|
int i;
|
11 : |
|
|
if (nrow > 0) {
|
12 : |
|
|
v = new PopInfoIndexVector*[nrow];
|
13 : |
|
|
for (i = 0; i < nrow; i++)
|
14 : |
|
|
v[i] = new PopInfoIndexVector(initial[i + minage]);
|
15 : |
|
|
} else
|
16 : |
|
|
v = 0;
|
17 : |
|
|
}
|
18 : |
|
|
|
19 : |
|
|
AgeBandMatrix::AgeBandMatrix(int age, const IntVector& minl,
|
20 : |
|
|
const IntVector& size) : minage(age), nrow(size.Size()) {
|
21 : |
|
|
|
22 : |
|
|
int i;
|
23 : |
|
|
if (nrow > 0) {
|
24 : |
|
|
PopInfo nullpop;
|
25 : |
|
|
v = new PopInfoIndexVector*[nrow];
|
26 : |
|
|
for (i = 0; i < nrow; i++)
|
27 : |
|
|
v[i] = new PopInfoIndexVector(size[i], minl[i], nullpop);
|
28 : |
|
|
} else
|
29 : |
|
|
v = 0;
|
30 : |
|
|
}
|
31 : |
|
|
|
32 : |
|
|
AgeBandMatrix::AgeBandMatrix(int age, const PopInfoMatrix& initial, int minl)
|
33 : |
|
|
: minage(age), nrow(initial.Nrow()) {
|
34 : |
|
|
|
35 : |
|
|
if (nrow > 0) {
|
36 : |
|
|
int i, j, lower, upper;
|
37 : |
|
|
v = new PopInfoIndexVector*[nrow];
|
38 : |
|
|
for (i = 0; i < nrow; i++) {
|
39 : |
|
|
lower = 0;
|
40 : |
|
|
upper = initial.Ncol(i) - 1;
|
41 : |
|
|
while (isZero(initial[i][lower].N) && (lower < upper))
|
42 : |
|
|
lower++;
|
43 : |
|
|
while (isZero(initial[i][upper].N) && (upper > lower))
|
44 : |
|
|
upper--;
|
45 : |
|
|
v[i] = new PopInfoIndexVector(upper - lower + 1, lower + minl);
|
46 : |
|
|
for (j = lower; j <= upper; j++)
|
47 : |
|
|
(*v[i])[j + minl] = initial[i][j];
|
48 : |
|
|
}
|
49 : |
|
|
} else
|
50 : |
|
|
v = 0;
|
51 : |
|
|
}
|
52 : |
|
|
|
53 : |
|
|
AgeBandMatrix::AgeBandMatrix(int age, const PopInfoIndexVector& initial)
|
54 : |
|
|
: minage(age), nrow(1) {
|
55 : |
|
|
|
56 : |
|
|
v = new PopInfoIndexVector*[nrow];
|
57 : |
|
|
v[0] = new PopInfoIndexVector(initial);
|
58 : |
|
|
}
|
59 : |
|
|
|
60 : |
|
|
AgeBandMatrix::~AgeBandMatrix() {
|
61 : |
|
|
int i;
|
62 : |
|
|
if (v != 0) {
|
63 : |
|
|
for (i = 0; i < nrow; i++)
|
64 : |
|
|
delete v[i];
|
65 : |
|
|
delete[] v;
|
66 : |
|
|
v = 0;
|
67 : |
|
|
}
|
68 : |
|
|
}
|