Skip to content

Commit

Permalink
update missing merge codes
Browse files Browse the repository at this point in the history
  • Loading branch information
alxlyj committed Nov 21, 2024
1 parent e644ce4 commit 0f0ac92
Show file tree
Hide file tree
Showing 16 changed files with 1,045,463 additions and 2,550 deletions.
21 changes: 14 additions & 7 deletions python/src/robyn/allocator/entities/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class Constraints:
Attributes:
lower_bounds: Lower bounds for each channel's spend
upper_bounds: Upper bounds for each channel's spend
budget_constraint: Total budget constraint
budget_constraint: Total budget constraint (can be None for target efficiency)
target_constraint: Target efficiency constraint (optional)
"""

lower_bounds: np.ndarray
upper_bounds: np.ndarray
budget_constraint: float
budget_constraint: Optional[float]
target_constraint: Optional[float] = None

def __post_init__(self):
Expand All @@ -35,7 +35,9 @@ def __post_init__(self):
raise ValueError("Upper bounds must be positive")
if np.any(self.upper_bounds < self.lower_bounds):
raise ValueError("Upper bounds must be greater than lower bounds")
if self.budget_constraint <= 0:

# Only validate budget_constraint if it's not None
if self.budget_constraint is not None and self.budget_constraint <= 0:
raise ValueError("Budget constraint must be positive")

def get_bounds(self) -> List[Tuple[float, float]]:
Expand All @@ -50,9 +52,10 @@ def is_feasible(self, x: np.ndarray, tolerance: float = 1e-6) -> bool:
):
return False

# Check budget constraint
if abs(np.sum(x) - self.budget_constraint) > tolerance:
return False
# Check budget constraint only if it exists
if self.budget_constraint is not None:
if abs(np.sum(x) - self.budget_constraint) > tolerance:
return False

# Check target constraint if applicable
if self.target_constraint is not None:
Expand All @@ -67,6 +70,10 @@ def scale_constraints(self, factor: float) -> "Constraints":
return Constraints(
lower_bounds=self.lower_bounds * factor,
upper_bounds=self.upper_bounds * factor,
budget_constraint=self.budget_constraint * factor,
budget_constraint=(
self.budget_constraint * factor
if self.budget_constraint is not None
else None
),
target_constraint=self.target_constraint,
)
Loading

0 comments on commit 0f0ac92

Please sign in to comment.