-
Notifications
You must be signed in to change notification settings - Fork 1
/
analysis.hpp
85 lines (69 loc) · 2.01 KB
/
analysis.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include "common.hpp"
#include "util.hpp"
#include "pu.hpp"
#include "zones.hpp"
#include "reserve.hpp"
#include <omp.h>
/*
Deals with calculation of any output analysis of solutions, reserves and other.
*/
namespace marzone {
using namespace std;
class Analysis {
public:
Analysis() {
}
void initSumSolution(int puno, int zoneCount) {
// initialize analysis objects.
sumSoln.resize(puno, 0);
zoneSumSoln.resize(puno*zoneCount, 0);
// Init locks
omp_init_lock(&sumLock);
}
// Writes both sumSoln and zoneSumSoln
void WriteAllSumSoln(string filename, Pu& pu, Zones& zones, int imode) {
ofstream myfile;
myfile.open(filename); /* Imode = 1, REST output, Imode = 2, Arcview output */
string d = imode > 1 ? "," : " ";
if (imode > 1)
{
myfile << "\"planning unit\",\"number\"";
for (int j = 0; j < zones.zoneCount; j++)
myfile << ",\"" << zones.IndexToName(j) << "\"";
myfile << "\n";
}
// Pu must be printed in reverse order for compatibility with zonae cogito
for (int i = pu.puno-1; i >= 0; i--)
{
if (imode > 1)
{
myfile << pu.puList[i].id << d << sumSoln[i];
for (int j = 0; j < zones.zoneCount; j++)
myfile << d << zoneSumSoln[pu.puno * j + i];
myfile << "\n";
}
}
myfile.close();
}
// Should be threadsafe. Applies the solution in Reserve to sums
void ApplyReserveToSumSoln(Reserve& r) {
int iZoneSumSolnIndex;
int rSize = r.solution.size();
omp_set_lock(&sumLock);
for (int i = 0; i < rSize; i++) {
if (r.solution[i] >= 0) {
sumSoln[i] ++;
iZoneSumSolnIndex = rSize * (r.solution[i]) + i;
zoneSumSoln[iZoneSumSolnIndex]++;
}
}
omp_unset_lock(&sumLock);
}
private:
vector<int> sumSoln; // size puno
vector<int> zoneSumSoln; //size puno*zoneCount
// thread safety
omp_lock_t sumLock;
};
} // namespace marzone