{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae506bdc",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "from math import log\n",
    "from math import e\n",
    "from matplotlib.patches import Patch\n",
    "from matplotlib.lines import Line2D\n",
    "from ipywidgets import interact, FloatSlider\n",
    "import plotly.graph_objects as go\n",
    "\n",
    "# Sample data for 5 exit points\n",
    "exit_data = pd.DataFrame({\n",
    "    'Exit': ['A', 'B', 'C', 'D', 'E'],\n",
    "    'Distance_km': [2.2, 5.8, 1.5, 4.0, 6.5],\n",
    "    'Traffic_factor': [1.2, 0.8, 1.5, 1.0, 0.7],\n",
    "    'Road_quality': [0.9, 0.6, 1.0, 0.7, 0.5],\n",
    "    'Obstacle_factor': [1.0, 0.7, 1.0, 0.8, 0.6],\n",
    "    'Attractiveness': [4, 2, 5, 3, 1]\n",
    "})\n",
    "\n",
    "# Function to calculate weights\n",
    "def calculate_weights(alpha, beta, gamma, delta, lambd):\n",
    "    df = exit_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",
    "    return df\n",
    "\n",
    "# Function to plot all visualizations\n",
    "def plot_all(alpha, beta, gamma, delta, lambd):\n",
    "    df = calculate_weights(alpha, beta, gamma, delta, lambd)\n",
    "\n",
    "    fig, axs = plt.subplots(2, 2, figsize=(16, 12))\n",
    "    fig.suptitle('Exit Point Weight Analysis', fontsize=16)\n",
    "\n",
    "    # Bar chart of weights\n",
    "    axs[0, 0].bar(df['Exit'], df['Weight'], color='skyblue')\n",
    "    axs[0, 0].set_title('Exit Weights')\n",
    "    axs[0, 0].set_ylabel('Weight')\n",
    "\n",
    "    # Scatter plot: Distance vs Weight\n",
    "    axs[0, 1].scatter(df['Distance_km'], df['Weight'], color='green')\n",
    "    axs[0, 1].set_title('Distance vs Weight')\n",
    "    axs[0, 1].set_xlabel('Distance (km)')\n",
    "    axs[0, 1].set_ylabel('Weight')\n",
    "\n",
    "    # Bar chart of factor contributions\n",
    "    factor_contrib = df[['Exit', 'Attractiveness', 'Road_quality', 'Traffic_factor', 'Obstacle_factor']].set_index('Exit')\n",
    "    factor_contrib.plot(kind='bar', stacked=True, ax=axs[1, 0])\n",
    "    axs[1, 0].set_title('Factor Contributions')\n",
    "    axs[1, 0].set_ylabel('Factor Value')\n",
    "\n",
    "    # Heatmap of correlations\n",
    "    sns.heatmap(df.drop(columns='Exit').corr(), annot=True, cmap='coolwarm', ax=axs[1, 1])\n",
    "    axs[1, 1].set_title('Correlation Heatmap')\n",
    "\n",
    "    plt.tight_layout(rect=[0, 0.03, 1, 0.95])\n",
    "    plt.show()\n",
    "\n",
    "    # Radar chart\n",
    "    categories = ['Attractiveness', 'Road_quality', 'Traffic_factor', 'Obstacle_factor']\n",
    "    num_vars = len(categories)\n",
    "\n",
    "    fig = go.Figure()\n",
    "    for i, row in df.iterrows():\n",
    "        values = [row[cat] for cat in categories]\n",
    "        values += values[:1]  # close the loop\n",
    "        fig.add_trace(go.Scatterpolar(\n",
    "            r=values,\n",
    "            theta=categories + [categories[0]],\n",
    "            fill='toself',\n",
    "            name=f\"Exit {row['Exit']}\"\n",
    "        ))\n",
    "\n",
    "    fig.update_layout(\n",
    "        polar=dict(\n",
    "            radialaxis=dict(visible=True, range=[0, 5])\n",
    "        ),\n",
    "        showlegend=True,\n",
    "        title='Radar Chart of Exit Factors'\n",
    "    )\n",
    "    fig.show()\n",
    "\n",
    "# Interactive sliders\n",
    "interact(\n",
    "    plot_all,\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"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 5
}
