ThreeBarTrussFunction#
- class ThreeBarTrussFunction(P: float = 2.0, sigma_max: float = 2.0, 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]#
Three-bar planar truss design optimization problem.
This classic structural engineering problem involves designing a three-bar planar truss to support a load P at minimum weight while satisfying stress constraints in each member.
Problem Description
The truss consists of three members arranged symmetrically: - Two diagonal members (area A1) at 45 degrees - One vertical member (area A2)
The structure must support a vertical load P applied at the junction point. The objective is to minimize the total weight (proportional to total material volume) while ensuring that stresses in all members remain below the allowable stress.
|------ L ------| * * \ / \ A1 A1 / \ / \ / \ / \ / \ / * ---- A2 | | P (load) v
Design Variables
- A1float
Cross-sectional area of diagonal members (dimensionless, normalized). Bounds: [0, 1]
- A2float
Cross-sectional area of vertical member (dimensionless, normalized). Bounds: [0, 1]
Objective Function
Minimize weight:
\[f(A_1, A_2) = (2\sqrt{2} A_1 + A_2) \cdot L\]where L is the member length (normalized to 1).
Constraints
Three stress constraints ensure members don’t exceed allowable stress:
\[ \begin{align}\begin{aligned}g_1: \frac{\sqrt{2} A_1 + A_2}{\sqrt{2} A_1^2 + 2 A_1 A_2} P - \sigma_{max} \leq 0\\g_2: \frac{A_2}{\sqrt{2} A_1^2 + 2 A_1 A_2} P - \sigma_{max} \leq 0\\g_3: \frac{1}{A_1 + \sqrt{2} A_2} P - \sigma_{max} \leq 0\end{aligned}\end{align} \]- Parameters:
P (float, default=2.0) – Applied load magnitude.
sigma_max (float, default=2.0) – Maximum allowable stress.
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.
References
Examples
>>> from surfaces.test_functions.engineering import ThreeBarTrussFunction >>> func = ThreeBarTrussFunction() >>> # Evaluate at a point >>> result = func({"A1": 0.5, "A2": 0.5}) >>> # Check if solution is feasible >>> func.is_feasible({"A1": 0.789, "A2": 0.408}) True
- __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.
- constraint_violations(params: Dict[str, Any]) List[float][source]#
Calculate constraint violations (positive values only).
- property meta: MetaSpec[source]#
Instance display/identity metadata (a frozen MetaSpec).
Metadata is fully static today, so this returns the class-level
MetaSpecresolved at class-definition time.
- 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:
- 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.
- 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)._specis 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 thatfunc.spec.n_dimreflects this instance’s value. It is resolved on every access rather than cached, because some functions (e.g. BBOB) readspecduring__init__before the optimum has been computed, and a cached early value would go stale.