-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeom.py
34 lines (25 loc) · 932 Bytes
/
geom.py
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
from math import log
from random import random
from typing import List
import numpy as np
from Edge import Edge
class Geometric():
def __init__(self, beta: float, safety_stock: float):
self.beta = beta
self.safety_stock = safety_stock
def get_position(self, n: int) -> int:
#np.random
return int((log(np.random.random()) // log(1 - self.beta)) % n)
def reorganize_savings_list(self, savings_list: List[Edge]) -> List[Edge]:
monte_carlo = []
while savings_list:
n = len(savings_list)
position = self.get_position(len(savings_list))
monte_carlo.insert(0, savings_list.pop(n - position - 1))
return monte_carlo
def name(self):
return f'Geometric_beta_{self.beta}'
def __str__(self):
return f'{self.beta};{self.safety_stock}'
def __repr__(self):
return f'{self.beta};{self.safety_stock}'