File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ def fitness_function (input_value : float ) -> float :
2
+ """
3
+ Calculate the fitness (objective) function value for a given input.
4
+
5
+ Args:
6
+ input_value (float): The input value for which the fitness is calculated.
7
+
8
+ Returns:
9
+ float: The fitness value calculated for the input.
10
+
11
+ Raises:
12
+ ValueError: If the input is not a valid floating-point number.
13
+
14
+ Example:
15
+ >>> fitness_function(2.5)
16
+ 12.25
17
+ >>> fitness_function(-1.0)
18
+ 6.0
19
+ """
20
+ if not isinstance (input_value , (int , float )):
21
+ raise ValueError ("Input must be a valid number." )
22
+
23
+ # Define your fitness function here (e.g., x^2, or any other function)
24
+ return input_value ** 2 + 3 * input_value + 2
25
+
26
+
27
+ if __name__ == "__main__" :
28
+ # Example usage
29
+ x_value = float (input ("Enter the value of input_value: " ).strip ())
30
+ fitness = fitness_function (x_value )
31
+ print (f"The fitness for = { x_value } is { fitness } ." )
You can’t perform that action at this time.
0 commit comments