{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# 07. Parametric Design and Optimisation\n\nCompare five room proportions with the same floor area. Use a small exhaustive search rather than a long optimisation run.\n\n**Goal:** Complete one small workflow. Run the cells from top to bottom in a fresh kernel.\n\n**Extra dependencies:** None beyond the base environment.\n\nAll examples use metres unless stated otherwise.\n",
   "id": "tutorial-07-00"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "import os\nos.environ[\"TOPOLOGICPY_CORE_BACKEND\"] = \"pythonocc\"\n\nimport topologicpy\nfrom topologicpy.Core import Core\n\nassert topologicpy.__version__ == \"0.9.86\", \"Use TopologicPy 0.9.86 for these tutorials.\"\nassert type(Core.Backend()).__name__ == \"PythonOCCBackend\", \"Restart with the pythonocc backend.\"\nprint(\"TopologicPy\", topologicpy.__version__, \"—\", type(Core.Backend()).__name__)\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-07-01"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Generate and evaluate alternatives\n\nKeep floor area at 24 m² and height at 3 m. Our objective is to minimise total surface area, a geometric proxy rather than a complete building-performance measure.\n",
   "id": "tutorial-07-02"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "from topologicpy.Cell import Cell\n\nfloor_area = 24\nheight = 3\ncandidates = []\nfor width in [3, 4, 5, 6, 8]:\n    length = floor_area / width\n    room = Cell.Prism(width=width, length=length, height=height)\n    surface_area = Cell.SurfaceArea(room)\n    candidates.append([width, length, surface_area])\n    print(\"Width:\", width, \"Length:\", round(length, 2), \"Surface area:\", surface_area)\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-07-03"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Select the best candidate\n\nA simple loop makes the selection rule visible. This finds the best of the five candidates, not a guaranteed global optimum over all possible dimensions.\n",
   "id": "tutorial-07-04"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "best = candidates[0]\nfor candidate in candidates:\n    if candidate[2] < best[2]:\n        best = candidate\nprint(\"Best width, length, surface area:\", best)\nassert best[0] == 5\nassert abs(best[0] * best[1] - floor_area) < 0.0001\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-07-05"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Try it yourself\n\nAdd more widths near the current best. Then impose a minimum length of 4 metres.\n",
   "id": "tutorial-07-06"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (TopologicPy tutorials)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
