{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9250a350-5f2d-4971-b614-1751bc3c1d1b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-06-04T09:26:05.453435Z",
     "iopub.status.busy": "2025-06-04T09:26:05.452564Z",
     "iopub.status.idle": "2025-06-04T09:26:08.822088Z",
     "shell.execute_reply": "2025-06-04T09:26:08.818690Z",
     "shell.execute_reply.started": "2025-06-04T09:26:05.453359Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HiGHS 1.10.0HiGHS 1.10.0: optimal solution; objective 1200\n",
      "0 simplex iterations\n",
      "0 barrier iterations\n",
      "Objective value (Total Profit): 1200.0\n",
      "Production plan:\n",
      "  A = 0.0\n",
      "  B = 40.0\n"
     ]
    }
   ],
   "source": [
    "from amplpy import AMPL, Environment\n",
    "\n",
    "# Use default environment\n",
    "env = Environment()\n",
    "ampl = AMPL(env)\n",
    "\n",
    "# Set the solver\n",
    "ampl.setOption('solver', 'highs')  # or 'cbc', 'gurobi', 'cplex' if installed\n",
    "\n",
    "# Define the model\n",
    "ampl.eval(r\"\"\"\n",
    "set PRODUCTS;\n",
    "param profit {PRODUCTS};\n",
    "param labor {PRODUCTS};\n",
    "param total_labor;\n",
    "\n",
    "var Production {PRODUCTS} >= 0;\n",
    "\n",
    "maximize TotalProfit:\n",
    "    sum {p in PRODUCTS} profit[p] * Production[p];\n",
    "\n",
    "subject to LaborLimit:\n",
    "    sum {p in PRODUCTS} labor[p] * Production[p] <= total_labor;\n",
    "\"\"\")\n",
    "\n",
    "# Load data\n",
    "ampl.set['PRODUCTS'] = ['A', 'B']\n",
    "ampl.param['profit'] = {'A': 20, 'B': 30}\n",
    "ampl.param['labor'] = {'A': 2, 'B': 1}\n",
    "ampl.param['total_labor'] = 40\n",
    "\n",
    "# Solve\n",
    "ampl.solve()\n",
    "\n",
    "# Show results\n",
    "print(\"Objective value (Total Profit):\", ampl.obj['TotalProfit'].value())\n",
    "print(\"Production plan:\")\n",
    "for p in ampl.set['PRODUCTS']:\n",
    "    print(f\"  {p} = {ampl.var['Production'][p].value()}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2336568c-aed4-437d-aecc-7b1f799f3222",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (venv)",
   "language": "python",
   "name": "venv"
  },
  "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.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
