def test_bclpcc(self):
     merged_dict = covering.merge_coverages([self.partial_coverage, self.partial_coverage2])
     merged_dict = covering.update_serviceable_demand(merged_dict, self.serviceable_demand_polygon)
     bclpcc = covering.create_bclpcc_model(merged_dict, {"total": 3}, 0.2)
     bclpcc.solve(pulp.GUROBI())
     ids = utilities.get_ids(bclpcc, "facility_service_areas")
     ids2 = utilities.get_ids(bclpcc, "facility2_service_areas")
     self.assertEqual(['4'], ids)
     self.assertEqual(['10'], ids2)
Exemplo n.º 2
0
 def test_bclpcc(self):
     merged_dict = covering.merge_coverages(
         [self.partial_coverage, self.partial_coverage2])
     merged_dict = covering.update_serviceable_demand(
         merged_dict, self.serviceable_demand_polygon)
     bclpcc = covering.create_bclpcc_model(merged_dict, {"total": 3}, 0.2)
     bclpcc.solve(pulp.GLPK())
     ids = utilities.get_ids(bclpcc, "facility_service_areas")
     ids2 = utilities.get_ids(bclpcc, "facility2_service_areas")
     self.assertEqual(['4'], ids)
     self.assertEqual(['10'], ids2)
 def test_backup(self):
     merged_dict = covering.merge_coverages([self.binary_coverage_point, self.binary_coverage_point2])
     merged_dict = covering.update_serviceable_demand(merged_dict, self.serviceable_demand_point)
     bclp = covering.create_backup_model(merged_dict, {"total": 30})
     bclp.solve(pulp.GUROBI())
     ids = utilities.get_ids(bclp, "facility_service_areas")
     ids2 = utilities.get_ids(bclp, "facility2_service_areas")
     self.assertEqual(['1', '3', '4', '5', '6', '7'], ids)
     self.assertEqual(
         ['0', '1', '10', '12', '13', '14', '15', '16', '17', '18', '19', '2', '20', '22', '3', '4', '5', '6', '8',
          '9'], ids2)
 def test_lscp(self):
     merged_dict = covering.merge_coverages([self.binary_coverage_point, self.binary_coverage_point2])
     merged_dict = covering.update_serviceable_demand(merged_dict, self.serviceable_demand_point)
     lscp = covering.create_lscp_model(merged_dict)
     lscp_i = covering.create_lscp_model(self.binary_coverage_point)
     lscp.solve(pulp.GUROBI())
     lscp_i.solve(pulp.GUROBI())
     ids = utilities.get_ids(lscp, "facility_service_areas")
     ids2 = utilities.get_ids(lscp, "facility2_service_areas")
     self.assertEqual(['1', '3', '4', '5', '6', '7'], ids)
     self.assertEqual(
         ['0', '1', '11', '12', '13', '14', '15', '16', '17', '19', '2', '20', '22', '4', '5', '6', '7', '9'], ids2)
     self.assertEqual(lscp_i.status, pulp.constants.LpStatusInfeasible)
Exemplo n.º 5
0
 def test_lscp(self):
     merged_dict = covering.merge_coverages(
         [self.binary_coverage_point, self.binary_coverage_point2])
     merged_dict = covering.update_serviceable_demand(
         merged_dict, self.serviceable_demand_point)
     lscp = covering.create_lscp_model(merged_dict, "lscp.lp")
     lscp.solve(pulp.GLPK())
     ids = utilities.get_ids(lscp, "facility_service_areas")
     ids2 = utilities.get_ids(lscp, "facility2_service_areas")
     self.assertEqual(['3', '4', '5', '6', '7'], ids)
     self.assertEqual([
         '0', '1', '11', '12', '13', '14', '15', '16', '17', '18', '19',
         '2', '20', '21', '22', '4', '5', '6', '9'
     ], ids2)
Exemplo n.º 6
0
 def test_backup(self):
     merged_dict = covering.merge_coverages(
         [self.binary_coverage_point, self.binary_coverage_point2])
     merged_dict = covering.update_serviceable_demand(
         merged_dict, self.serviceable_demand_point)
     bclp = covering.create_backup_model(merged_dict, {"total": 30})
     bclp.solve(pulp.GUROBI())
     ids = utilities.get_ids(bclp, "facility_service_areas")
     ids2 = utilities.get_ids(bclp, "facility2_service_areas")
     self.assertEqual(['1', '3', '4', '5', '6', '7'], ids)
     self.assertEqual([
         '0', '1', '10', '12', '13', '14', '15', '16', '17', '18', '19',
         '2', '20', '22', '3', '4', '5', '6', '8', '9'
     ], ids2)
Exemplo n.º 7
0
 def test_lscp(self):
     merged_dict = covering.merge_coverages(
         [self.binary_coverage_point, self.binary_coverage_point2])
     merged_dict = covering.update_serviceable_demand(
         merged_dict, self.serviceable_demand_point)
     lscp = covering.create_lscp_model(merged_dict)
     lscp_i = covering.create_lscp_model(self.binary_coverage_point)
     lscp.solve(pulp.GUROBI())
     lscp_i.solve(pulp.GUROBI())
     ids = utilities.get_ids(lscp, "facility_service_areas")
     ids2 = utilities.get_ids(lscp, "facility2_service_areas")
     self.assertEqual(['1', '3', '4', '5', '6', '7'], ids)
     self.assertEqual([
         '0', '1', '11', '12', '13', '14', '15', '16', '17', '19', '2',
         '20', '22', '4', '5', '6', '7', '9'
     ], ids2)
     self.assertEqual(lscp_i.status, pulp.constants.LpStatusInfeasible)
Exemplo n.º 8
0
        r"../sample_data/facility2_service_areas.shp").getOutput(0)

    # Create binary coverage (point) dictionary structure for each set of facilities since
    # LSCP requires complete coverage
    # we need to use both sets of facilities
    # Use population of each polygon as demand,
    # Use GEOID as the unique field
    # Ue ORIG_ID as the unique id for the facilities
    binary_coverage_point1 = arcpy_analysis.generate_binary_coverage(
        demand_point_fl, facility_service_areas_fl, "Population", "GEOID10",
        "ORIG_ID")
    binary_coverage_point2 = arcpy_analysis.generate_binary_coverage(
        demand_point_fl, facility2_service_areas_fl, "Population", "GEOID10",
        "ORIG_ID")
    # Merge the binary coverages together, serviceable area is auto-updated for binary coverage
    total_binary_coverage = covering.merge_coverages(
        [binary_coverage_point1, binary_coverage_point2])

    # Create the mclp model
    # Maximize the total coverage (binary polygon) using at most 5 out of 8 facilities
    logger.info("Creating MCLP model...")
    lscp = covering.create_lscp_model(total_binary_coverage, "lscp.lp")
    # Solve the model using GLPK
    logger.info("Solving LSCP...")
    lscp.solve(pulp.GLPK())
    # Get the unique ids of the facilities chosen
    logger.info("Extracting results")
    ids = utilities.get_ids(lscp, "facility_service_areas")
    ids2 = utilities.get_ids(lscp, "facility2_service_areas")
    # Generate a query that could be used as a definition query or selection in arcpy
    select_query = arcpy_analysis.generate_query(ids,
                                                 unique_field_name="ORIG_ID")
Exemplo n.º 9
0
    facility2_service_areas_fl = arcpy.MakeFeatureLayer_management(
        r"../sample_data/facility2_service_areas.shp").getOutput(0)

    # Create binary coverage (point) dictionary structure for each set of facilities since
    # LSCP requires complete coverage
    # we need to use both sets of facilities
    # Use population of each polygon as demand,
    # Use GEOID as the unique field
    # Ue ORIG_ID as the unique id for the facilities
    binary_coverage_point1 = arcpy_analysis.generate_binary_coverage(demand_point_fl, facility_service_areas_fl,
                                                                     "Population", "GEOID10", "ORIG_ID")
    binary_coverage_point2 = arcpy_analysis.generate_binary_coverage(demand_point_fl, facility2_service_areas_fl,
                                                                     "Population",
                                                                     "GEOID10", "ORIG_ID")
    # Merge the binary coverages together, serviceable area is auto-updated for binary coverage
    total_binary_coverage = covering.merge_coverages([binary_coverage_point1, binary_coverage_point2])

    # Create the mclp model
    # Maximize the total coverage (binary polygon) using at most 5 out of 8 facilities
    logger.info("Creating MCLP model...")
    lscp = covering.create_lscp_model(total_binary_coverage)
    # Solve the model using GLPK
    logger.info("Solving LSCP...")
    lscp.solve(pulp.GLPK())
    # Get the unique ids of the facilities chosen
    logger.info("Extracting results")
    ids = utilities.get_ids(lscp, "facility_service_areas")
    ids2 = utilities.get_ids(lscp, "facility2_service_areas")
    # Generate a query that could be used as a definition query or selection in arcpy
    select_query = arcpy_analysis.generate_query(ids, unique_field_name="ORIG_ID")
    # Generate a second query for the other layer