-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLookOut.py
More file actions
45 lines (40 loc) · 1.24 KB
/
LookOut.py
File metadata and controls
45 lines (40 loc) · 1.24 KB
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
from __future__ import print_function
import random
from display import *
""" BASELINES """
# Baseline 1
def best_greedy( graph, budget ): # TopK
return graph.get_plot_ranks()[:budget]
# Baseline 2
def random_plots( graph, budget ): # Random
plots = graph.get_plot_ranks()
return random.sample( plots, budget )
""" LookOut Algorithm """
# Select the optimised plot cover
def best_plots( graph, budget ):
best_plot_list = []
# Continue choosing plots till the budget is exhausted
while budget > 0:
# Choose the next best plot which mazimizes score
plot = graph.get_best_plot()
best_plot_list.append( int( plot ) )
# Update the graph after removing chosen plot
graph.update_graph( plot )
budget -= 1
# Return a list of the chosen plots
return best_plot_list
# Optimized Algorithm
def LookOut( graph, budget, algo="LookOut" ):
print( "\t-> Choosing best plots" )
if algo == "LookOut":
plots = best_plots( graph, budget )
elif algo == "TopK":
plots = best_greedy( graph, budget )
elif algo == "Random":
plots = random_plots( graph, budget )
else:
print_fail( "The Algorithm specified doesn't lie in { LookOut, TopK, Random }. Skipping ..." )
return
print( "\t-> Choosen Plots are ", end='' )
cprint( str(plots), OKBLUE )
return plots