{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "31360e8f",
   "metadata": {},
   "source": [
    "# Interaktiivne tööriist väljapääsupunktide kaalude arvutamiseks\n",
    "\n",
    "Muuda eksponentide väärtusi ja vaata, kuidas need mõjutavad väljapääsupunktide kaale.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ba626614",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "752fb0c855cc4b4695a3c97b1af4d23a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=1.0, description='α (Attractiveness)', max=3.0), FloatSlider(value=1.0…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.compute_weights(alpha, beta, gamma, delta, lambd)>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "from ipywidgets import interact, FloatSlider\n",
    "import ipywidgets as widgets\n",
    "\n",
    "# Näidisandmed väljapääsupunktide kohta\n",
    "data = pd.DataFrame({\n",
    "    'Exit': ['A', 'B', 'C', 'D', 'E'],\n",
    "    'Distance_km': [2.2, 5.8, 1.5, 3.9, 6.5],\n",
    "    'Traffic_factor': [1.2, 0.8, 1.5, 1.0, 0.6],\n",
    "    'Road_quality': [0.9, 0.6, 1.0, 0.7, 0.5],\n",
    "    'Obstacle_factor': [1.0, 0.8, 1.0, 0.9, 0.7],\n",
    "    'Attractiveness': [4, 2, 5, 3, 1]\n",
    "})\n",
    "\n",
    "# Funktsioon kaalu arvutamiseks\n",
    "def compute_weights(alpha, beta, gamma, delta, lambd):\n",
    "    df = data.copy()\n",
    "    df['Weight'] = (\n",
    "        (df['Attractiveness'] ** alpha) *\n",
    "        (df['Road_quality'] ** beta) *\n",
    "        (df['Traffic_factor'] ** gamma) *\n",
    "        (df['Obstacle_factor'] ** delta)\n",
    "    ) / (df['Distance_km'] ** lambd)\n",
    "\n",
    "    # Visualiseerimine\n",
    "    plt.figure(figsize=(8, 5))\n",
    "    plt.bar(df['Exit'], df['Weight'], color='skyblue')\n",
    "    plt.title('Väljapääsupunktide kaalud')\n",
    "    plt.xlabel('Väljapääs')\n",
    "    plt.ylabel('Kaal')\n",
    "    plt.grid(axis='y', linestyle='--', alpha=0.7)\n",
    "    plt.show()\n",
    "\n",
    "# Interaktiivne liides\n",
    "interact(\n",
    "    compute_weights,\n",
    "    alpha=FloatSlider(value=1, min=0, max=3, step=0.1, description='α (Attractiveness)'),\n",
    "    beta=FloatSlider(value=1, min=0, max=3, step=0.1, description='β (Road quality)'),\n",
    "    gamma=FloatSlider(value=1, min=0, max=3, step=0.1, description='γ (Traffic)'),\n",
    "    delta=FloatSlider(value=1, min=0, max=3, step=0.1, description='δ (Obstacle)'),\n",
    "    lambd=FloatSlider(value=2, min=0.1, max=5, step=0.1, description='λ (Distance)')\n",
    ")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
