Population selection to maximize value in an environmental gradient