diff --git a/notebooks/04/01-dinner-seat-allocation.ipynb b/notebooks/04/01-dinner-seat-allocation.ipynb index 869ad13f..c6716a12 100644 --- a/notebooks/04/01-dinner-seat-allocation.ipynb +++ b/notebooks/04/01-dinner-seat-allocation.ipynb @@ -238,51 +238,51 @@ " \n", " \n", " 0\n", - " 0.0\n", - " 1.0\n", - " 2.0\n", + " 3.0\n", " 0.0\n", " 3.0\n", + " -0.0\n", + " 0.0\n", " \n", " \n", " 1\n", - " 3.0\n", - " 0.0\n", - " 2.0\n", " 0.0\n", + " 1.0\n", + " 1.0\n", + " 3.0\n", " 3.0\n", " \n", " \n", " 2\n", " 0.0\n", + " 2.0\n", " 0.0\n", " 0.0\n", - " 2.0\n", " 0.0\n", " \n", " \n", " 3\n", " 2.0\n", - " 3.0\n", + " 2.0\n", " 3.0\n", " 0.0\n", - " 1.0\n", + " 2.0\n", " \n", " \n", " 4\n", " 3.0\n", " 3.0\n", " 3.0\n", - " 2.0\n", - " 2.0\n", + " 1.0\n", + " 3.0\n", " \n", " \n", " 5\n", " 0.0\n", - " 1.0\n", " 0.0\n", " 0.0\n", " 0.0\n", + " 1.0\n", " \n", " \n", "\n", @@ -291,12 +291,12 @@ "text/plain": [ " table 0 table 1 table 2 table 3 table 4\n", "family \n", - "0 0.0 1.0 2.0 0.0 3.0\n", - "1 3.0 0.0 2.0 0.0 3.0\n", - "2 0.0 0.0 0.0 2.0 0.0\n", - "3 2.0 3.0 3.0 0.0 1.0\n", - "4 3.0 3.0 3.0 2.0 2.0\n", - "5 0.0 1.0 0.0 0.0 0.0" + "0 3.0 0.0 3.0 -0.0 0.0\n", + "1 0.0 1.0 1.0 3.0 3.0\n", + "2 0.0 2.0 0.0 0.0 0.0\n", + "3 2.0 2.0 3.0 0.0 2.0\n", + "4 3.0 3.0 3.0 1.0 3.0\n", + "5 0.0 0.0 0.0 0.0 1.0" ] }, "metadata": {}, @@ -456,35 +456,35 @@ " \n", " \n", " 0\n", - " 2.6\n", - " 0.0\n", + " 0.8\n", + " 0.4\n", " 2.2\n", " 0.0\n", - " 1.2\n", + " 2.6\n", " \n", " \n", " 1\n", - " 0.2\n", - " 1.8\n", " 2.6\n", - " 1.4\n", - " 2.0\n", + " 2.4\n", + " 2.6\n", + " 0.2\n", + " 0.2\n", " \n", " \n", " 2\n", + " 2.0\n", " 0.0\n", " 0.0\n", " 0.0\n", " 0.0\n", - " 2.0\n", " \n", " \n", " 3\n", + " 0.0\n", " 2.6\n", " 2.6\n", - " 2.6\n", - " 0.0\n", " 1.2\n", + " 2.6\n", " \n", " \n", " 4\n", @@ -497,10 +497,10 @@ " \n", " 5\n", " 0.0\n", - " 1.0\n", " 0.0\n", " 0.0\n", " 0.0\n", + " 1.0\n", " \n", " \n", "\n", @@ -509,12 +509,12 @@ "text/plain": [ " table 0 table 1 table 2 table 3 table 4\n", "family \n", - "0 2.6 0.0 2.2 0.0 1.2\n", - "1 0.2 1.8 2.6 1.4 2.0\n", - "2 0.0 0.0 0.0 0.0 2.0\n", - "3 2.6 2.6 2.6 0.0 1.2\n", + "0 0.8 0.4 2.2 0.0 2.6\n", + "1 2.6 2.4 2.6 0.2 0.2\n", + "2 2.0 0.0 0.0 0.0 0.0\n", + "3 0.0 2.6 2.6 1.2 2.6\n", "4 2.6 2.6 2.6 2.6 2.6\n", - "5 0.0 1.0 0.0 0.0 0.0" + "5 0.0 0.0 0.0 0.0 1.0" ] }, "metadata": {}, @@ -609,51 +609,51 @@ " \n", " \n", " 0\n", - " 3\n", - " 0\n", " 2\n", " 0\n", " 1\n", + " 0\n", + " 3\n", " \n", " \n", " 1\n", - " 0\n", " 3\n", + " 2\n", " 3\n", - " 1\n", - " 1\n", + " 0\n", + " 0\n", " \n", " \n", " 2\n", + " 2\n", " 0\n", " 0\n", " 0\n", " 0\n", - " 2\n", " \n", " \n", " 3\n", - " 2\n", - " 3\n", - " 2\n", " 0\n", + " 3\n", + " 3\n", + " 1\n", " 2\n", " \n", " \n", " 4\n", - " 3\n", " 1\n", " 3\n", " 3\n", " 3\n", + " 3\n", " \n", " \n", " 5\n", " 0\n", - " 1\n", " 0\n", " 0\n", " 0\n", + " 1\n", " \n", " \n", "\n", @@ -662,12 +662,12 @@ "text/plain": [ " table 0 table 1 table 2 table 3 table 4\n", "family \n", - "0 3 0 2 0 1\n", - "1 0 3 3 1 1\n", - "2 0 0 0 0 2\n", - "3 2 3 2 0 2\n", - "4 3 1 3 3 3\n", - "5 0 1 0 0 0" + "0 2 0 1 0 3\n", + "1 3 2 3 0 0\n", + "2 2 0 0 0 0\n", + "3 0 3 3 1 2\n", + "4 1 3 3 3 3\n", + "5 0 0 0 0 1" ] }, "metadata": {}, @@ -796,49 +796,49 @@ " \n", " \n", " 0\n", - " 0\n", - " 2\n", " 1\n", " 0\n", " 3\n", + " 1\n", + " 1\n", " \n", " \n", " 1\n", - " 0\n", - " 1\n", " 3\n", - " 1\n", + " 2\n", " 3\n", + " 0\n", + " 0\n", " \n", " \n", " 2\n", - " 2\n", " 0\n", " 0\n", " 0\n", " 0\n", + " 2\n", " \n", " \n", " 3\n", " 3\n", " 3\n", - " 3\n", " 0\n", " 0\n", + " 3\n", " \n", " \n", " 4\n", - " 3\n", " 1\n", " 3\n", " 3\n", " 3\n", + " 3\n", " \n", " \n", " 5\n", " 0\n", - " 1\n", " 0\n", + " 1\n", " 0\n", " 0\n", " \n", @@ -849,12 +849,12 @@ "text/plain": [ " table 0 table 1 table 2 table 3 table 4\n", "family \n", - "0 0 2 1 0 3\n", - "1 0 1 3 1 3\n", - "2 2 0 0 0 0\n", - "3 3 3 3 0 0\n", - "4 3 1 3 3 3\n", - "5 0 1 0 0 0" + "0 1 0 3 1 1\n", + "1 3 2 3 0 0\n", + "2 0 0 0 0 2\n", + "3 3 3 0 0 3\n", + "4 1 3 3 3 3\n", + "5 0 0 1 0 0" ] }, "metadata": {}, @@ -973,18 +973,18 @@ " \n", " 0\n", " 0\n", - " 3\n", - " 0\n", + " 1\n", + " 2\n", " 0\n", " 3\n", " \n", " \n", " 1\n", - " 1\n", - " 1\n", " 3\n", - " 0\n", + " 2\n", " 3\n", + " 0\n", + " 0\n", " \n", " \n", " 2\n", @@ -996,11 +996,11 @@ " \n", " \n", " 3\n", - " 3\n", - " 3\n", " 2\n", - " 1\n", + " 3\n", " 0\n", + " 1\n", + " 3\n", " \n", " \n", " 4\n", @@ -1012,8 +1012,8 @@ " \n", " \n", " 5\n", - " 1\n", " 0\n", + " 1\n", " 0\n", " 0\n", " 0\n", @@ -1025,12 +1025,12 @@ "text/plain": [ " table 0 table 1 table 2 table 3 table 4\n", "family \n", - "0 0 3 0 0 3\n", - "1 1 1 3 0 3\n", + "0 0 1 2 0 3\n", + "1 3 2 3 0 0\n", "2 0 0 2 0 0\n", - "3 3 3 2 1 0\n", + "3 2 3 0 1 3\n", "4 3 1 3 3 3\n", - "5 1 0 0 0 0" + "5 0 1 0 0 0" ] }, "metadata": {}, @@ -1142,10 +1142,10 @@ " \n", " \n", " t0\n", - " 3\n", + " 1\n", " 0\n", " 0\n", - " 1\n", + " 3\n", " 3\n", " 1\n", " \n", @@ -1160,28 +1160,28 @@ " \n", " \n", " t2\n", - " 0\n", - " 3\n", " 1\n", " 3\n", + " 0\n", + " 3\n", " 3\n", " 0\n", " \n", " \n", " t3\n", - " 0\n", " 1\n", " 0\n", " 0\n", + " 0\n", " 3\n", " 0\n", " \n", " \n", " t4\n", " 3\n", + " 3\n", " 2\n", - " 1\n", - " 2\n", + " 0\n", " 1\n", " 0\n", " \n", @@ -1191,11 +1191,11 @@ ], "text/plain": [ " f0 f1 f2 f3 f4 f5\n", - "t0 3 0 0 1 3 1\n", + "t0 1 0 0 3 3 1\n", "t1 0 2 0 3 3 0\n", - "t2 0 3 1 3 3 0\n", - "t3 0 1 0 0 3 0\n", - "t4 3 2 1 2 1 0" + "t2 1 3 0 3 3 0\n", + "t3 1 0 0 0 3 0\n", + "t4 3 3 2 0 1 0" ] }, "execution_count": 10, @@ -1249,17 +1249,33 @@ "name": "stdout", "output_type": "stream", "text": [ - "CPU times: user 405 µs, sys: 8 µs, total: 413 µs\n", - "Wall time: 414 µs\n", - "CPU times: user 3.9 ms, sys: 5.22 ms, total: 9.13 ms\n", - "Wall time: 16.3 ms\n" + "CPU times: user 478 μs, sys: 4 μs, total: 482 μs\n", + "Wall time: 486 μs\n" ] } ], "source": [ - "%time flow_value, flow_dict = nx.maximum_flow(G, 'door', 'seat')\n", - "\n", - "%time results, seatplan = seating_allocation_maximize_flow_to_tables(members=[6, 8, 2, 9, 13, 1], capacity=[8, 8, 10, 4, 9], kmax=3, domain=pyo.NonNegativeIntegers)" + "%time flow_value, flow_dict = nx.maximum_flow(G, 'door', 'seat')" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CPU times: user 4.98 ms, sys: 2.68 ms, total: 7.66 ms\n", + "Wall time: 4.49 ms\n" + ] + } + ], + "source": [ + "%%time \n", + "m = seating_allocation_maximize_flow_to_tables(members=[6, 8, 2, 9, 13, 1], capacity=[8, 8, 10, 4, 9], kmax=3, domain=pyo.NonNegativeIntegers)\n", + "_ = SOLVER.solve(m)" ] }, { @@ -1273,9 +1289,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "22cb37210d5e4c73abcb38ef5efd0346", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + " 0%| | 0/49 [00:00 solver plugin - gurobi message=Could not create Model - gurobi message=License expired 2024-02-22\n\nSet parameter Username\n", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mApplicationError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[13], line 53\u001b[0m\n\u001b[1;32m 51\u001b[0m Reset(model)\n\u001b[1;32m 52\u001b[0m t \u001b[38;5;241m=\u001b[39m pc()\n\u001b[0;32m---> 53\u001b[0m \u001b[43mgurobi\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msolve\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 54\u001b[0m df\u001b[38;5;241m.\u001b[39mloc[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgurobi\u001b[39m\u001b[38;5;124m\"\u001b[39m][(n, m)] \u001b[38;5;241m=\u001b[39m pc() \u001b[38;5;241m-\u001b[39m t\n\u001b[1;32m 55\u001b[0m t \u001b[38;5;241m=\u001b[39m pc()\n", + "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/mo-book-rd3A6LPh-py3.10/lib/python3.10/site-packages/pyomo/solvers/plugins/solvers/direct_solver.py:75\u001b[0m, in \u001b[0;36mDirectSolver.solve\u001b[0;34m(self, *args, **kwds)\u001b[0m\n\u001b[1;32m 72\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msolve\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwds):\n\u001b[1;32m 73\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Solve the problem\"\"\"\u001b[39;00m\n\u001b[0;32m---> 75\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mavailable\u001b[49m\u001b[43m(\u001b[49m\u001b[43mexception_flag\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 76\u001b[0m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[1;32m 77\u001b[0m \u001b[38;5;66;03m# If the inputs are models, then validate that they have been\u001b[39;00m\n\u001b[1;32m 78\u001b[0m \u001b[38;5;66;03m# constructed! Collect suffix names to try and import from solution.\u001b[39;00m\n\u001b[1;32m 79\u001b[0m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[1;32m 80\u001b[0m _model \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n", + "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/mo-book-rd3A6LPh-py3.10/lib/python3.10/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py:232\u001b[0m, in \u001b[0;36mGurobiDirect.available\u001b[0;34m(self, exception_flag)\u001b[0m\n\u001b[1;32m 230\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m exception_flag:\n\u001b[1;32m 231\u001b[0m logger\u001b[38;5;241m.\u001b[39mwarning(msg)\n\u001b[0;32m--> 232\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ApplicationError(\n\u001b[1;32m 233\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCould not create Model for \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m solver plugin - gurobi message=\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 234\u001b[0m \u001b[38;5;241m%\u001b[39m (\u001b[38;5;28mtype\u001b[39m(\u001b[38;5;28mself\u001b[39m), msg)\n\u001b[1;32m 235\u001b[0m )\n\u001b[1;32m 236\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 237\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m\n", + "\u001b[0;31mApplicationError\u001b[0m: Could not create Model for solver plugin - gurobi message=Could not create Model - gurobi message=License expired 2024-02-22\n\nSet parameter Username\n" + ] + } + ], "source": [ "from tqdm.notebook import tqdm\n", "from time import perf_counter as pc\n", @@ -1350,7 +1403,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, "outputs": [ {