
class FitnessFunction(ReadonlyRegisterBase):
    def doRead(self):
        return 1000.0 - (math.pow(inp.take()-18, 2) + math.pow(out.take()-6, 2) + test.take())

add_device(FitnessFunction("fitness"), True)            

inp.read();out.read();test.read()


#Fitness Function
r = ascan([inp, out], fitness, [0.0,0.0], [21.0,26.0], [1.1,1.1], title = "Fitness")


#Binary Search
strategy = "Normal" # or "Boundary" or "FullNeighborhood"
r = bsearch([inp, out], fitness, [0.0,0.0], [21.0,26.0], [0.1, 0.1], maximum=True, strategy = strategy, latency = 0.01, title = "Binary Search")
#Relative search:
#inp.write(10.5);out.write(13.0)
#r = bsearch([inp, out], fitness, [-10.5,-13.0], [10.5,13.0], [0.1, 0.1],relative = True, maximum=True, strategy = "Normal", title = "Binary Search")

print "---------------  Binary Search  -----------------"
print r
print r.print()
print len(r.getRecords())



inp.write(10.5)
out.write(13.0)
r = hsearch([inp, out], fitness,[0.0,0.0], [21.0,26.0], [1.0, 1.0], [0.1, 0.1], 1, relative = False, maximum=True, latency = 0.01, title = "Hill Climbing")
print "---------------  Hill Climbing Search  -----------------"
print r
print r.print()
print len(r.getRecords())