-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpareto.py
48 lines (39 loc) · 1.38 KB
/
pareto.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
from solution import Solution
from operator import attrgetter
def load_solutions(ruta):
importedSolutions = []
with open(ruta) as content:
solutions = json.load(content)
for solution in solutions:
importedSolutions.append(Solution(solution["effort"], solution["satisfaction"]))
return importedSolutions
def getParetoFront(solutions):
paretoDict = {}
paretoFront = []
for solution in solutions:
if not solution.effort in paretoDict:
paretoDict[solution.effort] = solution.satisfaction
continue
if solution.satisfaction > paretoDict[solution.effort]:
paretoDict[solution.effort] = solution.satisfaction
for k,v in paretoDict.items():
paretoFront.append(Solution(k, v))
return paretoFront
def main():
solutions = load_solutions("solutions.json")
for s in solutions:
print(s)
sorted(solutions, key=attrgetter('productivity'))
print("================Ordenadas por productividad============")
for s in sorted(solutions, key=attrgetter('effort')):
print(s)
paretoFront = sorted(getParetoFront(solutions), key=attrgetter('effort'))
print("================Frente de pareto============")
for s in paretoFront:
print(s)
with open('result.json', 'w') as outfile:
json.dump([s.__dict__ for s in paretoFront], outfile, indent=4)
# then writes the result as another json
if __name__ == '__main__':
main()