Automatic optimization through reinforcement learning