Teitz and Bart p-median algorithm