TensionCompressionSpringFunction#

class TensionCompressionSpringFunction(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]#

Tension/compression spring design optimization problem.

This mechanical engineering problem involves designing a helical compression spring to minimize weight while satisfying constraints on minimum deflection, shear stress, surge frequency, and geometric limits.

Problem Description

A helical compression spring must be designed to carry a given load. The spring is characterized by wire diameter, mean coil diameter, and number of active coils.

   |<-- D -->|
   .----.----.
  /    /    /|
 /    /    / |
|    |    |  |  <- d (wire diameter)
 \    \    \ |
  \    \    \|
   '----'----'
       .
       .    N active coils
       .
   .----.----.
  /    /    /
 /    /    /

The objective is to minimize the spring weight, which is proportional to the wire length (N * pi * D * d^2).

Design Variables

dfloat

Wire diameter. Bounds: [0.05, 2.0] inches

Dfloat

Mean coil diameter (center of wire to center). Bounds: [0.25, 1.3] inches

Nfloat

Number of active coils. Bounds: [2.0, 15.0]

Objective Function

Minimize spring weight:

\[f(d, D, N) = (N + 2) D d^2\]

This is proportional to the total wire volume (and thus weight).

Constraints

  1. Minimum deflection constraint

  2. Shear stress constraint

  3. Surge frequency constraint

  4. Outer diameter constraint (D + d <= D_max)

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 0.0126652328.

Type:

float

x_global[source]#

Best known solution: [0.051689156131, 0.356720026419, 11.288831695483].

Type:

ndarray

Notes

This problem has a small feasible region relative to the search space, making it challenging for many optimization algorithms. The optimal solution lies at the boundary of multiple active constraints.

References

Examples

>>> from surfaces.test_functions.engineering import TensionCompressionSpringFunction
>>> func = TensionCompressionSpringFunction()
>>> # Evaluate at a point
>>> result = func({"d": 0.05, "D": 0.35, "N": 11.0})
>>> # Check feasibility
>>> func.is_feasible({"d": 0.05169, "D": 0.35673, "N": 11.2885})
True
x_global: ndarray | None = array([ 0.05168916,  0.35672003, 11.2888317 ])[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.