In this below code, i need you to update with below conditions, First condition: Penalty…
- User
In this below code, i need you to update with below conditions,
First condition: Penalty if 'gain' metric is negative
if metric_name == 'gain' and c_value < 0: reward -= self.SEVERE_PENALTY return reward
with in this above first condition i need you to include additional checking logic, here already i had on condition in the c_value, if the metric_name 'gain' is lessthan 0 then give severe penalty of 200 and return the reward without check any further condition, along with this i need you to add the following condition, if the 'gain' is lessthan 0 is true then return the reward without checking further conditions, if not true need to check the below condition, in the c_value, either the metric_name 'gain' is lessthan 20, or if the metric_name 'pm' is not between 60 to 75, any one condition is true then we need to give penalty as 100. and return the reward no further conditions are need to be check.
Define Circuit Environment
class CircuitEnvironment: VERY_CLOSE_REWARD = 40 LARGE_REWARD = 10 VERY_HIGH_REWARD = 50 PENALTY = 20 SEVERE_PENALTY = 200
def __init__(self, bounds_low, bounds_high): # Initialization code: setup bounds def calculate_reward(self, c_metrics, p_metrics): metrics_order = ['gain', 'bw', 'ugf', 'pm'] reward = 0 target_metrics = {k: self.target_metrics[i] for i, k in enumerate(metrics_order)} print("target_metrics", target_metrics) for metric_name in metrics_order: c_value = c_metrics[metric_name] p_value = p_metrics[metric_name] target_value = target_metrics[metric_name] # First condition: Penalty if 'gain' metric is negative if metric_name == 'gain' and c_value < 0: reward -= self.SEVERE_PENALTY return reward # Second condition: Check if c_value is exactly the target value if c_value == target_value: reward += self.VERY_HIGH_REWARD continue # Third condition: Check if c_value is very close to the target value if metric_name == 'gain' and abs(c_value - target_value) <= 1: reward += self.VERY_CLOSE_REWARD continue elif metric_name == 'bw' and abs(c_value - target_value) <= 1000: reward += self.VERY_CLOSE_REWARD continue elif metric_name == 'ugf' and abs(c_value - target_value) <= 1000000: reward += self.VERY_CLOSE_REWARD continue elif metric_name == 'pm' and abs(c_value - target_value) <= 1: reward += self.VERY_HIGH_REWARD continue # Fourth condition: Check if c_value is closer to target value than p_value if abs(c_value - target_value) < abs(p_value - target_value): reward += self.LARGE_REWARD else: # Fifth condition: Apply penalty if none of the above conditions are met reward -= self.PENALTY return reward - Assistant