temp.py 1 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

########################################################################
# Temperature programme
########################################################################

class continus:
    """Continus decrease temperature from T_0 and with T_{i+1} = \alpha x T_i"""

    def __init__(self, T_0, alpha):
        self.T = T_0
        self.alpha = alpha

    def __call__(self, i, val, sol):
        T = self.T
        self.T *= self.alpha
        return T

class level:
    """Level decrease temperature from T_0 and with T_{i+1} = T_i - \alpha after \beta changes"""

    def __init__(self, T_0, alpha, beta):
        self.T = T_0
        self.alpha = alpha
        self.beta = beta
        self.val = None
        self.count = 0

    def __call__(self, i, val, sol):
        T = self.T
        if val != self.val:
            self.count += 1
            self.val = val
        if self.count > self.beta:
            self.count = 0
            self.T -= self.alpha
        print()
        print("T = "+str(T))
        return T