示例#1
0
 def test_multiple_supply_arcgis(self):
     demand_col = "Population"
     demand_id_col = "GEOID10"
     supply_id_col = "ORIG_ID"
     d = arcgis.GeoAccessor.from_featureclass(
         os.path.join(self.dir_name, "../test_data/demand_point.shp"))
     s = arcgis.GeoAccessor.from_featureclass(
         os.path.join(self.dir_name,
                      "../test_data/facility_service_areas.shp"))
     s2 = arcgis.GeoAccessor.from_featureclass(
         os.path.join(self.dir_name,
                      "../test_data/facility2_service_areas.shp"))
     coverage = Coverage.from_spatially_enabled_dataframes(
         d, s, demand_id_col, supply_id_col, demand_col=demand_col)
     coverage2 = Coverage.from_spatially_enabled_dataframes(
         d,
         s2,
         demand_id_col,
         supply_id_col,
         demand_name=coverage.demand_name,
         demand_col=demand_col)
     problem = Problem.lscp([coverage, coverage2])
     problem.solve(pulp.GLPK())
     selected_locations = problem.selected_supply(coverage)
     selected_locations2 = problem.selected_supply(coverage2)
     covered_demand = d.query(
         f"{demand_id_col} in ({[f'{i}' for i in problem.selected_demand(coverage)]})"
     )
     coverage = math.ceil(
         (covered_demand[demand_col].sum() / d[demand_col].sum()) * 100)
     assert (len(selected_locations) >= 5)
     assert (len(selected_locations2) >= 17)
     assert (coverage == 100)
示例#2
0
 def test_from_coverage_sedf_invalid_demand_id_col2(
         self, demand_points_sedf, facility_service_areas_sedf):
     with pytest.raises(ValueError) as e:
         c = Coverage.from_spatially_enabled_dataframes(
             demand_points_sedf, facility_service_areas_sedf, "test",
             "ORIG_ID")
     assert (e.value.args[0] == f"'test' not in dataframe")
示例#3
0
 def test_from_coverage_sedf_invalid_supply_df(self, demand_points_sedf):
     with pytest.raises(TypeError) as e:
         c = Coverage.from_spatially_enabled_dataframes(
             demand_points_sedf, None, "GEOID10", "ORIG_ID")
     assert (
         e.value.args[0] ==
         "Expected 'Dataframe' type for supply_df, got '<class 'NoneType'>'"
     )
示例#4
0
 def test_from_coverage_sedf_invalid_supply_id_col(
         self, demand_points_sedf, facility_service_areas_sedf):
     with pytest.raises(TypeError) as e:
         c = Coverage.from_spatially_enabled_dataframes(
             demand_points_sedf, facility_service_areas_sedf, "GEOID10",
             None)
     assert (
         e.value.args[0] ==
         "Expected 'str' type for demand_id_col, got '<class 'NoneType'>'")
示例#5
0
 def test_from_coverage_sedf_invalid_demand_df(self,
                                               facility_service_areas_sedf):
     with pytest.raises(TypeError) as e:
         c = Coverage.from_spatially_enabled_dataframes(
             None, facility_service_areas_sedf, "GEOID10", "ORIG_ID")
     assert (
         e.value.args[0] ==
         "Expected 'Dataframe' type for demand_df, got '<class 'NoneType'>'"
     )
示例#6
0
 def test_from_coverage_sedf_invalid_coverage_type(
         self, demand_points_sedf, facility_service_areas_sedf):
     with pytest.raises(ValueError) as e:
         c = Coverage.from_spatially_enabled_dataframes(
             demand_points_sedf,
             facility_service_areas_sedf,
             "GEOID10",
             "ORIG_ID",
             coverage_type="test")
     assert (e.value.args[0] == "Invalid coverage type 'test'")
示例#7
0
 def test_from_coverage_sedf_demand_col(self, demand_points_sedf,
                                        facility_service_areas_sedf):
     c = Coverage.from_spatially_enabled_dataframes(
         demand_points_sedf,
         facility_service_areas_sedf,
         "GEOID10",
         "ORIG_ID",
         demand_col="Population")
     assert (isinstance(c, Coverage))
     assert c.demand_col == "Population"
示例#8
0
 def test_from_coverage_sedf_supply_name(self, demand_points_sedf,
                                         facility_service_areas_sedf):
     c = Coverage.from_spatially_enabled_dataframes(
         demand_points_sedf,
         facility_service_areas_sedf,
         "GEOID10",
         "ORIG_ID",
         supply_name="test")
     assert (isinstance(c, Coverage))
     assert c.supply_name == "test"
示例#9
0
 def test_from_spatially_enabled_dataframe_partial(
         self, demand_polygon_sedf, facility_service_areas_sedf):
     c = Coverage.from_spatially_enabled_dataframes(
         demand_polygon_sedf,
         facility_service_areas_sedf,
         "GEOID10",
         "ORIG_ID",
         coverage_type="partial",
         demand_col="Population")
     assert (isinstance(c, Coverage))
     assert (c.coverage_type == "partial")
示例#10
0
 def test_from_coverage_sedf_demand_col_required(
         self, demand_points_sedf, facility_service_areas_sedf):
     with pytest.raises(ValueError) as e:
         c = Coverage.from_spatially_enabled_dataframes(
             demand_points_sedf,
             facility_service_areas_sedf,
             "GEOID10",
             "ORIG_ID",
             coverage_type="partial")
     assert (e.value.args[0] ==
             "demand_col is required when generating partial coverage")
示例#11
0
 def test_single_supply_arcgis(self):
     demand_id_col = "GEOID10"
     supply_id_col = "ORIG_ID"
     d = arcgis.GeoAccessor.from_featureclass(
         os.path.join(self.dir_name, "../test_data/demand_point.shp"))
     s = arcgis.GeoAccessor.from_featureclass(
         os.path.join(self.dir_name,
                      "../test_data/facility_service_areas.shp"))
     coverage = Coverage.from_spatially_enabled_dataframes(
         d, s, demand_id_col, supply_id_col)
     problem = Problem.lscp(coverage)
     with pytest.raises((InfeasibleException, UndefinedException)) as e:
         problem.solve(pulp.GLPK())