-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
68 lines (41 loc) · 1.28 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import random
import json
import datetime
from partyoptimizer import helpers
from partyoptimizer.genetics.generation import simulateGenerations
if len(sys.argv)<2:
raise SystemExit, 'Provide source for participants in arguments'
# read first argument and use it as source for participants
sourcepath = sys.argv[1]
participantFile = open(sourcepath,'r')
participants = json.loads(participantFile.read())
participantFile.close()
# generate table to match participants
# NOTE: must be even number, otherwise raises ValueError
table = helpers.genTable(len(participants))
# determine population size
populationSize = len(participants)*3
if len(sys.argv)>2:
populationSize = int(sys.argv[2])
# determine how many generations to run
generations = len(participants)*50
if len(sys.argv)>3:
generations = int(sys.argv[3])
target = ''
if len(sys.argv)>4:
target = sys.argv[4]
# run the algo
print 'Start running'
print ''
bestReached, scores = simulateGenerations(generations, participants, table, populationSize)
print bestReached
print ''
print 'Done'
# if we have target file, save bestReached there
if target!='':
print 'Saving results to '+str(target)
open(target,'w').write(json.dumps(bestReached))
print 'DONE, 4real'