pair wise optimization