An Optimization-based Approach to Dynamic Visual Context Management