-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountry_scheduler.py
34 lines (27 loc) · 1.39 KB
/
country_scheduler.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 search_strategies.best_first_search import BestFirstSearch
from successors import RandomSuccessorFunction
def country_scheduler(self_country_name: str, initial_world_state: dict,
output_filename: str, max_best_schedules: int, depth_bound: int,
max_frontier_size: int) -> None:
def successor_fn():
"""
Returns a list of successor states generated by the generate_random_schedule function.
"""
sch_gen = RandomSuccessorFunction(self_country_name)
successors = []
for _ in range(5): # of partial schedules
successor = sch_gen.generate_random_schedule(4) # actions/schedule
successors.append(successor)
return successors
search_obj = BestFirstSearch()
search_obj.search(self_country_name, initial_world_state, successor_fn,
depth_bound, max_frontier_size, max_best_schedules)
with open(output_filename, 'w', encoding='utf8') as f_actions, \
open('scores', 'w', encoding='utf8') as f_scores:
for schedule in search_obj.best_schedules:
for action in schedule.actions:
f_actions.write(str(action))
print(str(action))
f_actions.write(" EU: " + str(schedule.score) + "\n")
f_scores.write(str(schedule.score) + ",\n")
print(str("EU: " + str(schedule.score)))