Skip to content

Commit 516fb6a

Browse files
committed
algoright returns solution
1 parent 899512c commit 516fb6a

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

algorithm/algorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ def execute(data):
6060
# podsumowujac - jesli np. n=5, m=3, e=1, to zawsze na koniec iteracji 1 pszczola pochodzi z obszaru
6161
# elitarnego, 2 z dobrych, a 2 sa losowane od nowa.
6262

63-
print(max(pool, key=lambda s: calculate_score(data, s)))
64-
return calculate_score(data, pool[0])
63+
pool = sorted(pool, key=lambda s: calculate_score(data, s), reverse=True)
64+
return pool[0]

main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
from algorithm.algorithm import Algorithm
22
from parsers.input_parser import parse_input
33
from utils.solution_checker import check_solution
4+
from parsers.output_builder import save_solution
45
import time
56

7+
68
def main():
79
# input_file = "files/videos_worth_spreading.in"
810
# input_file = "files/kittens.in"
911
# input_file = "files/example1.in"
10-
input_file = "files/me_at_the_zoo.in"
11-
# input_file = "files/trending_today.in"
12+
# input_file = "files/me_at_the_zoo.in"
13+
input_file = "files/trending_today.in"
1214

1315
# solution_file = "files/example1.out"
1416
# solution = check_solution(input_file, solution_file)
1517
# print(solution)
1618

1719
before = time.time()
18-
score = Algorithm.execute(parse_input(input_file))
20+
best_solution = Algorithm.execute(parse_input(input_file))
21+
save_solution(best_solution, "files/out1.out")
22+
score = check_solution(input_file, "files/out1.out")
1923
after = time.time()
2024

25+
print(best_solution)
2126
print("-----------------------------")
2227
print("Algorithm took: " + str(round(after-before, 2)) + " s")
2328
print("-----------------------------")
24-
print("Saved time: " + str(round(score / 1000, 2)) + " s")
29+
print("Saved time: " + str(round(score / 1000, 2)) + " s (score: " + str(score) + ")")
2530

2631
if __name__ == '__main__':
2732
main()

parsers/output_builder.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def save_solution(solution, name):
2+
with open(name, 'w') as f:
3+
f.write(str(len(solution)) + "\n")
4+
for s in solution:
5+
f.write(str(s) + " " + " ".join([str(v) for v in solution[s]]) + "\n")

0 commit comments

Comments
 (0)