Skip to content

Commit c91d547

Browse files
committed
solution evaluation
1 parent 595bf8c commit c91d547

File tree

7 files changed

+29
-6
lines changed

7 files changed

+29
-6
lines changed

app/main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
from datarepresentation.server import Server
44
from datarepresentation.endpoint import Endpoint
55
from datarepresentation.datacenter import DataCenter
6+
from datarepresentation.connection import Connection
7+
from datarepresentation.requestinfo import RequestInfo
68

79

810
def data_init():
911
endpoints = [Endpoint(0, 44, 1), Endpoint(1, 11, 1)]
1012
movies = [Movie(0, 55), Movie(1, 99)]
1113
servers = [Server(0), Server(1)]
12-
connections = []
13-
requests = []
14+
connections = [Connection(endpoints[0], servers[0], 11), Connection(endpoints[1], servers[1], 66)]
15+
requests = [RequestInfo(0, 0, 3), RequestInfo(1, 1, 1)]
1416

1517
return DataCenter(endpoints, movies, servers, connections, requests)
1618

19+
1720
def main():
1821

1922
max_iter = 3
@@ -24,7 +27,8 @@ def main():
2427
bee = Solution(data, {data.servers[0]: [data.movies[0]], data.servers[1]: [data.movies[1]]})
2528
print(bee)
2629
print(bee.evaluate())
27-
print(bee.random_neighbour(1))
30+
print(bee.random_neighbour(2))
31+
print(bee.random_neighbour(1).evaluate())
2832

2933
if __name__ == '__main__':
3034
main()

app/solution.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import random
2-
from datarepresentation.movie import Movie
32

43

54
class Solution:
@@ -47,7 +46,14 @@ def evaluate(self):
4746
res = 0
4847

4948
for request in self.data.requests:
50-
res += 1
51-
# print(request)
49+
m = self.data.movies[request.video_id]
50+
e = self.data.endpoints[request.endpoint_id]
51+
best_conn = e.datacenter_latency
52+
53+
for c in e.connections:
54+
if c.latency < best_conn and m in self.solution[c.server]:
55+
best_conn = c.latency
56+
57+
res += best_conn * request.amount_of_requests
5258

5359
return res

datarepresentation/connection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Connection:
2+
3+
def __init__(self, endpoint, server, latency):
4+
self.endpoint = endpoint
5+
self.server = server
6+
self.latency = latency

datarepresentation/datacenter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ def __init__(self, endpoints, movies, servers, connections, requests):
66
self.servers = servers
77
self.connections = connections
88
self.requests = requests
9+
10+
for connection in connections:
11+
connection.server.connections.append(connection)
12+
connection.endpoint.connections.append(connection)

datarepresentation/endpoint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ def __init__(self, endpoint_id, datacenter_latency, amount_of_caches):
44
self.datacenter_latency = datacenter_latency
55
self.amount_of_caches = amount_of_caches
66
self.cache_server_latencies = dict()
7+
self.connections = []
78

89
def __str__(self):
910
return self.__pretty_string_representation()

datarepresentation/requestinfo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class RequestInfo:
2+
23
def __init__(self, video_id, endpoint_id, amount_of_requests):
34
self.video_id = video_id
45
self.endpoint_id = endpoint_id

datarepresentation/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
class Server:
22
def __init__(self, ids):
33
self.ids = ids
4+
self.connections = []

0 commit comments

Comments
 (0)