Skip to content

Optimization

Tianhao Fu edited this page Nov 24, 2025 · 2 revisions

All design choices in this project are Convex Optimization Problems (COPs). By default, we use an advanced (multi-resolution) grid search to solve them. We also provide an option to use differential evolution from SciPy.

There is a much better way to implement the whole framework, which is to calculate everything in tensors using PyTorch. However, since it takes a lot of time to come up with a differentiable algorithm to find the cross-section properties, we choose to stick with the current discrete approach. If you are gifted, you can rewrite the whole thing in PyTorch instead of NumPy so that you can use gradient-based optimization to replace the current search-based approach.

Cross-section Optimization

The following example is optimizing the cross-section dimensions when the width of the matboard is 400, so that the surface lengths of the cross-section must add up to 400, and the top must be wider than the bottom. There are some other constraints applied to the range of the parameters, such as the height must be a multiple of 20. See details in the project handout.

from bridger import *

MATBOARD_WIDTH: float = 400


def constraint(kwargs: dict[str, float]) -> dict[str, float] | None:
    top, bottom, height = kwargs["top"], kwargs["bottom"], kwargs["height"]
    kwargs["thickness"] = 1.27
    kwargs["outreach"] = 5
    used = bottom + 2 * (height - 2.54) + 10
    return kwargs if used <= MATBOARD_WIDTH and top > bottom else None


matboard_width = 813
cross_section = CIV102Beam()
bridge = BeamBridge(452, cross_section)
evaluator = Evaluator(bridge, Material())
optimizer = BeamOptimizer(evaluator)
params, load = optimizer.optimize_cross_section({
    "top": (100, MATBOARD_WIDTH, .1),
    "bottom": (10, MATBOARD_WIDTH, .1),
    "height": (20, 200, 20),
}, constraint=constraint)
print(params, load)

It takes about 20 seconds to finish searching, thanks to the help of the LRU cache.

{'top': 100.19999999999999, 'bottom': 60.69999999999999, 'height': 120.0, 'thickness': 1.27, 'outreach': 5} 719.6692696587126

Please let us know your questions through Issues.

Clone this wiki locally