releso.shape_parameterization.VariableLocation

class releso.shape_parameterization.VariableLocation(*, save_location: Path, logger_name: str | None = None, current_position: float, min_value: float | None = None, max_value: float | None = None, n_steps: ConstrainedIntValue | None = 10, step: float | None = None)

Bases: BaseModel

Variable location class.

Object of this class defines the position and movement possibilities for a single dimensions of a single control point of the geometry.

__init__(**data: Any) None

Constructor for VariableLocation.

Methods

apply_continuous_action(value)

Apply a continuous action the variable.

apply_discrete_action(increasing)

Apply a discrete action to the variable.

convert_to_pathlib_add_datetime(v)

Add timestamp to save_location, of applicable.

define_step(values)

Validator for class.

get_logger()

Gets the currently defined environment logger.

is_action()

Boolean if variable defines an action.

reset()

Resets the current_location to the initial position.

set_logger_name_recursively(logger_name)

Set the logger_name variable for all child elements.

set_variable_to_current_position_if_not_given(v, ...)

Validator for min_value and max_value.

Attributes

current_position

coordinate of the current position of the current control point in the dimension

min_value

lower bound of possible values which can be reached by this variable

max_value

upper bound of possible values which can be reached by this variable

n_steps

number of steps the value range is divided into used to define the step if not given.

step

If discrete actions are used the step is used to define the new current position by adding/subtracting it from the current position.

save_location

Definition of the save location of the logs and validation results.

logger_name

name of the logger.

apply_continuous_action(value: float) float

Apply a continuous action the variable.

Apply the zero-mean normalized value as the new current position. Needs to descale the value first. Also applies clipping.

Parameters:
  • value (float) – Scaled value [-1,1] that needs to be descaled and

  • position. (applied as the new current)

Returns:

New clipped value.

Return type:

float

apply_discrete_action(increasing: bool) float

Apply a discrete action to the variable.

Apply the a discrete action to the current value. If resulting value would be outside of the min and max value range no step is taken.

Parameters:
  • increasing (bool) – Toggle whether or not the value should increase

  • not. (or)

Returns:

Value of the position that the current position is now at.

Return type:

float

current_position: float

coordinate of the current position of the current control point in the dimension

classmethod define_step(values: Dict[str, Any]) Dict[str, Any]

Validator for class.

Validation function that defines the step taken if the action would be discrete. If nothing is given for the calculation a n_steps default value of 10 is used.

Parameters:

values (Dict[str, Any]) – Validated variables of the object.

Returns:

Validated variables but if steps was not given before now it has a value.

Return type:

Dict[str, Any]

is_action() bool

Boolean if variable defines an action.

Checks if the variable has variability. Meaning is there optimization between the min_value and the max_value.

Returns:

True if (self.max_value > self.current_position) or (self.min_value < self.current_position)

Return type:

bool

max_value: float | None

upper bound of possible values which can be reached by this variable

min_value: float | None

lower bound of possible values which can be reached by this variable

n_steps: ConstrainedIntValue | None

number of steps the value range is divided into used to define the step if not given.

reset() None

Resets the current_location to the initial position.

classmethod set_variable_to_current_position_if_not_given(v, values, field) float

Validator for min_value and max_value.

Validation of the min and max values for the current VariableLocation. If non are set no variability is assumed min = max = current_position

Parameters:
  • v ([type]) – Value to validate.

  • values ([type]) – Already validated values.

  • field ([type]) – Name of the field that is currently validated.

Raises:
  • ParserException – Parser error if current_position is not already

  • validated.

Returns:

value of the validated value.

Return type:

float

step: float | None

If discrete actions are used the step is used to define the new current position by adding/subtracting it from the current position.