Optimization · AI Agents · Backend Engineering
OptiNest
An optimization tool for arranging rectangular boxes on a sheet while respecting dimensions, rotation rules, and spacing.
Project overview
OptiNest explores how constraint-based optimization and AI-driven workflows can simplify sheet-layout planning. Users provide sheet dimensions and the box types they need to place; the system validates the input and computes a feasible arrangement subject to the configured constraints.
The problem
Arranging multiple rectangular pieces on a fixed sheet is a two-dimensional packing problem. Manual placement can be time-consuming, and a layout must respect boundaries, orientation restrictions, spacing requirements, and the quantity of each box.
What I built
- Structured layout input: Models sheet dimensions, box dimensions, quantities, allowed rotations, and required gaps.
- Input validation: Uses Pydantic schemas to validate requests before optimization begins.
- Constraint-based solver: Uses Google OR-Tools CP-SAT to represent placement variables and enforce sheet-boundary and non-overlap constraints.
- Agent workflow: Uses a LangGraph-based workflow to organize the processing steps and tool interactions.
- API layer: Uses FastAPI to expose the optimization workflow to a frontend.
- Layout visualization: Presents the computed placements in a visual layout so users can inspect the result.
Technical approach
The backend converts validated dimensions into a constraint model. The solver searches for placements that satisfy the geometric restrictions. The API then returns structured placement data for rendering in the interface.
The solver handles the actual geometric constraints; the language model or agent workflow coordinates the process rather than replacing the mathematical solver.
What I learned
- How to model rectangle packing as a constraint-satisfaction problem.
- Why non-overlap constraints and rotation-dependent dimensions must be handled carefully.
- How to validate API input and represent optimization results with typed schemas.
- How to separate agent orchestration from deterministic optimization logic.
- Why feasibility checks and visualization are important when validating solver output.
Future improvements
Add a clear optimization objective, compare utilization across layouts, support irregular shapes or cutting constraints where appropriate, and benchmark solver performance on larger inputs.