コード例 #1
0
 def test_from_coverage_dataframe_invalid_demand_id_col2(
         self, demand_points_dataframe, facility_service_areas_dataframe):
     with pytest.raises(ValueError) as e:
         c = Coverage.from_geodataframes(demand_points_dataframe,
                                         facility_service_areas_dataframe,
                                         "test", "ORIG_ID")
     assert (e.value.args[0] == f"'test' not in dataframe")
コード例 #2
0
 def test_from_coverage_dataframe_invalid_supply_id_col(
         self, demand_points_dataframe, facility_service_areas_dataframe):
     with pytest.raises(TypeError) as e:
         c = Coverage.from_geodataframes(demand_points_dataframe,
                                         facility_service_areas_dataframe,
                                         "GEOID10", None)
     assert (
         e.value.args[0] ==
         "Expected 'str' type for demand_id_col, got '<class 'NoneType'>'")
コード例 #3
0
 def test_from_coverage_dataframe_invalid_coverage_type(
         self, demand_points_dataframe, facility_service_areas_dataframe):
     with pytest.raises(ValueError) as e:
         c = Coverage.from_geodataframes(demand_points_dataframe,
                                         facility_service_areas_dataframe,
                                         "GEOID10",
                                         "ORIG_ID",
                                         coverage_type="test")
     assert (e.value.args[0] == "Invalid coverage type 'test'")
コード例 #4
0
 def test_from_coverage_dataframe_invalid_supply_df(
         self, demand_points_dataframe):
     with pytest.raises(TypeError) as e:
         c = Coverage.from_geodataframes(demand_points_dataframe, None,
                                         "GEOID10", "ORIG_ID")
     assert (
         e.value.args[0] ==
         "Expected 'Dataframe' type for supply_df, got '<class 'NoneType'>'"
     )
コード例 #5
0
 def test_from_coverage_dataframe_demand_col(
         self, demand_points_dataframe, facility_service_areas_dataframe):
     c = Coverage.from_geodataframes(demand_points_dataframe,
                                     facility_service_areas_dataframe,
                                     "GEOID10",
                                     "ORIG_ID",
                                     demand_col="Population")
     assert (isinstance(c, Coverage))
     assert c.demand_col == "Population"
コード例 #6
0
 def test_from_coverage_dataframe_supply_name(
         self, demand_points_dataframe, facility_service_areas_dataframe):
     c = Coverage.from_geodataframes(demand_points_dataframe,
                                     facility_service_areas_dataframe,
                                     "GEOID10",
                                     "ORIG_ID",
                                     supply_name="test")
     assert (isinstance(c, Coverage))
     assert c.supply_name == "test"
コード例 #7
0
 def test_from_coverage_dataframe_partial(self, demand_polygon_dataframe,
                                          facility_service_areas_dataframe):
     c = Coverage.from_geodataframes(demand_polygon_dataframe,
                                     facility_service_areas_dataframe,
                                     "GEOID10",
                                     "ORIG_ID",
                                     coverage_type="partial",
                                     demand_col="Population")
     assert (isinstance(c, Coverage))
     assert (c.coverage_type == "partial")
コード例 #8
0
 def test_from_coverage_dataframe_invalid_demand_df(
         self, facility_service_areas_dataframe):
     with pytest.raises(TypeError) as e:
         c = Coverage.from_geodataframes(None,
                                         facility_service_areas_dataframe,
                                         "GEOID10", "ORIG_ID")
     assert (
         e.value.args[0] ==
         "Expected 'Dataframe' type for demand_df, got '<class 'NoneType'>'"
     )
コード例 #9
0
 def test_from_coverage_dataframe_demand_col_required(
         self, demand_points_dataframe, facility_service_areas_dataframe):
     with pytest.raises(ValueError) as e:
         c = Coverage.from_geodataframes(demand_points_dataframe,
                                         facility_service_areas_dataframe,
                                         "GEOID10",
                                         "ORIG_ID",
                                         coverage_type="partial")
     assert (e.value.args[0] ==
             "demand_col is required when generating partial coverage")
コード例 #10
0
ファイル: test_mclp.py プロジェクト: pankababukova/allagash
 def test_multiple_supply(self):
     demand_id_col = "GEOID10"
     supply_id_col = "ORIG_ID"
     demand_col = "Population"
     d = geopandas.read_file(
         os.path.join(self.dir_name, "../test_data/demand_point.shp"))
     s = geopandas.read_file(
         os.path.join(self.dir_name,
                      "../test_data/facility_service_areas.shp"))
     s2 = geopandas.read_file(
         os.path.join(self.dir_name,
                      "../test_data/facility2_service_areas.shp"))
     coverage = Coverage.from_geodataframes(d,
                                            s,
                                            demand_id_col,
                                            supply_id_col,
                                            demand_col=demand_col)
     coverage2 = Coverage.from_geodataframes(
         d,
         s2,
         demand_id_col,
         supply_id_col,
         demand_col=demand_col,
         demand_name=coverage.demand_name)
     problem = Problem.mclp([coverage, coverage2],
                            max_supply={
                                coverage: 5,
                                coverage2: 10
                            })
     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)]})"
     )
     result = math.ceil(
         (covered_demand[demand_col].sum() / d[demand_col].sum()) * 100)
     assert (len(selected_locations) == 5)
     assert (len(selected_locations2) == 10)
     assert result == 96
コード例 #11
0
ファイル: test_lscp.py プロジェクト: pankababukova/allagash
 def test_single_supply(self):
     demand_id_col = "GEOID10"
     supply_id_col = "ORIG_ID"
     d = geopandas.read_file(
         os.path.join(self.dir_name, "../test_data/demand_point.shp"))
     s = geopandas.read_file(
         os.path.join(self.dir_name,
                      "../test_data/facility_service_areas.shp"))
     coverage = Coverage.from_geodataframes(d, s, demand_id_col,
                                            supply_id_col)
     problem = Problem.lscp(coverage)
     with pytest.raises((InfeasibleException, UndefinedException)) as e:
         problem.solve(pulp.GLPK())
コード例 #12
0
ファイル: test_mclp.py プロジェクト: pankababukova/allagash
 def test_single_supply(self):
     demand_id_col = "GEOID10"
     supply_id_col = "ORIG_ID"
     demand_col = "Population"
     d = geopandas.read_file(
         os.path.join(self.dir_name, "../test_data/demand_point.shp"))
     s = geopandas.read_file(
         os.path.join(self.dir_name,
                      "../test_data/facility_service_areas.shp"))
     coverage = Coverage.from_geodataframes(d,
                                            s,
                                            demand_id_col,
                                            supply_id_col,
                                            demand_col=demand_col)
     problem = Problem.mclp(coverage, max_supply={coverage: 5})
     problem.solve(pulp.GLPK())
     covered_demand = d.query(
         f"{demand_id_col} in ({[f'{i}' for i in problem.selected_demand(coverage)]})"
     )
     result = math.ceil(
         (covered_demand[demand_col].sum() / d[demand_col].sum()) * 100)
     assert result == 53