-
Notifications
You must be signed in to change notification settings - Fork 1
/
gdfann_node.py
executable file
·50 lines (40 loc) · 1.48 KB
/
gdfann_node.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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer
from algoritmoGenetico.Populacao import Populacao
from algoritmoGenetico.Cromossomo import Cromossomo
from config_cromossomo import avaliacaoRNA
class GDFANN_Node:
def __init__(self, domain='0.0.0.0', port=5000):
self._server = SimpleJSONRPCServer( (domain, port) )
functions = {
'run' : self.run
}
for name in functions.keys():
self._server.register_function(functions[name], name)
self._pop = None
def run(self, population):
if type(population) <> list:
return 'Population must be a list'
if self._pop is not None: del(self._pop)
self._pop = Populacao(None, verboso=True)
for i in population:
print i
self._pop.addIndividuo(Cromossomo(9,i))
print 'Evaluating population...'
self._pop.avaliarPopulacao(avaliacaoRNA)
print 'Sending answers...'
answersMSE = []
for i in self._pop.getIndividuos():
answersMSE.append(i.getAvaliacao())
print answersMSE
return answersMSE
def serve(self):
try:
print 'Server running. Press CTRL+C to stop...'
self._server.serve_forever()
except KeyboardInterrupt:
print 'Exiting'
if __name__ == "__main__":
server = GDFANN_Node()
server.serve()