diff --git a/notebooks/lscp_capacity.ipynb b/notebooks/lscp_capacity.ipynb index b51206f9..ea9fe88e 100644 --- a/notebooks/lscp_capacity.ipynb +++ b/notebooks/lscp_capacity.ipynb @@ -60,8 +60,8 @@ "execution_count": 1, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:53.041361Z", - "start_time": "2023-01-10T18:19:53.007862Z" + "end_time": "2023-01-10T23:04:25.556826Z", + "start_time": "2023-01-10T23:04:25.511104Z" } }, "outputs": [ @@ -69,7 +69,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Last updated: 2023-01-10T13:19:53.030211-05:00\n", + "Last updated: 2023-01-10T18:04:25.545436-05:00\n", "\n", "Python implementation: CPython\n", "Python version : 3.10.8\n", @@ -97,8 +97,8 @@ "execution_count": 2, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:55.712024Z", - "start_time": "2023-01-10T18:19:53.045515Z" + "end_time": "2023-01-10T23:04:27.903605Z", + "start_time": "2023-01-10T23:04:25.560503Z" } }, "outputs": [ @@ -108,15 +108,15 @@ "text": [ "Watermark: 2.3.1\n", "\n", - "spaghetti : 1.6.10\n", - "numpy : 1.23.5\n", - "geopandas : 0.12.2\n", "json : 2.0.9\n", + "pandas : 1.5.2\n", "shapely : 2.0.0\n", - "spopt : 0.4.1+200.g336f235.dirty\n", - "pulp : 2.7.0\n", + "geopandas : 0.12.2\n", + "numpy : 1.23.5\n", "matplotlib: 3.6.2\n", - "pandas : 1.5.2\n", + "pulp : 2.7.0\n", + "spopt : 0.4.1+200.g336f235.dirty\n", + "spaghetti : 1.6.10\n", "\n" ] } @@ -159,8 +159,8 @@ "execution_count": 3, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:55.720970Z", - "start_time": "2023-01-10T18:19:55.716334Z" + "end_time": "2023-01-10T23:04:27.913721Z", + "start_time": "2023-01-10T23:04:27.909758Z" } }, "outputs": [], @@ -196,8 +196,8 @@ "execution_count": 4, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:55.765767Z", - "start_time": "2023-01-10T18:19:55.723673Z" + "end_time": "2023-01-10T23:04:27.956375Z", + "start_time": "2023-01-10T23:04:27.916517Z" } }, "outputs": [], @@ -221,8 +221,8 @@ "execution_count": 5, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:55.903447Z", - "start_time": "2023-01-10T18:19:55.768948Z" + "end_time": "2023-01-10T23:04:28.075025Z", + "start_time": "2023-01-10T23:04:27.958968Z" } }, "outputs": [], @@ -235,8 +235,8 @@ "execution_count": 6, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:55.941977Z", - "start_time": "2023-01-10T18:19:55.906449Z" + "end_time": "2023-01-10T23:04:28.112687Z", + "start_time": "2023-01-10T23:04:28.078199Z" } }, "outputs": [], @@ -260,8 +260,8 @@ "execution_count": 7, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:56.137766Z", - "start_time": "2023-01-10T18:19:55.945844Z" + "end_time": "2023-01-10T23:04:28.333204Z", + "start_time": "2023-01-10T23:04:28.115708Z" } }, "outputs": [ @@ -299,8 +299,8 @@ "execution_count": 8, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:56.160565Z", - "start_time": "2023-01-10T18:19:56.144139Z" + "end_time": "2023-01-10T23:04:28.350099Z", + "start_time": "2023-01-10T23:04:28.335755Z" } }, "outputs": [], @@ -325,8 +325,8 @@ "execution_count": 9, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:56.642527Z", - "start_time": "2023-01-10T18:19:56.164585Z" + "end_time": "2023-01-10T23:04:28.837537Z", + "start_time": "2023-01-10T23:04:28.352994Z" } }, "outputs": [ @@ -372,8 +372,8 @@ "execution_count": 10, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:56.696496Z", - "start_time": "2023-01-10T18:19:56.645242Z" + "end_time": "2023-01-10T23:04:28.891494Z", + "start_time": "2023-01-10T23:04:28.840129Z" } }, "outputs": [], @@ -405,8 +405,8 @@ "execution_count": 11, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.031388Z", - "start_time": "2023-01-10T18:19:56.699040Z" + "end_time": "2023-01-10T23:04:29.218510Z", + "start_time": "2023-01-10T23:04:28.893647Z" } }, "outputs": [ @@ -449,8 +449,8 @@ "execution_count": 12, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.104495Z", - "start_time": "2023-01-10T18:19:57.033703Z" + "end_time": "2023-01-10T23:04:29.292374Z", + "start_time": "2023-01-10T23:04:29.226199Z" } }, "outputs": [ @@ -485,8 +485,8 @@ "execution_count": 13, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.112475Z", - "start_time": "2023-01-10T18:19:57.107265Z" + "end_time": "2023-01-10T23:04:29.299210Z", + "start_time": "2023-01-10T23:04:29.294422Z" } }, "outputs": [ @@ -527,8 +527,8 @@ "execution_count": 14, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.124623Z", - "start_time": "2023-01-10T18:19:57.115202Z" + "end_time": "2023-01-10T23:04:29.311349Z", + "start_time": "2023-01-10T23:04:29.301327Z" } }, "outputs": [ @@ -627,8 +627,8 @@ "execution_count": 15, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.138015Z", - "start_time": "2023-01-10T18:19:57.126446Z" + "end_time": "2023-01-10T23:04:29.327964Z", + "start_time": "2023-01-10T23:04:29.312943Z" } }, "outputs": [ @@ -724,8 +724,8 @@ "execution_count": 16, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.146725Z", - "start_time": "2023-01-10T18:19:57.140539Z" + "end_time": "2023-01-10T23:04:29.334313Z", + "start_time": "2023-01-10T23:04:29.330619Z" } }, "outputs": [], @@ -751,15 +751,15 @@ "execution_count": 17, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.193470Z", - "start_time": "2023-01-10T18:19:57.149054Z" + "end_time": "2023-01-10T23:04:29.667783Z", + "start_time": "2023-01-10T23:04:29.336901Z" } }, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 17, @@ -784,8 +784,8 @@ "execution_count": 18, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.207249Z", - "start_time": "2023-01-10T18:19:57.196684Z" + "end_time": "2023-01-10T23:04:29.682819Z", + "start_time": "2023-01-10T23:04:29.670368Z" } }, "outputs": [ @@ -878,8 +878,8 @@ "execution_count": 19, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.255221Z", - "start_time": "2023-01-10T18:19:57.209332Z" + "end_time": "2023-01-10T23:04:29.730317Z", + "start_time": "2023-01-10T23:04:29.685128Z" } }, "outputs": [], @@ -908,8 +908,8 @@ "execution_count": 20, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.302812Z", - "start_time": "2023-01-10T18:19:57.258781Z" + "end_time": "2023-01-10T23:04:29.777401Z", + "start_time": "2023-01-10T23:04:29.733472Z" } }, "outputs": [], @@ -938,8 +938,8 @@ "execution_count": 21, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.350809Z", - "start_time": "2023-01-10T18:19:57.305776Z" + "end_time": "2023-01-10T23:04:29.822844Z", + "start_time": "2023-01-10T23:04:29.780531Z" } }, "outputs": [], @@ -968,8 +968,8 @@ "execution_count": 22, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.401709Z", - "start_time": "2023-01-10T18:19:57.354465Z" + "end_time": "2023-01-10T23:04:29.873260Z", + "start_time": "2023-01-10T23:04:29.826601Z" } }, "outputs": [], @@ -998,8 +998,8 @@ "execution_count": 23, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.454028Z", - "start_time": "2023-01-10T18:19:57.404811Z" + "end_time": "2023-01-10T23:04:29.923169Z", + "start_time": "2023-01-10T23:04:29.876581Z" } }, "outputs": [], @@ -1028,8 +1028,8 @@ "execution_count": 24, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.464958Z", - "start_time": "2023-01-10T18:19:57.457511Z" + "end_time": "2023-01-10T23:04:29.933682Z", + "start_time": "2023-01-10T23:04:29.926791Z" } }, "outputs": [ @@ -1087,8 +1087,8 @@ "execution_count": 25, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.570952Z", - "start_time": "2023-01-10T18:19:57.466945Z" + "end_time": "2023-01-10T23:04:30.044786Z", + "start_time": "2023-01-10T23:04:29.935872Z" } }, "outputs": [], @@ -1192,8 +1192,8 @@ "execution_count": 26, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.583710Z", - "start_time": "2023-01-10T18:19:57.580222Z" + "end_time": "2023-01-10T23:04:30.050946Z", + "start_time": "2023-01-10T23:04:30.047184Z" } }, "outputs": [], @@ -1206,8 +1206,8 @@ "execution_count": 27, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:57.999143Z", - "start_time": "2023-01-10T18:19:57.586461Z" + "end_time": "2023-01-10T23:04:30.474871Z", + "start_time": "2023-01-10T23:04:30.053102Z" } }, "outputs": [ @@ -1247,8 +1247,8 @@ "execution_count": 28, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:58.391013Z", - "start_time": "2023-01-10T18:19:58.001811Z" + "end_time": "2023-01-10T23:04:30.896633Z", + "start_time": "2023-01-10T23:04:30.477992Z" } }, "outputs": [ @@ -1288,8 +1288,8 @@ "execution_count": 29, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:58.863044Z", - "start_time": "2023-01-10T18:19:58.393714Z" + "end_time": "2023-01-10T23:04:31.422405Z", + "start_time": "2023-01-10T23:04:30.899081Z" } }, "outputs": [ @@ -1329,8 +1329,8 @@ "execution_count": 30, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:59.275307Z", - "start_time": "2023-01-10T18:19:58.865723Z" + "end_time": "2023-01-10T23:04:31.824194Z", + "start_time": "2023-01-10T23:04:31.425265Z" } }, "outputs": [ @@ -1370,8 +1370,8 @@ "execution_count": 31, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:19:59.660217Z", - "start_time": "2023-01-10T18:19:59.278736Z" + "end_time": "2023-01-10T23:04:32.228895Z", + "start_time": "2023-01-10T23:04:31.826665Z" } }, "outputs": [ @@ -1411,8 +1411,8 @@ "execution_count": 32, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:20:00.092469Z", - "start_time": "2023-01-10T18:19:59.662886Z" + "end_time": "2023-01-10T23:04:32.641725Z", + "start_time": "2023-01-10T23:04:32.231423Z" } }, "outputs": [ @@ -1453,8 +1453,8 @@ "execution_count": 33, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:20:02.467301Z", - "start_time": "2023-01-10T18:20:00.094647Z" + "end_time": "2023-01-10T23:04:34.693483Z", + "start_time": "2023-01-10T23:04:32.644278Z" } }, "outputs": [ @@ -1501,8 +1501,8 @@ "execution_count": 34, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:20:02.473687Z", - "start_time": "2023-01-10T18:20:02.469714Z" + "end_time": "2023-01-10T23:04:34.699660Z", + "start_time": "2023-01-10T23:04:34.696062Z" } }, "outputs": [], @@ -1529,8 +1529,8 @@ "execution_count": 35, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:20:02.607861Z", - "start_time": "2023-01-10T18:20:02.476731Z" + "end_time": "2023-01-10T23:04:34.807693Z", + "start_time": "2023-01-10T23:04:34.702017Z" } }, "outputs": [], @@ -1563,8 +1563,8 @@ "execution_count": 36, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:20:02.615185Z", - "start_time": "2023-01-10T18:20:02.611192Z" + "end_time": "2023-01-10T23:04:34.814997Z", + "start_time": "2023-01-10T23:04:34.810702Z" } }, "outputs": [], @@ -1585,8 +1585,8 @@ "execution_count": 37, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:20:02.628194Z", - "start_time": "2023-01-10T18:20:02.617579Z" + "end_time": "2023-01-10T23:04:34.823001Z", + "start_time": "2023-01-10T23:04:34.817295Z" } }, "outputs": [ @@ -1633,8 +1633,8 @@ "execution_count": 38, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:20:02.641664Z", - "start_time": "2023-01-10T18:20:02.631018Z" + "end_time": "2023-01-10T23:04:34.834881Z", + "start_time": "2023-01-10T23:04:34.825818Z" } }, "outputs": [ @@ -1779,8 +1779,8 @@ "execution_count": 39, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:20:03.747326Z", - "start_time": "2023-01-10T18:20:02.644743Z" + "end_time": "2023-01-10T23:04:35.725743Z", + "start_time": "2023-01-10T23:04:34.843310Z" } }, "outputs": [ @@ -1832,8 +1832,8 @@ "execution_count": 40, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:20:04.672051Z", - "start_time": "2023-01-10T18:20:03.750221Z" + "end_time": "2023-01-10T23:04:36.585753Z", + "start_time": "2023-01-10T23:04:35.728435Z" } }, "outputs": [ @@ -1881,8 +1881,8 @@ "execution_count": 41, "metadata": { "ExecuteTime": { - "end_time": "2023-01-10T18:20:05.818278Z", - "start_time": "2023-01-10T18:20:04.675097Z" + "end_time": "2023-01-10T23:04:37.624128Z", + "start_time": "2023-01-10T23:04:36.588495Z" } }, "outputs": [ diff --git a/spopt/locate/base.py b/spopt/locate/base.py index 33ec42e6..f2ea60bb 100644 --- a/spopt/locate/base.py +++ b/spopt/locate/base.py @@ -232,11 +232,13 @@ def add_client_integer_variable( setattr(obj, "cli_vars", cli_vars) @staticmethod - def add_client_assign_integer_variable( + def add_client_assign_variable( obj: T_FacModel, range_client: range, range_facility: range, var_name: str, + low_bound=0, + up_bound=1, lp_category=pulp.LpInteger, ) -> None: """Client assignment integer decision variables (used for allocation). @@ -252,6 +254,10 @@ def add_client_assign_integer_variable( The range of facility points. var_name : str A formatted string for the client assignment variable name. + low_bound : int (default 0) + The lower bound for variable values. Set to ``None`` for no lower bound. + up_bound : int (default 1) + The upper bound for variable values. Set to ``None`` for no upper bound. lp_category : pulp.LpVariable parameter The category this variable is in, ``pulp.LpInteger`` or ``pulp.LpContinuous``. @@ -268,8 +274,8 @@ def add_client_assign_integer_variable( [ pulp.LpVariable( var_name.format(i=i, j=j), - lowBound=0, - upBound=1, + lowBound=low_bound, + upBound=up_bound, cat=lp_category, ) for j in range_facility diff --git a/spopt/locate/coverage.py b/spopt/locate/coverage.py index 2322d29c..20f9bd94 100644 --- a/spopt/locate/coverage.py +++ b/spopt/locate/coverage.py @@ -256,8 +256,13 @@ def from_cost_matrix( f"({sum_demand} > {sum_capacity})." ) - FacilityModelBuilder.add_client_assign_integer_variable( - lscp, r_cli, r_fac, "z[{i}_{j}]", lp_category=pulp.LpContinuous + FacilityModelBuilder.add_client_assign_variable( + lscp, + r_cli, + r_fac, + "z[{i}_{j}]", + up_bound=None, + lp_category=pulp.LpContinuous, ) FacilityModelBuilder.add_facility_capacity_constraint( diff --git a/spopt/locate/p_center.py b/spopt/locate/p_center.py index 32c9c13a..f4abbba6 100644 --- a/spopt/locate/p_center.py +++ b/spopt/locate/p_center.py @@ -193,7 +193,7 @@ def from_cost_matrix( p_center = PCenter(name, model, cost_matrix) FacilityModelBuilder.add_facility_integer_variable(p_center, r_fac, "y[{i}]") - FacilityModelBuilder.add_client_assign_integer_variable( + FacilityModelBuilder.add_client_assign_variable( p_center, r_cli, r_fac, "z[{i}_{j}]" ) FacilityModelBuilder.add_weight_continuous_variable(p_center) diff --git a/spopt/locate/p_median.py b/spopt/locate/p_median.py index ca327f59..74d13976 100644 --- a/spopt/locate/p_median.py +++ b/spopt/locate/p_median.py @@ -242,7 +242,7 @@ def from_cost_matrix( p_median = PMedian(name, model, aij, weights_sum) FacilityModelBuilder.add_facility_integer_variable(p_median, r_fac, "y[{i}]") - FacilityModelBuilder.add_client_assign_integer_variable( + FacilityModelBuilder.add_client_assign_variable( p_median, r_cli, r_fac, "z[{i}_{j}]" )