def choose_peers(relay, relay_count, worker_count, min_w2r, min_r2w):
    """
    Given `relay`, the position of relay within the affinity set for a
    given service, the number of relays in that set (`relay_count`), the number
    of workers for the service (`worker_count`), the minimum number of
    connections required on each worker (`min_w2r`), and the minimum number of
    connections required for each relay node (`min_r2w`), compute the set of
    workers that the relay should connect to as positions in the worker set.
    """
    if relay_count == 0 or worker_count == 0:
        return set()
    ratio = float(worker_count) / relay_count
    start = int(relay * ratio)
    stop = int(relay * ratio + max(min_r2w, min_w2r * ratio) + 0.5)
    return set(worker % worker_count for worker in range(start, stop))