aboutsummaryrefslogtreecommitdiff
path: root/src/main/evaluation/benchmark.cpp
blob: 9e1b7a934fe5a6422cd87e553a323acdacd7b250 (plain) (blame)
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
//
// Created by thecharlesblake on 4/5/18.
//

#include <climits>
#include <iostream>
#include <numeric>

#include "benchmark.h"
#include "../game/search-state/game_state.h"
#include "../solver/solver.h"

using namespace std;
typedef chrono::microseconds microsec;

void benchmark::run(const sol_rules &rules, uint64_t cache_capacity, game_state::streamliner_options streamliners) {
    cout << "Seed "
            "| Median/Mean Solution Time(μs) "
            "| Median/Mean States Searched "
            "| Solvable/Unsolvable";

    multiset<int> sol_times;
    multiset<int> states_searched;
    int total_time = 0;
    int total_states = 0;
    int total_solvable = 0;
    int total_unsolvable = 0;

    for(int seed = 1; seed <= 1000; seed++) {
        game_state gs(rules, seed, streamliners);
        solver sol(gs, cache_capacity);

        auto start = chrono::steady_clock::now();
        solver::sol_state result = sol.run();
        auto end = chrono::steady_clock::now();
        microsec elapsed_micros =
                chrono::duration_cast<chrono::microseconds>(end - start);

        sol_times.insert(static_cast<int>(elapsed_micros.count()));
        total_time += static_cast<int>(elapsed_micros.count());
        states_searched.insert(sol.get_states_searched());
        total_states += sol.get_states_searched();
        switch (result) {
            case solver::sol_state::solved:
                total_solvable++;
                break;
            case solver::sol_state::unsolvable:
                total_unsolvable++;
                break;
            case solver::sol_state::timed_out:
                assert(false);
                break;
        }

        cout << "\n"  << seed
             << " | " << *next(begin(sol_times), (sol_times.size())/2)
             << "/" << total_time/sol_times.size()
             << " | " << *next(begin(states_searched), (states_searched.size())/2)
             << "/" << total_states/sol_times.size()
             << " | " << total_solvable
             <<  "/"  << total_unsolvable;
    }
}