src.Generator
1class Generator: 2 """ 3 A class to represent a power generator with its characteristics and cost calculation. 4 5 Attributes: 6 ----------- 7 - `gen_id (str)`: The unique identifier for the generator. 8 - `min_capacity (float)`: The minimum capacity of the generator. 9 - `max_capacity (float)`: The maximum capacity of the generator. 10 - `a (float)`: The quadratic cost coefficient. 11 - `b (float)`: The linear cost coefficient. 12 - `c (float)`: The constant cost coefficient. 13 14 Methods: 15 -------- 16 - `calculate_cost(power)`: Calculate the cost for a given power output. 17 - `validate_power(power)`: Validate if the given power is within the generator's capacity limits. 18 """ 19 def __init__(self,gen_id,min_capacity,max_capacity,a,b,c): 20 """ 21 Initialize a Generator object with its parameters. 22 23 Parameters: 24 ----------- 25 - `gen_id (str)`: The unique identifier for the generator. 26 - `min_capacity (float)`: The minimum capacity of the generator. 27 - `max_capacity (float)`:The maximum capacity of the generator. 28 - `a (float)`: The quadratic cost coefficient. 29 - `b (float)`: The linear cost coefficient. 30 - `c (float)`: The constant cost coefficient. 31 32 Returns: 33 -------- 34 None 35 36 """ 37 38 self.gen_id = gen_id 39 """Generator ID""" 40 self.min_capacity = min_capacity 41 """Minimum Capacity""" 42 self.max_capacity = max_capacity 43 """Maximum Capacity""" 44 self.a = a 45 """Cost coefficient a""" 46 self.b = b 47 """Cost coefficient b""" 48 self.c = c 49 """Cost coefficient c""" 50 51 52 def calculate_cost(self,power): 53 54 """ 55 Calculate the cost for a given power output. 56 57 Parameters: 58 ----------- 59 `power (float)`: 60 The power output of the generator. 61 62 Returns: 63 -------- 64 `float`: 65 The cost associated with the given power output. 66 """ 67 68 return (self.a * (power * power) + (self.b * power) + self.c) 69 70 71 def validate_power(self,power): 72 """ 73 Validate if the given power is within the generator's capacity limits. 74 Parameters: 75 ----------- 76 `power (float)`: 77 The power output to validate. 78 Returns: 79 -------- 80 `float`: 81 The validated power output, adjusted to be within capacity limits if necessary. 82 """ 83 if (power < self.min_capacity): 84 return self.min_capacity 85 elif (power > self.max_capacity): 86 return self.max_capacity 87 else: 88 return power 89 90
class
Generator:
2class Generator: 3 """ 4 A class to represent a power generator with its characteristics and cost calculation. 5 6 Attributes: 7 ----------- 8 - `gen_id (str)`: The unique identifier for the generator. 9 - `min_capacity (float)`: The minimum capacity of the generator. 10 - `max_capacity (float)`: The maximum capacity of the generator. 11 - `a (float)`: The quadratic cost coefficient. 12 - `b (float)`: The linear cost coefficient. 13 - `c (float)`: The constant cost coefficient. 14 15 Methods: 16 -------- 17 - `calculate_cost(power)`: Calculate the cost for a given power output. 18 - `validate_power(power)`: Validate if the given power is within the generator's capacity limits. 19 """ 20 def __init__(self,gen_id,min_capacity,max_capacity,a,b,c): 21 """ 22 Initialize a Generator object with its parameters. 23 24 Parameters: 25 ----------- 26 - `gen_id (str)`: The unique identifier for the generator. 27 - `min_capacity (float)`: The minimum capacity of the generator. 28 - `max_capacity (float)`:The maximum capacity of the generator. 29 - `a (float)`: The quadratic cost coefficient. 30 - `b (float)`: The linear cost coefficient. 31 - `c (float)`: The constant cost coefficient. 32 33 Returns: 34 -------- 35 None 36 37 """ 38 39 self.gen_id = gen_id 40 """Generator ID""" 41 self.min_capacity = min_capacity 42 """Minimum Capacity""" 43 self.max_capacity = max_capacity 44 """Maximum Capacity""" 45 self.a = a 46 """Cost coefficient a""" 47 self.b = b 48 """Cost coefficient b""" 49 self.c = c 50 """Cost coefficient c""" 51 52 53 def calculate_cost(self,power): 54 55 """ 56 Calculate the cost for a given power output. 57 58 Parameters: 59 ----------- 60 `power (float)`: 61 The power output of the generator. 62 63 Returns: 64 -------- 65 `float`: 66 The cost associated with the given power output. 67 """ 68 69 return (self.a * (power * power) + (self.b * power) + self.c) 70 71 72 def validate_power(self,power): 73 """ 74 Validate if the given power is within the generator's capacity limits. 75 Parameters: 76 ----------- 77 `power (float)`: 78 The power output to validate. 79 Returns: 80 -------- 81 `float`: 82 The validated power output, adjusted to be within capacity limits if necessary. 83 """ 84 if (power < self.min_capacity): 85 return self.min_capacity 86 elif (power > self.max_capacity): 87 return self.max_capacity 88 else: 89 return power
A class to represent a power generator with its characteristics and cost calculation.
Attributes:
gen_id (str): The unique identifier for the generator.min_capacity (float): The minimum capacity of the generator.max_capacity (float): The maximum capacity of the generator.a (float): The quadratic cost coefficient.b (float): The linear cost coefficient.c (float): The constant cost coefficient.
Methods:
calculate_cost(power): Calculate the cost for a given power output.validate_power(power): Validate if the given power is within the generator's capacity limits.
Generator(gen_id, min_capacity, max_capacity, a, b, c)
20 def __init__(self,gen_id,min_capacity,max_capacity,a,b,c): 21 """ 22 Initialize a Generator object with its parameters. 23 24 Parameters: 25 ----------- 26 - `gen_id (str)`: The unique identifier for the generator. 27 - `min_capacity (float)`: The minimum capacity of the generator. 28 - `max_capacity (float)`:The maximum capacity of the generator. 29 - `a (float)`: The quadratic cost coefficient. 30 - `b (float)`: The linear cost coefficient. 31 - `c (float)`: The constant cost coefficient. 32 33 Returns: 34 -------- 35 None 36 37 """ 38 39 self.gen_id = gen_id 40 """Generator ID""" 41 self.min_capacity = min_capacity 42 """Minimum Capacity""" 43 self.max_capacity = max_capacity 44 """Maximum Capacity""" 45 self.a = a 46 """Cost coefficient a""" 47 self.b = b 48 """Cost coefficient b""" 49 self.c = c 50 """Cost coefficient c"""
Initialize a Generator object with its parameters.
Parameters:
gen_id (str): The unique identifier for the generator.min_capacity (float): The minimum capacity of the generator.max_capacity (float):The maximum capacity of the generator.a (float): The quadratic cost coefficient.b (float): The linear cost coefficient.c (float): The constant cost coefficient.
Returns:
None
def
calculate_cost(self, power):
53 def calculate_cost(self,power): 54 55 """ 56 Calculate the cost for a given power output. 57 58 Parameters: 59 ----------- 60 `power (float)`: 61 The power output of the generator. 62 63 Returns: 64 -------- 65 `float`: 66 The cost associated with the given power output. 67 """ 68 69 return (self.a * (power * power) + (self.b * power) + self.c)
Calculate the cost for a given power output.
Parameters:
power (float):
The power output of the generator.
Returns:
float:
The cost associated with the given power output.
def
validate_power(self, power):
72 def validate_power(self,power): 73 """ 74 Validate if the given power is within the generator's capacity limits. 75 Parameters: 76 ----------- 77 `power (float)`: 78 The power output to validate. 79 Returns: 80 -------- 81 `float`: 82 The validated power output, adjusted to be within capacity limits if necessary. 83 """ 84 if (power < self.min_capacity): 85 return self.min_capacity 86 elif (power > self.max_capacity): 87 return self.max_capacity 88 else: 89 return power
Validate if the given power is within the generator's capacity limits.
Parameters:
power (float):
The power output to validate.
Returns:
float:
The validated power output, adjusted to be within capacity limits if necessary.