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

LSCP-B #259

Merged
merged 71 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
6d3672d
create add_backup_covering_constraint method
erinrolson Jun 22, 2022
1a06083
create LSCPB object
erinrolson Jun 22, 2022
70d35d5
post mtg changes
erinrolson Jun 22, 2022
5be9d0d
remove cov_minimun variable
erinrolson Jun 22, 2022
c21f3dd
testing
erinrolson Jun 22, 2022
4571d32
test
erinrolson Jun 22, 2022
b39c23d
remove dev comments and test class
erinrolson Jun 23, 2022
d7fd196
add LSCPB
erinrolson Jun 23, 2022
41d479b
remove add_backup_covering_constraint()
erinrolson Jun 23, 2022
b9f9008
add add_backup_covering_constraint, enhance LSCPB
erinrolson Jun 23, 2022
c852dcc
add comments and print messages to undrstnd error
erinrolson Jun 23, 2022
8f7a189
fix attribute error scoping and remove comments
erinrolson Jun 24, 2022
af29ab7
remove notes and update comments
erinrolson Jun 27, 2022
88ecf7f
update code notes
erinrolson Jun 27, 2022
630a114
add solver to from_geodataframe
erinrolson Jun 28, 2022
e958672
remove dev notes and update example
erinrolson Jun 28, 2022
6247f5d
run Black on coverage.py
erinrolson Jun 29, 2022
e04e228
remove inline comments from backup covering constraint method
erinrolson Jun 29, 2022
7be0aaa
remove inline comments from cost matrix class method
erinrolson Jun 29, 2022
d8f74aa
add lscp_obj_value attribute to LSCPB and alter LN 491 to set attribute
erinrolson Jun 29, 2022
f087f8f
lscpb.lscp_obj_value after object instantiation
erinrolson Jun 30, 2022
09a2f2c
copy test_locate.py file and rename test_lscpb.py
erinrolson Jul 5, 2022
f6cb3f4
remove all non-lscp tests from file
erinrolson Jul 5, 2022
5d04e2b
trans test_lscpb_from_cost_matrix to lscpb params
erinrolson Jul 5, 2022
214723a
update class methods for LSCPB
erinrolson Jul 5, 2022
d54a78f
update for LSCPB
erinrolson Jul 5, 2022
b1cf5d5
remove unnecessary class methods
erinrolson Jul 6, 2022
211a23c
create lscpb_cli2fac pickle file
erinrolson Jul 11, 2022
3aacbd8
rename new pickle file
erinrolson Jul 11, 2022
27d2da5
create lscpb_cli2fac pickle file
erinrolson Jul 11, 2022
62db449
create lscpb_geodataframe_fac2cli.pkl file
erinrolson Jul 11, 2022
0b219bb
new file created
erinrolson Jul 11, 2022
e1a9983
testing preselected fac_cli_array
erinrolson Jul 11, 2022
b3acae4
testing preselected fac2cli array
erinrolson Jul 11, 2022
42d2e00
add inline dev notes
erinrolson Jul 13, 2022
d482ea0
create copies of .csv's to modify data
erinrolson Jul 13, 2022
d179225
updated tests
erinrolson Jul 18, 2022
6483b68
remove print dev tests
erinrolson Jul 18, 2022
e7c1af7
create notebook and resolve errors to run
erinrolson Jul 18, 2022
4f2a9a6
add lscp-b to notebook
erinrolson Jul 18, 2022
08c2d59
create file just solving LSCPB for comparison
erinrolson Jul 18, 2022
f42e360
self.assertRaises(RuntimeError) to begin of funct
erinrolson Jul 19, 2022
773af09
run black
erinrolson Jul 19, 2022
cee8d51
remove nested assert runtime error
erinrolson Jul 20, 2022
c638a00
reduce line widths on plot
erinrolson Jul 21, 2022
8c59a6a
modify marrkers
erinrolson Jul 22, 2022
72512b4
remove comments and unnecessary variables
erinrolson Jul 24, 2022
3e2a6d5
started basic lscpb notebook
erinrolson Jul 24, 2022
8028510
add check for predef fac array when creating LSCP
erinrolson Jul 25, 2022
0c78f32
remmove dev notes
erinrolson Jul 25, 2022
fb514de
set service_radius to org val, created nw pkl file
erinrolson Jul 25, 2022
5e4da20
run black formatting
erinrolson Jul 25, 2022
4288bf1
formulate LSCP-B equation
erinrolson Jul 26, 2022
48d6a40
add formulation definition
erinrolson Jul 26, 2022
d9a5a86
add Daskin, Stern citation
erinrolson Jul 26, 2022
685d60f
Update tutorial description
erinrolson Jul 26, 2022
6ef826b
remove legacy code
erinrolson Jul 26, 2022
20a9c4a
update descriptions, create new plot function
erinrolson Jul 26, 2022
6ab3645
remove dev comments
erinrolson Jul 26, 2022
6426762
remove .coverage file
erinrolson Jul 27, 2022
d2a023b
change max service radius - gdf
erinrolson Jul 27, 2022
9439e7c
change service_dist from 5000 to 8000
erinrolson Jul 27, 2022
b94d39d
remove '$$' tags
erinrolson Jul 27, 2022
e92d9c0
rerun notebook
erinrolson Jul 27, 2022
6cd2f14
run lscpb notebook
erinrolson Jul 29, 2022
14e31c8
add facility constraint test
erinrolson Jul 29, 2022
1173e56
run black
erinrolson Jul 29, 2022
f57741e
add backup covering constraint
erinrolson Aug 4, 2022
5e0b0bc
add covering constraint
erinrolson Aug 4, 2022
1b61f87
remove backup covering constraint
erinrolson Aug 4, 2022
6888fcc
update tests
erinrolson Aug 4, 2022
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
1,367 changes: 1,367 additions & 0 deletions notebooks/facloc-lscpb-real-world.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions notebooks/lscp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,10 @@
],
"metadata": {
"interpreter": {
"hash": "31b88bb145573cdebdaa7fd72fef7949ecb3dda26d5e10d4ccc660a5d07787a7"
"hash": "56b72aab97c5d88c22a6bf5872989e2e65e9296dc12395fbfb8350007c775deb"
},
"kernelspec": {
"display_name": "Python 3.9.9 ('spopt')",
"display_name": "Python 3.8.13 ('geo_env')",
"language": "python",
"name": "python3"
},
Expand All @@ -923,7 +923,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
"version": "3.8.13"
}
},
"nbformat": 4,
Expand Down
1,098 changes: 1,098 additions & 0 deletions notebooks/lscpb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spopt/locate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .base import BaseOutputMixin, CoveragePercentageMixin, MeanDistanceMixin
from .coverage import LSCP, MCLP
from .coverage import LSCP, MCLP, LSCPB
from .p_median import PMedian
from .p_center import PCenter
from .util import simulated_geo_points
68 changes: 64 additions & 4 deletions spopt/locate/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def client_facility_array(self) -> None:
for fac_site in self.fac2cli[i]:
self.cli2fac[fac_site].append(i)
else:
raise AttributeError("The attribute `fac2cli` is not set. See `facility_client_array` method to set the attribute")
raise AttributeError(
"The attribute `fac2cli` is not set. See `facility_client_array` method to set the attribute"
)


class CoveragePercentageMixin:
"""
Expand Down Expand Up @@ -103,8 +106,9 @@ def uncovered_clients(self) -> None:

self.n_cli_uncov = self.aij.shape[0] - len(set_cov)
else:
raise AttributeError("The attribute `fac2cli` is not set. See `facility_client_array` method to set the attribute")

raise AttributeError(
"The attribute `fac2cli` is not set. See `facility_client_array` method to set the attribute"
)

def get_percentage(self):
"""
Expand All @@ -113,7 +117,10 @@ def get_percentage(self):
if hasattr(self, "n_cli_uncov"):
self.percentage = 1 - (self.n_cli_uncov / self.aij.shape[0])
else:
raise AttributeError("The attribute `n_cli_uncov` is not set. See `uncovered_clients` method to set the attribute.")
raise AttributeError(
"The attribute `n_cli_uncov` is not set. See `uncovered_clients` method to set the attribute."
)


class MeanDistanceMixin:
"""
Expand Down Expand Up @@ -291,6 +298,59 @@ def add_set_covering_constraint(
"before setting constraints must set facility variable"
)

@staticmethod
def add_backup_covering_constraint(
obj: T_FacModel,
model: pulp.LpProblem,
ni: np.array,
range_facility: range,
range_client: range,
) -> None:
"""
backup covering constraint:
- coverage_0 + facility_1 + facility_3 + facility_4 + facility_6 + facility_7 + facility_9 >= 1

Parameters
----------
obj: T_FacModel
bounded type of LocateSolver class
model: pulp.LpProblem
optimization model problem
ni: np.array
two-dimensional array that defines candidate sites between facility points within a distance to supply {i}
demand point
range_facility: range
range of facility points quantity
range_client: range
range of demand points quantity
Returns
-------
None

"""
if hasattr(obj, "fac_vars"):
fac_vars = getattr(obj, "fac_vars")
cli_vars = getattr(obj, "cli_vars")
for i in range_client:
if sum(ni[i]) >= 2:
model += (
pulp.lpSum(
[int(ni[i][j]) * fac_vars[j] for j in range_facility]
)
>= 1 + 1 * cli_vars[i]
)
else:
model += (
pulp.lpSum(
[int(ni[i][j]) * fac_vars[j] for j in range_facility]
)
>= 1 + 0 * cli_vars[i]
)
else:
raise AttributeError(
"before setting constraints must set facility variable"
)

@staticmethod
def add_facility_constraint(
obj: T_FacModel, model: pulp.LpProblem, p_facilities: int
Expand Down
Loading