-
Notifications
You must be signed in to change notification settings - Fork 11
/
GSLSimplex.cpp
63 lines (49 loc) · 1.58 KB
/
GSLSimplex.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
#include <iostream>
#include <cmath>
#include <gsl/gsl_multimin.h>
#include <gsl/gsl_sf_erf.h>
#include <mysql++/mysql++.h>
#include "player.h"
#include "game.h"
#include "collection.h"
using namespace std;
int main(void) {
int tournid;
collection c;
player p;
game g;
mysqlpp::Connection conn(false);
if (conn.connect("ratings", "localhost", "pwaldron", "Burcan**")) {
mysqlpp::Query query = conn.query("SELECT Players.agaid AS ID, Players.rating AS EntryRating FROM Players WHERE TournamentIndex=%0q ORDER BY agaid;");
query.parse();
mysqlpp::StoreQueryResult res = query.store(tournid);
if (res) {
for (size_t i=0; i<res.num_rows(); i++) {
p.seed = res[i]["EntryRating"];
p.id = res[i]["ID"];
p.sigma = 0.5;
c.playerHash[p.id] = p;
}
}
mysqlpp::Query query2 = conn.query("SELECT * FROM Games WHERE TournamentIndex=%0q ORDER BY idx");
query2.parse();
mysqlpp::StoreQueryResult res2 = query2.store(tournid);
if (res2) {
for (size_t i=0; i<res2.num_rows(); i++) {
g.white = res2[i]["WhitePlayer"];
g.black = res2[i]["BlackPlayer"];
g.handicap = res2[i]["Handicap"];
g.komi = res2[i]["Komi"];
g.whiteWins = res2[i]["WhiteWins"];
c.gameList.push_back(g);
}
}
}
// Run the faster algorithm first; use the slower one as a backup.
if (c.calc_ratings_fdf() != 0)
c.calc_ratings();
for (map<int, player>::iterator It = c.playerHash.begin(); It != c.playerHash.end(); It++) {
cout << It->second.id << '\t' << It->second.rating << '\t' << It->second.sigma << endl;
}
return 0;
}