Пример #1
0
def checkcontiguity(soln_column, w):
    """
    Check the contiguity of a solution in the shared memory space. Called by
    the test script to validate IFS generation.
    """
    soln = soln_column[1:]
    nregions = soln_column[0]

    for i in xrange(1, nregions + 1):
        ids = np.where(soln == i)[0]
        try:
            assert is_component(w, ids) == True
        except:
            print "Failure in connected component check"
Пример #2
0
def checkcontiguity(soln_column, w):
    """
    Check the contiguity of a solution in the shared memory space. Called by
    the test script to validate IFS generation.
    """
    soln = soln_column[1:]
    nregions = soln_column[0]

    for i in xrange(1, nregions + 1):
        ids = np.where(soln == i)[0]
        try:
            assert is_component(w, ids) == True
        except:
            print "Failure in connected component check"
Пример #3
0
def checkcontiguity(idx, w):
    """
    Check the contiguity of a solution in the shared memory space. Called by
    the test script to validate IFS generation.
    """
    valid = True
    start, stop = idx
    
    for idx in range(start,stop):
        soln_column = soln_space[idx]
        soln = soln_column[1:]
        nregions = int(soln_column[0])
        for i in xrange(1, nregions + 1):
            ids = np.where(soln == i)[0]
            if is_component(w, ids) != True:
                valid = False
    if valid == True:
        pass
    else:
        print "FAILURE:", soln_column.reshape(10,10)
Пример #4
0
def checkcontiguity(idx, w):
    """
    Check the contiguity of a solution in the shared memory space. Called by
    the test script to validate IFS generation.
    """
    valid = True
    start, stop = idx

    for idx in range(start, stop):
        soln_column = soln_space[idx]
        soln = soln_column[1:]
        nregions = int(soln_column[0])
        for i in xrange(1, nregions + 1):
            ids = np.where(soln == i)[0]
            if is_component(w, ids) != True:
                valid = False
    if valid == True:
        pass
    else:
        print "FAILURE:", soln_column.reshape(10, 10)
Пример #5
0
    def test_Random_Regions(self):
        random.seed(10)
        np.random.seed(10)
        t0 = pysal.region.Random_Regions(self.ids, permutations=2)
        result = [19, 14, 43, 37, 66, 3, 79, 41, 38, 68, 2, 1, 60]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[0][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])

        random.seed(60)
        np.random.seed(60)
        t0 = pysal.region.Random_Regions(
            self.ids, num_regions=self.nregs, cardinality=self.cards, contiguity=self.w, permutations=2
        )
        result = [88, 97, 98, 89, 99, 86, 77, 68, 79, 78, 59, 49, 69]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[0][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])
        for solution in t0.solutions:
            for region in solution.regions:
                self.assertTrue(is_component(self.w, region))

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Regions(self.ids, num_regions=self.nregs, cardinality=self.cards, permutations=2)
        result = [37, 62]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[0][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Regions(self.ids, num_regions=self.nregs, contiguity=self.w, permutations=2)
        result = [73, 83, 94, 95, 64, 92, 70, 82, 81, 60, 74, 93, 71]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[1][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])
        for solution in t0.solutions:
            for region in solution.regions:
                self.assertTrue(is_component(self.w, region))

        random.seed(60)
        np.random.seed(60)
        t0 = pysal.region.Random_Regions(self.ids, cardinality=self.cards, contiguity=self.w, permutations=2)
        result = [88, 97, 98, 89, 99, 86, 77, 68, 79, 78, 59, 49, 69]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[0][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])
        for solution in t0.solutions:
            for region in solution.regions:
                self.assertTrue(is_component(self.w, region))

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Regions(self.ids, num_regions=self.nregs, permutations=2)
        result = [37, 62, 26, 41, 35, 25, 36]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[0][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Regions(self.ids, cardinality=self.cards, permutations=2)
        result = [37, 62]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[0][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Regions(self.ids, contiguity=self.w, permutations=2)
        result = [62, 52, 51, 50]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[1][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])
        for solution in t0.solutions:
            for region in solution.regions:
                self.assertTrue(is_component(self.w, region))
Пример #6
0
    def test_Random_Region(self):
        random.seed(10)
        np.random.seed(10)
        t0 = pysal.region.Random_Region(self.ids)
        t0.regions[0]
        result = [19, 14, 43, 37, 66, 3, 79, 41, 38, 68, 2, 1, 60]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)

        random.seed(60)
        np.random.seed(60)
        t0 = pysal.region.Random_Region(self.ids, num_regions=self.nregs, cardinality=self.cards, contiguity=self.w)
        t0.regions[0]
        result = [88, 97, 98, 89, 99, 86, 77, 68, 79, 78, 59, 49, 69]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)
        for region in t0.regions:
            self.assertTrue(is_component(self.w, region))

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Region(self.ids, num_regions=self.nregs, cardinality=self.cards)
        t0.regions[0]
        result = [37, 62]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Region(self.ids, num_regions=self.nregs, contiguity=self.w)
        t0.regions[1]
        result = [73, 83, 94, 95, 64, 92, 70, 82, 81, 60, 74, 93, 71]
        for i in range(len(result)):
            self.assertEquals(t0.regions[1][i], result[i])
        self.assertEquals(t0.feasible, True)
        for region in t0.regions:
            self.assertTrue(is_component(self.w, region))

        random.seed(60)
        np.random.seed(60)
        t0 = pysal.region.Random_Region(self.ids, cardinality=self.cards, contiguity=self.w)
        t0.regions[0]
        result = [88, 97, 98, 89, 99, 86, 77, 68, 79, 78, 59, 49, 69]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)
        for region in t0.regions:
            self.assertTrue(is_component(self.w, region))

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Region(self.ids, num_regions=self.nregs)
        t0.regions[0]
        result = [37, 62, 26, 41, 35, 25, 36]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Region(self.ids, cardinality=self.cards)
        t0.regions[0]
        result = [37, 62]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Region(self.ids, contiguity=self.w)
        t0.regions[0]
        result = [37, 27, 36, 17]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)
        for region in t0.regions:
            self.assertTrue(is_component(self.w, region))
Пример #7
0
    def test_Random_Regions(self):
        random.seed(10)
        np.random.seed(10)
        t0 = pysal.region.Random_Regions(self.ids, permutations=2)
        result = [19, 14, 43, 37, 66, 3, 79, 41, 38, 68, 2, 1, 60]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[0][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])

        random.seed(60)
        np.random.seed(60)
        t0 = pysal.region.Random_Regions(self.ids,
                                         num_regions=self.nregs,
                                         cardinality=self.cards,
                                         contiguity=self.w,
                                         permutations=2)
        result = [88, 97, 98, 89, 99, 86, 77, 68, 79, 78, 59, 49, 69]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[0][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])
        for solution in t0.solutions:
            for region in solution.regions:
                self.assertTrue(is_component(self.w, region))

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Regions(self.ids,
                                         num_regions=self.nregs,
                                         cardinality=self.cards,
                                         permutations=2)
        result = [37, 62]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[0][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Regions(self.ids,
                                         num_regions=self.nregs,
                                         contiguity=self.w,
                                         permutations=2)
        result = [73, 83, 94, 95, 64, 92, 70, 82, 81, 60, 74, 93, 71]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[1][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])
        for solution in t0.solutions:
            for region in solution.regions:
                self.assertTrue(is_component(self.w, region))

        random.seed(60)
        np.random.seed(60)
        t0 = pysal.region.Random_Regions(self.ids,
                                         cardinality=self.cards,
                                         contiguity=self.w,
                                         permutations=2)
        result = [88, 97, 98, 89, 99, 86, 77, 68, 79, 78, 59, 49, 69]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[0][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])
        for solution in t0.solutions:
            for region in solution.regions:
                self.assertTrue(is_component(self.w, region))

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Regions(self.ids,
                                         num_regions=self.nregs,
                                         permutations=2)
        result = [37, 62, 26, 41, 35, 25, 36]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[0][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Regions(self.ids,
                                         cardinality=self.cards,
                                         permutations=2)
        result = [37, 62]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[0][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Regions(self.ids,
                                         contiguity=self.w,
                                         permutations=2)
        result = [62, 52, 51, 50]
        for i in range(len(result)):
            self.assertEquals(t0.solutions[0].regions[1][i], result[i])
        for i in range(len(t0.solutions)):
            self.assertEquals(t0.solutions_feas[i], t0.solutions[i])
        for solution in t0.solutions:
            for region in solution.regions:
                self.assertTrue(is_component(self.w, region))
Пример #8
0
    def test_Random_Region(self):
        random.seed(10)
        np.random.seed(10)
        t0 = pysal.region.Random_Region(self.ids)
        t0.regions[0]
        result = [19, 14, 43, 37, 66, 3, 79, 41, 38, 68, 2, 1, 60]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)

        random.seed(60)
        np.random.seed(60)
        t0 = pysal.region.Random_Region(self.ids,
                                        num_regions=self.nregs,
                                        cardinality=self.cards,
                                        contiguity=self.w)
        t0.regions[0]
        result = [88, 97, 98, 89, 99, 86, 77, 68, 79, 78, 59, 49, 69]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)
        for region in t0.regions:
            self.assertTrue(is_component(self.w, region))

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Region(self.ids,
                                        num_regions=self.nregs,
                                        cardinality=self.cards)
        t0.regions[0]
        result = [37, 62]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Region(self.ids,
                                        num_regions=self.nregs,
                                        contiguity=self.w)
        t0.regions[1]
        result = [73, 83, 94, 95, 64, 92, 70, 82, 81, 60, 74, 93, 71]
        for i in range(len(result)):
            self.assertEquals(t0.regions[1][i], result[i])
        self.assertEquals(t0.feasible, True)
        for region in t0.regions:
            self.assertTrue(is_component(self.w, region))

        random.seed(60)
        np.random.seed(60)
        t0 = pysal.region.Random_Region(self.ids,
                                        cardinality=self.cards,
                                        contiguity=self.w)
        t0.regions[0]
        result = [88, 97, 98, 89, 99, 86, 77, 68, 79, 78, 59, 49, 69]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)
        for region in t0.regions:
            self.assertTrue(is_component(self.w, region))

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Region(self.ids, num_regions=self.nregs)
        t0.regions[0]
        result = [37, 62, 26, 41, 35, 25, 36]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Region(self.ids, cardinality=self.cards)
        t0.regions[0]
        result = [37, 62]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)

        random.seed(100)
        np.random.seed(100)
        t0 = pysal.region.Random_Region(self.ids, contiguity=self.w)
        t0.regions[0]
        result = [37, 27, 36, 17]
        for i in range(len(result)):
            self.assertEquals(t0.regions[0][i], result[i])
        self.assertEquals(t0.feasible, True)
        for region in t0.regions:
            self.assertTrue(is_component(self.w, region))