{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "dc130883",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from math import pi\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",
    "    'Attractiveness': [4, 2, 5, 3, 1],\n",
    "    'Road_quality': [0.9, 0.6, 1.0, 0.7, 0.5],\n",
    "    'Traffic_factor': [1.2, 0.8, 1.5, 1.0, 0.6],\n",
    "    'Obstacle_factor': [1.0, 0.8, 1.0, 0.9, 0.7],\n",
    "    'Distance_km_G1': [2.5, 6.0, 1.8, 4.2, 7.5],\n",
    "    'Distance_km_G2': [5.0, 2.0, 3.5, 1.5, 6.0]\n",
    "})\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1a76e3f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def compute_weights(alpha, beta, gamma, delta, lambd):\n",
    "    weights = []\n",
    "    for _, row in data.iterrows():\n",
    "        w1 = (row['Attractiveness']**alpha * row['Road_quality']**beta *\n",
    "              row['Traffic_factor']**gamma * row['Obstacle_factor']**delta) / (row['Distance_km_G1']**lambd)\n",
    "        w2 = (row['Attractiveness']**alpha * row['Road_quality']**beta *\n",
    "              row['Traffic_factor']**gamma * row['Obstacle_factor']**delta) / (row['Distance_km_G2']**lambd)\n",
    "        weights.append(w1 + w2)\n",
    "    data['Weight'] = weights\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f2852807",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def plot_radar():\n",
    "    categories = ['Attractiveness', 'Road_quality', 'Traffic_factor', 'Obstacle_factor']\n",
    "    N = len(categories)\n",
    "\n",
    "    angles = [n / float(N) * 2 * pi for n in range(N)]\n",
    "    angles += angles[:1]\n",
    "\n",
    "    fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))\n",
    "    for i, row in data.iterrows():\n",
    "        values = [row[cat] for cat in categories]\n",
    "        values += values[:1]\n",
    "        ax.plot(angles, values, label=f\"Exit {row['Exit']}\")\n",
    "        ax.fill(angles, values, alpha=0.1)\n",
    "    ax.set_xticks(angles[:-1])\n",
    "    ax.set_xticklabels(categories)\n",
    "    ax.set_title(\"Väljapääsupunktide tegurite radar-graafik\")\n",
    "    ax.legend(loc='upper right', bbox_to_anchor=(1.3, 1.1))\n",
    "    plt.tight_layout()\n",
    "    plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "cb116a59",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d9ba45223ab44d309a4ca6be9f9f0b48",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=1.0, description='α (Attractiveness)', max=3.0, min=0.1), FloatSlider(…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "@interact(\n",
    "    alpha=FloatSlider(value=1.0, min=0.1, max=3.0, step=0.1, description='α (Attractiveness)'),\n",
    "    beta=FloatSlider(value=1.0, min=0.1, max=3.0, step=0.1, description='β (Road quality)'),\n",
    "    gamma=FloatSlider(value=1.0, min=0.1, max=3.0, step=0.1, description='γ (Traffic)'),\n",
    "    delta=FloatSlider(value=1.0, min=0.1, max=3.0, step=0.1, description='δ (Obstacle)'),\n",
    "    lambd=FloatSlider(value=2.0, min=0.1, max=5.0, step=0.1, description='λ (Distance)')\n",
    ")\n",
    "def update(alpha, beta, gamma, delta, lambd):\n",
    "    compute_weights(alpha, beta, gamma, delta, lambd)\n",
    "    display(data[['Exit', 'Weight']])\n",
    "    plot_radar()\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
}
