Planar Truss Span
Source: examples/grammar/planar_truss_span.py
Introduction
Build and optionally evaluate a simple truss state.
Technical Implementation
This page is generated from the top-of-file module docstring and the example source code. The full script is included below for direct inspection.
1from __future__ import annotations
2
3import design_research_problems as derp
4
5
6def main() -> None:
7 """Build a simple triangular state and evaluate it when ``trussme`` is installed."""
8
9 # Load the planar truss grammar and start from its seed state, which already
10 # includes the fixed support joints and one free top joint.
11 problem = derp.get_problem("planar_truss_span")
12 state = problem.initial_state()
13
14 # Apply three rule methods to connect the top joint to both supports and then
15 # close the base edge. Together these edits build the minimal triangle.
16 state = problem.add_member(state, start_joint_id=0, end_joint_id=2)
17 state = problem.add_member(state, start_joint_id=1, end_joint_id=2)
18 state = problem.add_member(state, start_joint_id=0, end_joint_id=1)
19 try:
20 # The evaluator converts the serializable grammar state into a fresh truss
21 # model for analysis and returns the resulting performance metrics.
22 evaluation = problem.evaluate(state)
23 except derp.MissingOptionalDependencyError as exc:
24 print(exc)
25 return
26 print(evaluation)
27
28
29if __name__ == "__main__":
30 main()
Expected Results
Run Command
PYTHONPATH=src python3 examples/grammar/planar_truss_span.py
Run the command shown below from repository root. Output should summarize the problem setup, a baseline solution, or diagnostic values relevant to this example.