File size: 1,433 Bytes
4d0ffdd
 
 
 
 
 
 
 
6a28f91
4d0ffdd
 
 
 
 
6a28f91
 
4d0ffdd
 
 
 
f6c65ef
4d0ffdd
 
f6c65ef
4d0ffdd
 
 
 
f6c65ef
4d0ffdd
 
 
f6c65ef
4d0ffdd
 
 
 
 
 
 
f6c65ef
4d0ffdd
 
f6c65ef
4d0ffdd
 
f6c65ef
4d0ffdd
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Readiness-based scheduling policy.

Combines age, readiness score, and urgency into a composite priority score.
This is the most sophisticated policy, balancing fairness with efficiency.

Priority formula:
  priority = (age/2000) * 0.4 + readiness * 0.3 + urgent * 0.3
"""

from __future__ import annotations

from datetime import date
from typing import List

from src.core.case import Case
from src.core.policy import SchedulerPolicy


class ReadinessPolicy(SchedulerPolicy):
    """Readiness-based scheduling: composite priority score."""

    def prioritize(self, cases: List[Case], current_date: date) -> List[Case]:
        """Sort cases by composite priority score (highest first).

        The priority score combines:
        - Age (40% weight)
        - Readiness (30% weight)
        - Urgency (30% weight)

        Args:
            cases: List of eligible cases
            current_date: Current simulation date

        Returns:
            Cases sorted by priority score (descending)
        """
        # Update ages and compute readiness
        for c in cases:
            c.update_age(current_date)
            c.compute_readiness_score()

        # Sort by priority score (higher = more urgent)
        return sorted(cases, key=lambda c: c.get_priority_score(), reverse=True)

    def get_name(self) -> str:
        return "Readiness-Based"

    def requires_readiness_score(self) -> bool:
        return True