-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSessionOrganizer.cpp
170 lines (154 loc) · 4.99 KB
/
SessionOrganizer.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* File: SessionOrganizer.cpp
* Author: Kapil Thakkar
*
*/
#include "SessionOrganizer.h"
#include "Util.h"
#include "HillClimb.h"
#include <vector>
SessionOrganizer::SessionOrganizer()
{
parallelTracks = 0;
papersInSession = 0;
sessionsInTrack = 0;
processingTimeInMinutes = 0;
tradeoffCoefficient = 1.0;
}
SessionOrganizer::SessionOrganizer(string filename)
{
readInInputFile(filename);
conference = new Conference(parallelTracks, sessionsInTrack, papersInSession);
}
void SessionOrganizer::organizePapers()
{
const int ANSWER_TO_THE_UNIVERSE = 43;
HillClimb hill_climb(distanceMatrix, parallelTracks, sessionsInTrack, papersInSession, tradeoffCoefficient);
auto state = hill_climb.hill_climb(true, processingTimeInMinutes * 0.95, ANSWER_TO_THE_UNIVERSE);
int paperCounter = 0;
for (int i = 0; i < conference->getSessionsInTrack(); i++)
{
for (int j = 0; j < conference->getParallelTracks(); j++)
{
for (int k = 0; k < conference->getPapersInSession(); k++)
{
conference->setPaper(j, i, k, state[paperCounter]);
paperCounter++;
}
}
}
return;
}
void SessionOrganizer::readInInputFile(string filename)
{
vector<string> lines;
string line;
ifstream myfile(filename.c_str());
if (myfile.is_open())
{
while (getline(myfile, line))
{
//cout<<"Line read:"<<line<<endl;
lines.push_back(line);
}
myfile.close();
}
else
{
cout << "Unable to open input file";
exit(0);
}
if (6 > lines.size())
{
cout << "Not enough information given, check format of input file";
exit(0);
}
processingTimeInMinutes = atof(lines[0].c_str());
papersInSession = atoi(lines[1].c_str());
parallelTracks = atoi(lines[2].c_str());
sessionsInTrack = atoi(lines[3].c_str());
tradeoffCoefficient = atof(lines[4].c_str());
int n = lines.size() - 5;
double **tempDistanceMatrix = new double *[n];
for (int i = 0; i < n; ++i)
{
tempDistanceMatrix[i] = new double[n];
}
for (int i = 0; i < n; i++)
{
string tempLine = lines[i + 5];
// std::vector<string> elements(n);
string* elements = new string[n];
splitString(tempLine, " ", elements, n);
for (int j = 0; j < n; j++)
{
tempDistanceMatrix[i][j] = atof(elements[j].c_str());
}
delete[] elements;
}
distanceMatrix = tempDistanceMatrix;
int numberOfPapers = n;
int slots = parallelTracks * papersInSession * sessionsInTrack;
if (slots != numberOfPapers)
{
cout << "More papers than slots available! slots:" << slots << " num papers:" << numberOfPapers << endl;
exit(0);
}
}
double **SessionOrganizer::getDistanceMatrix()
{
return distanceMatrix;
}
void SessionOrganizer::printSessionOrganiser(char *filename)
{
conference->printConference(filename);
}
double SessionOrganizer::scoreOrganization()
{
// Sum of pairwise similarities per session.
double score1 = 0.0;
for (int i = 0; i < conference->getParallelTracks(); i++)
{
Track tmpTrack = conference->getTrack(i);
for (int j = 0; j < tmpTrack.getNumberOfSessions(); j++)
{
Session tmpSession = tmpTrack.getSession(j);
for (int k = 0; k < tmpSession.getNumberOfPapers(); k++)
{
int index1 = tmpSession.getPaper(k);
for (int l = k + 1; l < tmpSession.getNumberOfPapers(); l++)
{
int index2 = tmpSession.getPaper(l);
score1 += 1 - distanceMatrix[index1][index2];
}
}
}
}
// Sum of distances for competing papers.
double score2 = 0.0;
for (int i = 0; i < conference->getParallelTracks(); i++)
{
Track tmpTrack1 = conference->getTrack(i);
for (int j = 0; j < tmpTrack1.getNumberOfSessions(); j++)
{
Session tmpSession1 = tmpTrack1.getSession(j);
for (int k = 0; k < tmpSession1.getNumberOfPapers(); k++)
{
int index1 = tmpSession1.getPaper(k);
// Get competing papers.
for (int l = i + 1; l < conference->getParallelTracks(); l++)
{
Track tmpTrack2 = conference->getTrack(l);
Session tmpSession2 = tmpTrack2.getSession(j);
for (int m = 0; m < tmpSession2.getNumberOfPapers(); m++)
{
int index2 = tmpSession2.getPaper(m);
score2 += distanceMatrix[index1][index2];
}
}
}
}
}
double score = score1 + tradeoffCoefficient * score2;
return score;
}