def map_action(self, action):
		## convert to the format used by the simulator
		O_i = self.R_man[0]		
		state = State_Function(self.R_tgt, O_i, action, showRender=False)
		state_point = state.run()
		#print action
		#print state_point
		return state_point
    def run(self):
        granluarity = 5 # start with granularity 1
        while (granluarity <= self.k):
            R_tgt_rect_sg = self.R_tgt_rect_g
            impulse_sg = self.impulse_g
            solution = self.solve(R_tgt_rect_sg, self.initial_R_id, impulse_sg, granluarity)

            # test solution, if works, break, else increase granularity
            if solution != -1:
                print 'solution is found', solution
                action = ((np.random.uniform(solution[0][0], solution[0][1]),np.random.uniform(solution[1][0], solution[1][1])), (1, np.random.uniform(solution[2][0], solution[2][1]))) 
                state = State_Function(R_tgt_rect_sg, self.O_man_rect, action, showRender=True)
                state_point = state.run()
                print "resulting state: ", state_point   
            else:
                print 'solution is not found at granluarity ', granluarity
            granluarity = granluarity + 1
    def __init__(self):
        # do noting.

        self.O_man_rect = Rect(45, 29, 1, 5)

        # An initial target region (position, (hwidth, hheight))
        #R_tgt_rect = Rect(75, 29, 1, 5)
        R_tgt_rect = Rect(25, 2, 1, 5)


        self.R_tgt_rect_g = R_tgt_rect  # currently just use the entire region
        self.impulse_g = ((500,1000), (500, 1000))
        self.k = 5

        initial_state = State_Function(R_tgt_rect)
        self.objects_distance_matrix = initial_state.objects_distance_matrix()
        self.initial_R_id = initial_state.initial_R_tgt_id()

        self.used_objects = []
		#print action
		#print state_point
		return state_point
	
	#def __sample_pts_box(box):
		## sample each surface



if __name__=="__main__":

	impulse_sg = ((500, 1000),(500,1000))
	
	O_i_rect = Rect(55,29,1,5)

	O_i = (O_i_rect, O_i_rect.left_edge())	  

	#R_tgt_rect = Rect(75,29,1,5)
	R_tgt_rect = Rect(45,29,1,5)
	#R_tgt = (R_tgt_rect, R_tgt_rect.left_edge())
	R_tgt = R_tgt_rect
	test = subsolver(impulse_sg, R_tgt, O_i, 2)

	local_solution = test.run()
	action = ((np.random.uniform(local_solution[0][0], local_solution[0][1]),np.random.uniform(local_solution[1][0], local_solution[1][1])), (1, np.random.uniform(local_solution[2][0], local_solution[2][1]))) 

	#action = ((0, -628), (-1, 2))
	state = State_Function(R_tgt_rect, O_i_rect, action, showRender=True)
	state_point = state.run()	
	print local_solution