try_solver.py 1.54 KB
Newer Older
Grégoire Grzeczkowicz's avatar
Grégoire Grzeczkowicz committed
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
from os import system
import json
import numpy as np
from scipy.integrate import dblquad
import matplotlib.pyplot as plt

Nb_run = 5

solvers = [
    '-m num_greedy -n 45 -i 20 -r 0.08 -t 10000 -w 100 -a 0.01',
    '-m bit_greedy -n 45 -i 20 -r 0.08 -t 10000 -w 100 -a 0.01'
]

datas = []

for solver in solvers:
    print("python3 draw_ert.py --nb-run " + str(Nb_run) + " --save-proba " + solver)
    system("python3 draw_ert.py --nb-run " + str(Nb_run) + " --save-proba " + solver)
    with open('proba.json') as json_file:
        data = json.load(json_file)
    datas.append(data)

temps_max = 0
value_max = 0
value_min = np.inf

for data in datas:
    for run in data:
        m = max([int(k) for k,v in run.items()])
        if m > temps_max:
            temps_max = m
        m = max([v for k,v in run.items()])
        if m > value_max:
            value_max = m
        m = min([v for k,v in run.items()])
        if m < value_min:
            value_min = m

def probability(data,time,value):
    num = 0
    for attempt in data:
        good = False
        for t,v in attempt.items():
Grégoire Grzeczkowicz's avatar
Grégoire Grzeczkowicz committed
44
            if int(t) <= time and v >= value:
Grégoire Grzeczkowicz's avatar
Grégoire Grzeczkowicz committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
                good = True
                break
        if good:
            num += 1
    return num/len(data)

probability = np.vectorize(probability, excluded=[0])

m = 0
v = 0
for i in range(len(solvers)):
    volume = dblquad(lambda x,y: probability(datas[i],x,y),value_min,value_max,0,temps_max)[0]
    print(solvers[i])
    print(volume)
    if volume > v:
        m = i
        v = volume

print("Best solveur:")
print(solvers[m])