Skip to content

Fix: properly render P-Median model formulation in docs (#466) #483

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

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 63 additions & 42 deletions notebooks/p-median.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,38 @@
"\n",
"**P-Median can be written as:**\n",
"\n",
"$\\begin{array} \\displaystyle \\textbf{Minimize} & \\displaystyle \\sum_{i \\in I}\\sum_{j \\in J}{a_i d_{ij} X_{ij}} &&& (1) \\\\\n",
"\\displaystyle \\textbf{Subject to:} & \\displaystyle \\sum_{j \\in J}{X_{ij} = 1} & \\forall i \\in I && (2) \\\\\n",
" & \\displaystyle \\sum_{j \\in J}{Y_{j} = p} &&& (3) \\\\\n",
" & X_{ij} \\leq Y_{j} & \\forall i \\in I & \\forall j \\in J & (4) \\\\\n",
" & X_{ij} \\in \\{0,1\\} & \\forall i \\in I & \\forall j \\in J & (5) \\\\\n",
" & Y_{j} \\in \\{0,1\\} & \\forall j \\in J && (6) \\\\ \\end{array}$\n",
"$$\n",
"\\begin{array}{lllll}\n",
"\\textbf{Minimize} & \\displaystyle \\sum_{i \\in I} \\sum_{j \\in J} a_i d_{ij} X_{ij} &&& (1) \\\\\n",
"\\textbf{Subject to:} & \\sum_{j \\in J} X_{ij} = 1 & \\forall i \\in I && (2) \\\\\n",
"& \\sum_{j \\in J} Y_j = p &&& (3) \\\\\n",
"& X_{ij} \\leq Y_j & \\forall i \\in I, j \\in J && (4) \\\\\n",
"& X_{ij} \\in \\{0, 1\\} & \\forall i \\in I, j \\in J && (5) \\\\\n",
"& Y_j \\in \\{0, 1\\} & \\forall j \\in J && (6) \\\\\n",
"\\end{array}\n",
"$$\n",
"\n",
"$$\n",
"\\begin{array}{lllll}\n",
"\\textbf{Where:} \\\\\n",
"& i & = & \\text{index referencing demand nodes} \\\\\n",
"& j & = & \\text{index referencing potential facility sites} \\\\\n",
"& d_{ij} & = & \\text{distance or travel time between node } i \\text{ and } j \\\\\n",
"& p & = & \\text{number of facilities to locate} \\\\\n",
"& a_i & = & \\text{demand at node } i \\\\\n",
"& X_{ij} & = &\n",
" \\begin{cases}\n",
" 1, & \\text{if demand } i \\text{ is assigned to facility } j \\\\\n",
" 0, & \\text{otherwise}\n",
" \\end{cases} \\\\\n",
"& Y_j & = &\n",
" \\begin{cases}\n",
" 1, & \\text{if facility is located at node } j \\\\\n",
" 0, & \\text{otherwise}\n",
" \\end{cases}\n",
"\\end{array}\n",
"$$\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",
"& & d_{ij} & \\small = & \\textrm{shortest distance or travel time between nodes } i \\textrm{ and } j \\\\\n",
"& & p & \\small = & \\textrm{number of facilities to be located} \\\\\n",
"& & a_i & \\small = & \\textrm{service load or population demand at } i \\\\\n",
"& & X_{ij} & \\small = & \\begin{cases}\n",
" 1, \\textrm{if demand } i \\textrm{ is assigned to facility } j \\\\\n",
" 0, \\textrm{otherwise}\n",
" \\end{cases} \\\\\n",
"& & Y_{j} & \\small = & \\begin{cases}\n",
" 1, \\textrm{if node } j \\textrm{ has been selected for a facility} \\\\\n",
" 0, \\textrm{otherwise} \\\\\n",
" \\end{cases} \\\\ \n",
"\\end{array}$\n",
"\n",
"_The formulation above is adapted from Church and Murray (2018)_\n",
"\n",
Expand Down Expand Up @@ -1696,29 +1707,39 @@
"\n",
"**Capacitated P-Median can be written as:**\n",
"\n",
"$\\begin{array} \\displaystyle \\textbf{Minimize} & \\displaystyle \\sum_{i \\in I}\\sum_{j \\in J}{a_i d_{ij} X_{ij}} &&& (1) \\\\\n",
"\\displaystyle \\textbf{Subject to:} & \\displaystyle \\sum_{j \\in J}{X_{ij} = 1} & \\forall i \\in I && (2) \\\\\n",
" & \\displaystyle \\sum_{j \\in J}{Y_{j} = p} &&& (3) \\\\\n",
" & \\displaystyle \\sum_{i \\in I}{a_i X_{ij} \\leq {c_j Y_{j}}}& \\forall j \\in J && (4) \\\\\n",
" & X_{ij} \\leq Y_{j} & \\forall i \\in I & \\forall j \\in J & (5) \\\\\n",
" & X_{ij} \\in \\{0,1\\} & \\forall i \\in I & \\forall j \\in J & (6) \\\\\n",
" & Y_{j} \\in \\{0,1\\} & \\forall j \\in J && (7) \\\\ \\end{array}$\n",
"$$\n",
"\\begin{array}{lllll}\n",
"\\textbf{Minimize} & \\displaystyle \\sum_{i \\in I} \\sum_{j \\in J} a_i d_{ij} X_{ij} &&& (1) \\\\\n",
"\\textbf{Subject to:} & \\sum_{j \\in J} X_{ij} = 1 & \\forall i \\in I && (2) \\\\\n",
"& \\sum_{j \\in J} Y_j = p &&& (3) \\\\\n",
"& \\sum_{i \\in I} a_i X_{ij} \\leq c_j Y_j & \\forall j \\in J && (4) \\\\\n",
"& X_{ij} \\leq Y_j & \\forall i \\in I, j \\in J && (5) \\\\\n",
"& X_{ij} \\in \\{0, 1\\} & \\forall i \\in I, j \\in J && (6) \\\\\n",
"& Y_j \\in \\{0, 1\\} & \\forall j \\in J && (7) \\\\\n",
"\\end{array}\n",
"$$\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",
"& & d_{ij} & \\small = & \\textrm{shortest distance or travel time between nodes } i \\textrm{ and } j \\\\\n",
"& & p & \\small = & \\textrm{number of facilities to be located} \\\\\n",
"& & a_i & \\small = & \\textrm{service load or population demand at } i \\\\\n",
"& & c_j & \\small = & \\textrm{capacity of facility} j \\\\\n",
"& & X_{ij} & \\small = & \\begin{cases}\n",
" 1, \\textrm{if demand } i \\textrm{ is assigned to facility } j \\\\\n",
" 0, \\textrm{otherwise}\n",
" \\end{cases} \\\\\n",
"& & Y_{j} & \\small = & \\begin{cases}\n",
" 1, \\textrm{if node } j \\textrm{ has been selected for a facility} \\\\\n",
" 0, \\textrm{otherwise} \\\\\n",
" \\end{cases} \\\\ \n",
"\\end{array}$\n",
"$$\n",
"\\begin{array}{lllll}\n",
"\\textbf{Where:} \\\\\n",
"& i & = & \\text{index referencing demand nodes} \\\\\n",
"& j & = & \\text{index referencing potential facility sites} \\\\\n",
"& d_{ij} & = & \\text{distance or travel time between nodes } i \\text{ and } j \\\\\n",
"& p & = & \\text{number of facilities to locate} \\\\\n",
"& a_i & = & \\text{demand at node } i \\\\\n",
"& c_j & = & \\text{capacity of facility at node } j \\\\\n",
"& X_{ij} & = &\n",
" \\begin{cases}\n",
" 1, & \\text{if demand } i \\text{ is assigned to facility } j \\\\\n",
" 0, & \\text{otherwise}\n",
" \\end{cases} \\\\\n",
"& Y_j & = &\n",
" \\begin{cases}\n",
" 1, & \\text{if facility is located at node } j \\\\\n",
" 0, & \\text{otherwise}\n",
" \\end{cases}\n",
"\\end{array}\n",
"$$\n",
"\n",
"_The formulation above is adapted from Church and Murray (2009)_"
]
Expand Down