{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# 13. Space Syntax Analysis\n\nCompare integration and choice on a four-space access graph. This is an introduction to graph-based spatial interpretation.\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-13-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-13-01"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Create an access graph\n\nEach vertex represents a space and each edge a direct connection. This is a justified access representation, not an axial or visibility graph.\n",
   "id": "tutorial-13-02"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "from topologicpy.Vertex import Vertex\nfrom topologicpy.TGraph import TGraph\n\nentrance = Vertex.ByCoordinates(0, 0, 0)\nhall = Vertex.ByCoordinates(2, 0, 0)\nstudio = Vertex.ByCoordinates(4, 0, 0)\noffice = Vertex.ByCoordinates(2, 2, 0)\nvertices = [entrance, hall, studio, office]\nedges = [{\"src\": 0, \"dst\": 1},\n         {\"src\": 1, \"dst\": 2},\n         {\"src\": 1, \"dst\": 3}]\ngraph = TGraph.ByVerticesEdges(vertices, edges, directed=False)\nassert isinstance(graph, TGraph)\nassert len(TGraph.Vertices(graph)) == 4\nassert len(TGraph.Edges(graph)) == 3\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-13-03"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Calculate two measures\n\n`TGraph.Integration` defaults to closeness-based integration; `TGraph.Choice` uses vertex betweenness. Both use hop distances here. These introduce accessibility and through-movement, rather than every conventional space-syntax normalisation. The API also offers `method=\"hh\"` for Hillier–Hanson integration, where some tiny graphs have undefined values.\n",
   "id": "tutorial-13-04"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "integration = TGraph.Integration(graph, method=\"closeness\")\nchoice = TGraph.Choice(graph)\nfor index in range(len(vertices)):\n    print(\"Space\", index, \"Integration:\", integration[index], \"Choice:\", choice[index])\nassert integration[1] > integration[0]\nassert choice[1] > choice[0]\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-13-05"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Try it yourself\n\nAdd a connection between the studio and office. How does the hall’s role change?\n",
   "id": "tutorial-13-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
}
