Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New attributes & functionality for locate models #296

Merged
merged 14 commits into from
Nov 8, 2022
190 changes: 95 additions & 95 deletions notebooks/facloc-lscpb-real-world.ipynb

Large diffs are not rendered by default.

213 changes: 104 additions & 109 deletions notebooks/facloc-real-world.ipynb

Large diffs are not rendered by default.

140 changes: 69 additions & 71 deletions notebooks/lscp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
"\n",
"**LSCP can be written as:**\n",
"\n",
"$\\begin{array} \\displaystyle \\textbf{Minimize} & \\sum_{j=1}^{n}{x_j} && (1) \\\\\n",
"\\displaystyle \\textbf{Subject to:} & \\sum_{j\\in N_i}{x_j} \\geq 1 & \\forall i & (2) \\\\\n",
" & x_j \\in {0,1} & \\forall j & (3) \\\\ \\end{array}$\n",
"$\\begin{array} \\displaystyle \\textbf{Minimize} & \\sum_{j=1}^{n}{Y_j} && (1) \\\\\n",
"\\displaystyle \\textbf{Subject to:} & \\sum_{j\\in N_i}{Y_j} \\geq 1 & \\forall i & (2) \\\\\n",
" & Y_j \\in {0,1} & \\forall j & (3) \\\\ \\end{array}$\n",
" \n",
"$\\begin{array} \\displaystyle \\textbf{Where:}\\\\ & & \\displaystyle i & \\small = & \\textrm{index referencing nodes of the network as demand} \\\\\n",
"& & j & \\small = & \\textrm{index referencing nodes of the network as potential facility sites} \\\\\n",
"& & S & \\small = & \\textrm{maximal acceptable service distance or time standard} \\\\\n",
"& & d_{ij} & \\small = & \\textrm{shortest distance or travel time between nodes } i \\textrm{ and } j \\\\\n",
"& & N_i & \\small = & \\{j | d_{ij} < S\\} \\\\\n",
"& & x_j & \\small = & \\begin{cases} \n",
"& & Y_j & \\small = & \\begin{cases} \n",
" 1, \\text{if a facility is located at node } j\\\\\n",
" 0, \\text{otherwise} \\\\\n",
" \\end{cases} \\end{array}$\n",
" \n",
"_The formulation above is from Church and Murray (2018)._\n",
"_The formulation above is adapted from Church and Murray (2018)._\n",
"\n",
"This tutorial generates synthetic demand (clients) and facility sites near a 10x10 lattice representing a gridded urban core. Three LSCP instances are solved while varying parameters:\n",
"* `LSCP.from_cost_matrix()` with network distance as the metric\n",
Expand All @@ -43,16 +43,16 @@
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:10.288464Z",
"start_time": "2022-10-29T17:24:10.234534Z"
"end_time": "2022-10-31T15:32:40.510990Z",
"start_time": "2022-10-31T15:32:40.470045Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Last updated: 2022-10-29T13:24:10.268599-04:00\n",
"Last updated: 2022-10-31T11:32:40.499417-04:00\n",
"\n",
"Python implementation: CPython\n",
"Python version : 3.10.6\n",
Expand Down Expand Up @@ -80,8 +80,8 @@
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:12.661484Z",
"start_time": "2022-10-29T17:24:10.293029Z"
"end_time": "2022-10-31T15:32:42.811857Z",
"start_time": "2022-10-31T15:32:40.514175Z"
}
},
"outputs": [
Expand All @@ -91,14 +91,14 @@
"text": [
"Watermark: 2.3.1\n",
"\n",
"geopandas : 0.11.1\n",
"pulp : 2.6.0\n",
"matplotlib: 3.6.1\n",
"shapely : 1.8.5\n",
"spaghetti : 1.6.7\n",
"numpy : 1.23.3\n",
"json : 2.0.9\n",
"pulp : 2.6.0\n",
"geopandas : 0.11.1\n",
"spopt : 0.4.1+200.g336f235.dirty\n",
"matplotlib: 3.6.1\n",
"\n"
]
}
Expand Down Expand Up @@ -135,8 +135,8 @@
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:12.670969Z",
"start_time": "2022-10-29T17:24:12.666683Z"
"end_time": "2022-10-31T15:32:42.820099Z",
"start_time": "2022-10-31T15:32:42.816774Z"
}
},
"outputs": [],
Expand Down Expand Up @@ -172,8 +172,8 @@
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:12.710970Z",
"start_time": "2022-10-29T17:24:12.673911Z"
"end_time": "2022-10-31T15:32:42.861464Z",
"start_time": "2022-10-31T15:32:42.825154Z"
}
},
"outputs": [],
Expand All @@ -194,8 +194,8 @@
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:12.830045Z",
"start_time": "2022-10-29T17:24:12.713183Z"
"end_time": "2022-10-31T15:32:42.990479Z",
"start_time": "2022-10-31T15:32:42.867406Z"
}
},
"outputs": [],
Expand All @@ -208,8 +208,8 @@
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:12.861920Z",
"start_time": "2022-10-29T17:24:12.832378Z"
"end_time": "2022-10-31T15:32:43.024037Z",
"start_time": "2022-10-31T15:32:42.995636Z"
}
},
"outputs": [],
Expand All @@ -233,8 +233,8 @@
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:13.037097Z",
"start_time": "2022-10-29T17:24:12.864592Z"
"end_time": "2022-10-31T15:32:43.198502Z",
"start_time": "2022-10-31T15:32:43.026452Z"
}
},
"outputs": [
Expand Down Expand Up @@ -272,8 +272,8 @@
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:13.056493Z",
"start_time": "2022-10-29T17:24:13.040255Z"
"end_time": "2022-10-31T15:32:43.216912Z",
"start_time": "2022-10-31T15:32:43.200995Z"
}
},
"outputs": [],
Expand All @@ -298,8 +298,8 @@
"execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:13.587598Z",
"start_time": "2022-10-29T17:24:13.059011Z"
"end_time": "2022-10-31T15:32:43.693289Z",
"start_time": "2022-10-31T15:32:43.223962Z"
}
},
"outputs": [
Expand Down Expand Up @@ -345,8 +345,8 @@
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:13.669181Z",
"start_time": "2022-10-29T17:24:13.590864Z"
"end_time": "2022-10-31T15:32:43.775478Z",
"start_time": "2022-10-31T15:32:43.695889Z"
}
},
"outputs": [],
Expand All @@ -372,8 +372,8 @@
"execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.091403Z",
"start_time": "2022-10-29T17:24:13.675828Z"
"end_time": "2022-10-31T15:32:44.204087Z",
"start_time": "2022-10-31T15:32:43.778286Z"
}
},
"outputs": [
Expand Down Expand Up @@ -416,8 +416,8 @@
"execution_count": 12,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.158095Z",
"start_time": "2022-10-29T17:24:14.094085Z"
"end_time": "2022-10-31T15:32:44.265311Z",
"start_time": "2022-10-31T15:32:44.207037Z"
}
},
"outputs": [
Expand Down Expand Up @@ -452,8 +452,8 @@
"execution_count": 13,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.165419Z",
"start_time": "2022-10-29T17:24:14.160439Z"
"end_time": "2022-10-31T15:32:44.272033Z",
"start_time": "2022-10-31T15:32:44.268259Z"
}
},
"outputs": [
Expand Down Expand Up @@ -486,8 +486,8 @@
"execution_count": 14,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.173253Z",
"start_time": "2022-10-29T17:24:14.167907Z"
"end_time": "2022-10-31T15:32:44.277575Z",
"start_time": "2022-10-31T15:32:44.273555Z"
}
},
"outputs": [
Expand Down Expand Up @@ -527,8 +527,8 @@
"execution_count": 15,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.194494Z",
"start_time": "2022-10-29T17:24:14.175718Z"
"end_time": "2022-10-31T15:32:44.296895Z",
"start_time": "2022-10-31T15:32:44.279094Z"
}
},
"outputs": [],
Expand All @@ -550,15 +550,15 @@
"execution_count": 16,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.250171Z",
"start_time": "2022-10-29T17:24:14.196737Z"
"end_time": "2022-10-31T15:32:44.545524Z",
"start_time": "2022-10-31T15:32:44.298772Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"<spopt.locate.coverage.LSCP at 0x163b4a0e0>"
"<spopt.locate.coverage.LSCP at 0x15ad45180>"
]
},
"execution_count": 16,
Expand All @@ -583,8 +583,8 @@
"execution_count": 17,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.269096Z",
"start_time": "2022-10-29T17:24:14.253091Z"
"end_time": "2022-10-31T15:32:44.564475Z",
"start_time": "2022-10-31T15:32:44.547722Z"
}
},
"outputs": [
Expand Down Expand Up @@ -689,9 +689,7 @@
],
"source": [
"facility_points[\"dv\"] = lscp_from_cm.fac_vars\n",
"facility_points[\"dv\"] = facility_points[\"dv\"].map(\n",
" lambda x: x.name.replace(\"_\", \"\").replace(\"x\", \"y\")\n",
")\n",
"facility_points[\"dv\"] = facility_points[\"dv\"].map(lambda x: x.name.replace(\"_\", \"\"))\n",
"facilities_snapped[\"dv\"] = facility_points[\"dv\"]\n",
"facility_points"
]
Expand All @@ -712,8 +710,8 @@
"execution_count": 18,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.292897Z",
"start_time": "2022-10-29T17:24:14.271725Z"
"end_time": "2022-10-31T15:32:44.586276Z",
"start_time": "2022-10-31T15:32:44.566881Z"
}
},
"outputs": [],
Expand All @@ -735,15 +733,15 @@
"execution_count": 19,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.344817Z",
"start_time": "2022-10-29T17:24:14.295447Z"
"end_time": "2022-10-31T15:32:44.631447Z",
"start_time": "2022-10-31T15:32:44.588217Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"<spopt.locate.coverage.LSCP at 0x163a0df30>"
"<spopt.locate.coverage.LSCP at 0x15ad464d0>"
]
},
"execution_count": 19,
Expand All @@ -768,8 +766,8 @@
"execution_count": 20,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.360997Z",
"start_time": "2022-10-29T17:24:14.347038Z"
"end_time": "2022-10-31T15:32:44.647538Z",
"start_time": "2022-10-31T15:32:44.634473Z"
}
},
"outputs": [
Expand Down Expand Up @@ -895,8 +893,8 @@
"execution_count": 21,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.382118Z",
"start_time": "2022-10-29T17:24:14.362829Z"
"end_time": "2022-10-31T15:32:44.668483Z",
"start_time": "2022-10-31T15:32:44.649123Z"
}
},
"outputs": [],
Expand All @@ -918,15 +916,15 @@
"execution_count": 22,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.427486Z",
"start_time": "2022-10-29T17:24:14.384168Z"
"end_time": "2022-10-31T15:32:44.713096Z",
"start_time": "2022-10-31T15:32:44.670668Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"<spopt.locate.coverage.LSCP at 0x163b491b0>"
"<spopt.locate.coverage.LSCP at 0x15ad46830>"
]
},
"execution_count": 22,
Expand All @@ -953,8 +951,8 @@
"execution_count": 23,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.436257Z",
"start_time": "2022-10-29T17:24:14.430311Z"
"end_time": "2022-10-31T15:32:44.722587Z",
"start_time": "2022-10-31T15:32:44.716371Z"
}
},
"outputs": [
Expand Down Expand Up @@ -1012,8 +1010,8 @@
"execution_count": 24,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:14.450536Z",
"start_time": "2022-10-29T17:24:14.437943Z"
"end_time": "2022-10-31T15:32:44.737851Z",
"start_time": "2022-10-31T15:32:44.724548Z"
}
},
"outputs": [],
Expand Down Expand Up @@ -1117,8 +1115,8 @@
"execution_count": 25,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:15.216290Z",
"start_time": "2022-10-29T17:24:14.452984Z"
"end_time": "2022-10-31T15:32:45.607636Z",
"start_time": "2022-10-31T15:32:44.739700Z"
},
"scrolled": false
},
Expand Down Expand Up @@ -1160,8 +1158,8 @@
"execution_count": 26,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:15.862559Z",
"start_time": "2022-10-29T17:24:15.219646Z"
"end_time": "2022-10-31T15:32:46.224173Z",
"start_time": "2022-10-31T15:32:45.610610Z"
}
},
"outputs": [
Expand Down Expand Up @@ -1208,8 +1206,8 @@
"execution_count": 27,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:16.584010Z",
"start_time": "2022-10-29T17:24:15.865038Z"
"end_time": "2022-10-31T15:32:46.965679Z",
"start_time": "2022-10-31T15:32:46.226753Z"
}
},
"outputs": [
Expand Down Expand Up @@ -1252,8 +1250,8 @@
"execution_count": 28,
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-29T17:24:18.460691Z",
"start_time": "2022-10-29T17:24:16.586422Z"
"end_time": "2022-10-31T15:32:48.608363Z",
"start_time": "2022-10-31T15:32:46.968486Z"
}
},
"outputs": [
Expand Down
Loading