Script execution
This commit is contained in:
@@ -1,33 +1,44 @@
|
||||
###################################################################################################
|
||||
# Using bsearch(Binary Search) and hsearch(Hill Climbing Search) to find optimum
|
||||
###################################################################################################
|
||||
|
||||
|
||||
|
||||
run("camtool")
|
||||
add_device(CamTool("image_stats", prefix = "SINEG01-DSCR190:", latch = True, camera = "SINEG01-DSCR190"), True)
|
||||
|
||||
image_stats.start()
|
||||
image_stats.setNumberOfImages(5)
|
||||
|
||||
laser_off()
|
||||
image_stats.captureBackground(10)
|
||||
laser_on()
|
||||
image_stats.setNumberOfImages(5)
|
||||
image_stats.enableBackground
|
||||
(True)
|
||||
|
||||
|
||||
def before_sample():
|
||||
image_stats.update()
|
||||
|
||||
class FitnessFunction(ReadonlyRegisterBase):
|
||||
def doRead(self):
|
||||
r = lscan(gun_solenoid, [image_stats.com_x_mean, image_stats.com_y_mean] , 110.0, 120.0, 1.0, 0.1, before_read = before_sample)
|
||||
return 1000.0 - (math.pow(ao1.take()-18, 2) + math.pow(ao2.take()-6, 2))
|
||||
|
||||
#Plot Fitness Function
|
||||
r = ascan([ao1, ao2], fitness, [0.0,0.0], [21.0,26.0], [1.0, 1.0], title = "Fitness")
|
||||
add_device(FitnessFunction("fitness"), True)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
#Binary Search
|
||||
#Relative search:
|
||||
#ao1.write(10.5); ao2.write(13.0)
|
||||
#r = bsearch([ao1, ao2], fitness, [-10.5,-13.0], [10.5,13.0], [0.1, 0.1],relative = True, maximum=True, strategy = "Normal", title = "Binary Search")
|
||||
strategy = "Normal" # or "Boundary" or "FullNeighborhood"
|
||||
r = bsearch([ao1, ao2], fitness, [0.0,0.0], [21.0,26.0], [0.1, 0.1], maximum=True, strategy = strategy, latency = 0.01, title = "Binary Search")
|
||||
|
||||
print "--------------- Binary Search -----------------"
|
||||
print r
|
||||
|
||||
print r.print()
|
||||
print len(r.getRecords())
|
||||
|
||||
ao1.write(10.5); ao2.write(13.0)
|
||||
r = hsearch([ao1, ao2], 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")
|
||||
"""
|
||||
|
||||
#Hill Climbing Search
|
||||
r = hsearch([gsx, gsy, gsrx, gsry], fitness,[-1.0,-1.0,-1.0,-1.0], [1.0,1.0,1.0,1.0], [0.1, 0.1, 0.1, 0.1], [0.01, 0.01, 0.01, 0.01], 3, relative = False, maximum=False, latency = 0.01, title = "Hill Climbing")
|
||||
|
||||
Reference in New Issue
Block a user