Discrete bounds for integer variables #175
juan11iguel
started this conversation in
Ideas
Replies: 2 comments
-
Of course, what you want can be obtained mapping the values [0,1,2] to your finite set [0,3,4]. The bounds would then be [0,2] and the mapping used inside the fitness function. Makes sense? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes! class Problem:
logical_dec_vars_mapping: dict[str, list[int]] = {} # Probably throws error due to mutable default value
def get_bounds(self) -> tuple[ list[float|int], list[float|int] ]:
# Variables 0,1,2 are real
lower_bounds = [0, 0, -np.inf]
upper_bounds = [10, 100, np.inf]
# Variable 3 is an integer with 5 possible states
if some_condition:
# allowed states [0,3,4] -> bounds: [0, 2]
lower_bounds.append(0)
upper_bounds.append(2)
# Setup mapping
self.logical_dec_vars_mapping["var_3"] = [0,3,4]
else: # Default case
# allowed states [0,1,2,3,4] -> bounds: [0, 4]
lower_bounds.append(0)
upper_bounds.append(4)
# Setup default mapping
self.logical_dec_vars_mapping["var_3"] = [0,1,2,3,4]
return lower_bounds, upper_bounds
def fitness(self, x: np.ndarray[float | int]):
# Map logical decision variables values to their actual values
x[3] = self.logical_dec_vars_mapping["var_3"][x[3]]
... Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As of now, the bounds in the
Problem
interface can only be set as box-bounds:This is fine for real variables, but for integer ones, where the value may represent for example a finite machine state, it would be very beneficial having the ability to restrict the possible states to a set of discrete values.
Pseudo-code of how this interface could look:
With the current implementation, one would have to define [0,4] as the bounds for the discrete variable, adding complexity to the solution space (1,2 would be explored) that could have otherwise been avoided by setting appropriate bounds.
Does what I propose make any sense? I understand that this would imply a modification on how the initial values are generated, which for these integer variables with bounds would need to pick one element from the set of possible values at random.
Best regards!
Beta Was this translation helpful? Give feedback.
All reactions