CantileverBeamFunction#

class CantileverBeamFunction(objective: str = 'minimize', modifiers: List[BaseModifier] | None = None, memory: bool = False, collect_data: bool = True, callbacks=None, catch_errors=None, penalty_coefficient: float = 1000000.0)[source]#

Cantilever beam design optimization problem.

This structural engineering problem involves designing a stepped cantilever beam with minimum weight while constraining the tip deflection. The beam has a square cross-section that varies along its length in discrete steps.

Problem Description

A cantilever beam is fixed at one end and carries a vertical load at the free end. The beam is divided into five segments of equal length, each with a square cross-section of different width. The widths must be optimized to minimize total weight while keeping tip deflection below a specified limit.

WALL
####|   x1    |   x2    |   x3    |   x4    |   x5    |
####|=========|=========|=========|=========|=========| <- P
####|   x1    |   x2    |   x3    |   x4    |   x5    |
####|_________|_________|_________|_________|_________|
     |<- l ->|

Each segment has square cross-section with side length xi.
Total length = 5l, where l is segment length.

Design Variables

x1float

Width of segment 1 (nearest to wall). Bounds: [0.01, 100.0]

x2float

Width of segment 2. Bounds: [0.01, 100.0]

x3float

Width of segment 3. Bounds: [0.01, 100.0]

x4float

Width of segment 4. Bounds: [0.01, 100.0]

x5float

Width of segment 5 (at free end). Bounds: [0.01, 100.0]

Objective Function

Minimize beam weight (volume for uniform density):

\[f(x_1, ..., x_5) = 0.0624 (x_1 + x_2 + x_3 + x_4 + x_5)\]

The coefficient 0.0624 comes from segment length and density normalization.

Constraints

Tip deflection must not exceed the specified limit:

\[g: \frac{61}{x_1^3} + \frac{37}{x_2^3} + \frac{19}{x_3^3} + \frac{7}{x_4^3} + \frac{1}{x_5^3} \leq 1\]

These coefficients arise from the structural analysis of a stepped cantilever beam under end loading.

Parameters:
  • objective (str, default="minimize") – Either “minimize” or “maximize”.

  • sleep (float, default=0) – Artificial delay in seconds.

  • penalty_coefficient (float, default=1e6) – Penalty coefficient for constraint violations.

f_global[source]#

Best known objective value: approximately 1.33995636.

Type:

float

x_global[source]#

Best known solution: [6.01601589, 5.30917386, 4.49432957, 3.50147497, 2.15266533].

Type:

ndarray

Notes

This problem has a smooth, well-behaved landscape but the optimal solution requires careful balancing of material distribution along the beam. Segments near the fixed end (higher bending moment) require more material than those near the free end.

The deflection formula comes from applying Castigliano’s theorem to a stepped beam with square cross-section.

References

Examples

>>> from surfaces.test_functions.engineering import CantileverBeamFunction
>>> func = CantileverBeamFunction()
>>> # Evaluate at a point
>>> result = func({"x1": 6.0, "x2": 5.3, "x3": 4.5, "x4": 3.5, "x5": 2.2})
>>> # Check deflection constraint
>>> func.is_feasible({"x1": 6.0089, "x2": 5.3049, "x3": 4.5023, "x4": 3.5077, "x5": 2.1504})
True
x_global: ndarray | None = array([6.01601589, 5.30917386, 4.49432957, 3.50147497, 2.15266533])[source]#
__call__(params: Dict[str, Any] | ndarray | list | tuple | None = None, *, fidelity: float | None = None, **kwargs)[source]#

Evaluate the objective function.

Args:

params: Parameter values as dict, array, list, or tuple fidelity: Optional fidelity level in (0, 1]. Controls evaluation

cost vs accuracy trade-off for multi-fidelity optimization (e.g. Hyperband, BOHB). None means full-fidelity evaluation. Only supported by ML test functions; ignored by algebraic functions.

**kwargs: Parameters as keyword arguments (only with dict input)

Returns:

The objective function value

batch(X: ArrayLike) ArrayLike[source]#

Evaluate multiple parameter sets in a single call.

Parameters:

X (ArrayLike) – 2D array of shape (n_points, n_dim) where each row is a parameter set.

Returns:

1D array of shape (n_points,) with evaluation results.

Return type:

ArrayLike

Raises:
  • NotImplementedError – If the function does not implement _batch_objective.

  • ValueError – If X has wrong number of dimensions or wrong n_dim.

property callbacks[source]#

Callback management (CallbackAccessor).

constraint_violations(params: Dict[str, Any]) List[float][source]#

Calculate constraint violations (positive values only).

Parameters:

params (dict) – Design variable values.

Returns:

Violation amounts. Zero means constraint is satisfied.

Return type:

list of float

constraints(params: Dict[str, Any]) List[float][source]#

Public API: evaluate constraint functions.

property data[source]#

Evaluation data (DataAccessor).

property errors[source]#

Error handler management (ErrorAccessor).

is_feasible(params: Dict[str, Any]) bool[source]#

Check if a solution satisfies all constraints.

Parameters:

params (dict) – Design variable values.

Returns:

True if all constraints are satisfied.

Return type:

bool

property memory[source]#

Memory cache management (MemoryAccessor).

property meta: MetaSpec[source]#

Instance display/identity metadata (a frozen MetaSpec).

Metadata is fully static today, so this returns the class-level MetaSpec resolved at class-definition time.

property modifiers[source]#

Modifier management (ModifierAccessor).

property n_dim: int[source]#

Number of design variables.

penalty(params: Dict[str, Any]) float[source]#

Calculate total penalty for constraint violations.

Parameters:

params (dict) – Design variable values.

Returns:

Penalty value (sum of squared violations times coefficient).

Return type:

float

property plot[source]#

Access plotting methods for this function.

pure(params: Dict[str, Any] | ndarray | list | tuple | None = None, *, fidelity: float | None = None, **kwargs)[source]#

Evaluate the function without modifiers.

Returns the true (deterministic) function value, bypassing any configured modifiers. Does not update search_data, n_evaluations, or callbacks. Ignores memory caching.

Parameters:
  • params (dict, array, list, or tuple) – Parameter values to evaluate.

  • fidelity (float or None) – Fidelity level in (0, 1] for multi-fidelity evaluation.

  • **kwargs (dict) – Parameters as keyword arguments.

Returns:

The true function value without modifiers, with direction applied.

Return type:

float or np.ndarray

raw_objective(params: Dict[str, Any]) float[source]#

Public API: evaluate raw objective without penalties.

reset() None[source]#

Reset all state including collected data and memory cache.

property search_space: Dict[str, Any][source]#

Search space for this function (read-only public API).

property spec: FunctionSpec[source]#

Instance-resolved function specification (a frozen FunctionSpec).

type(self)._spec is the static class-level template. This property overlays the fields that genuinely vary per instance (n_dim, n_objectives, f_global, x_global) by lifting them off the instance, so that func.spec.n_dim reflects this instance’s value. It is resolved on every access rather than cached, because some functions (e.g. BBOB) read spec during __init__ before the optimum has been computed, and a cached early value would go stale.