File size: 726 Bytes
c289d87 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | from __future__ import annotations
from typing import Dict
from .policies import PrioritizationPolicy
def compute_priority(
predicted_utility: float,
uncertainty: float,
diversity_gain: float,
cluster_bonus: float,
policy: PrioritizationPolicy,
) -> float:
"""Weighted priority function used by adaptive queueing."""
return (
policy.utility_weight * predicted_utility
+ policy.uncertainty_weight * uncertainty
+ policy.diversity_weight * diversity_gain
+ policy.cluster_bonus_weight * cluster_bonus
)
def cluster_bonus(cluster_load: Dict[int, int], cluster_id: int) -> float:
load = cluster_load.get(cluster_id, 0)
return 1.0 / (1.0 + float(load))
|