예제 #1
0
def test_incomplete_housing_missing_comparisons():
    m = {('a', 'b'): 5, ('a', 'c'): 3, ('a', 'd'): 7, ('a', 'e'): 6, ('a', 'f'): 6,
         ('b', 'd'): 5, ('b', 'f'): 3,
         ('c', 'e'): 3, ('c', 'g'): 6,
         ('f', 'd'): 4,
         ('g', 'a'): 3, ('g', 'e'): 5,
         ('h', 'a'): 4, ('h', 'b'): 7, ('h', 'd'): 8, ('h', 'f'): 6}
    cm = ahpy.Compare('Incomplete Housing', m)
    assert (cm._missing_comparisons ==
            pytest.approx({('b', 'c'): 0.3300187496240363, ('b', 'e'): 1.7197409185349517,
                           ('b', 'g'): 0.4663515002203321, ('c', 'd'): 9.920512661898753,
                           ('c', 'f'): 4.852486449214693, ('c', 'h'): 0.5696073301509899,
                           ('d', 'e'): 0.5252768142894285, ('d', 'g'): 0.1424438146531802,
                           ('e', 'f'): 0.9311973564754218, ('e', 'h'): 0.10930828182051665,
                           ('f', 'g'): 0.2912120796181874, ('g', 'h'): 0.4030898885178746}))
예제 #2
0
def test_cities_weights_saaty_precision_3():
    cu = ahpy.Compare('Culture', culture, precision=3, random_index='Saaty')
    f = ahpy.Compare('Family', family, precision=3, random_index='Saaty')
    h = ahpy.Compare('Housing', housing, precision=3, random_index='Saaty')
    j = ahpy.Compare('Jobs', jobs, precision=3, random_index='Saaty')
    t = ahpy.Compare('Transportation', transportation, precision=3, random_index='Saaty')

    cr = ahpy.Compare('Goal', criteria, precision=3, random_index='Saaty')
    cr.add_children([cu, f, h, j, t])

    assert cr.target_weights == {'Bethesda': 0.229, 'Boston': 0.275, 'Pittsburgh': 0.385, 'Santa Fe': 0.111}
예제 #3
0
def test_cities_target_weights():
    cu = ahpy.Compare('Culture', culture, precision=4)
    f = ahpy.Compare('Family', family, precision=4)
    h = ahpy.Compare('Housing', housing, precision=4)
    j = ahpy.Compare('Jobs', jobs, precision=4)
    t = ahpy.Compare('Transportation', transportation, precision=4)

    cr = ahpy.Compare('Goal', criteria, precision=4)
    cr.add_children([cu, f, h, j, t])

    assert t.target_weights is None
예제 #4
0
def test_cities_weights_dd_precision_4():
    cu = ahpy.Compare('Culture', culture, precision=4)
    f = ahpy.Compare('Family', family, precision=4)
    h = ahpy.Compare('Housing', housing, precision=4)
    j = ahpy.Compare('Jobs', jobs, precision=4)
    t = ahpy.Compare('Transportation', transportation, precision=4)

    cr = ahpy.Compare('Goal', criteria, precision=4)
    cr.add_children([cu, f, h, j, t])

    assert cr.target_weights == {'Bethesda': 0.2291, 'Boston': 0.2748, 'Pittsburgh': 0.3852, 'Santa Fe': 0.1110}
예제 #5
0
def test_drinks_weights_precision_4_dd():
    c = ahpy.Compare('Drinks', drinks, precision=4, random_index='dd')
    assert c.local_weights == {'beer': 0.1164, 'coffee': 0.1775, 'milk': 0.1288, 'soda': 0.1896,
                               'tea': 0.0418, 'water': 0.3268, 'wine': 0.0191}
예제 #6
0
def test_drinks_weights_precision_3_saaty():
    c = ahpy.Compare('Drinks', drinks, precision=3, random_index='saaty')
    assert c.local_weights == {'beer': 0.116, 'coffee': 0.177, 'milk': 0.129, 'soda': 0.190,
                               'tea': 0.042, 'water': 0.327, 'wine': 0.019}
예제 #7
0
def test_drinks_cr_dd():
    c = ahpy.Compare('Drinks', drinks, precision=4, random_index='dd')
    assert c.consistency_ratio == 0.0235
예제 #8
0
def test_drinks_cr_saaty():
    c = ahpy.Compare('Drinks', drinks, precision=3, random_index='saaty')
    assert c.consistency_ratio == 0.022
예제 #9
0
def test_size_limit_normalize_saaty():
    y = dict.fromkeys([i[0] for i in itertools.combinations(alphabet, 1)], 1)
    cy = ahpy.Compare('CR Test', y, random_index='saaty')
    assert cy.local_weights == values
예제 #10
0
def test_size_limit_saaty():
    with pytest.raises(ValueError):
        x = dict.fromkeys(itertools.permutations(alphabet, 2), 1)
        ahpy.Compare('CR Test', x, random_index='saaty')
예제 #11
0
def test_normalized_weights():
    fuel = {'civic': 34, 'saturn': 27, 'escort': 24, 'clio': 28}
    cf = ahpy.Compare('Fuel Economy', fuel)
    assert cf.local_weights == {'civic': 0.3009, 'saturn': 0.2389, 'escort': 0.2124, 'clio': 0.2478}
예제 #12
0
def test_incomplete_example_cr():
    cu = ahpy.Compare('Incomplete Example', u)
    assert cu.consistency_ratio == 0.0372
예제 #13
0
def test_incomplete_example_weights():
    cu = ahpy.Compare('Incomplete Example', u)
    assert cu.local_weights == {'a': 0.3738, 'b': 0.392, 'c': 0.0985, 'd': 0.1357}
예제 #14
0
def test_incomplete_example_missing_comparisons():
    cu = ahpy.Compare('Incomplete Example', u)
    assert cu._missing_comparisons == pytest.approx({('c', 'd'): 0.730297106886979})
예제 #15
0
def test_size_limit_override_saaty():
    x = dict.fromkeys(itertools.permutations(alphabet, 2), 1)
    cx = ahpy.Compare('CR Test', x, random_index='saaty', cr=False)
    assert cx.local_weights == values
예제 #16
0
with open('ffp.csv') as csv_file:
    reader = csv.DictReader(csv_file)

    for row in reader:
        labels.append(row['SITE_ID'])
        wbid += '{};'.format(row['WBID'])
        ag += '{};'.format(row['AGRICULTURE'])
        bio += '{};'.format(row['BIODIVERSITY'])

# Remove trailing semicolon from matrices
wbid_m = wbid.rstrip(';')
ag_m = ag.rstrip(';')
bio_m = bio.rstrip(';')

# Create Compare objects
wbid = ahpy.Compare('wbid', wbid_m, labels, comp_type='quant')
ag = ahpy.Compare('ag', ag_m, labels, comp_type='quant')
bio = ahpy.Compare('bio', bio_m, labels, comp_type='quant')

# Build all possible criteria combinations
combo_list = [str(i) for i in xrange(1, 10)]
combo_list += ['1/{}'.format(i) for i in xrange(1, 10) if i > 1]
matrix_list = []
for i in itertools.product(combo_list, repeat=2):
    for j in combo_list:
        matrix_list.append('{} {}; {}'.format(i[0], i[1], j))

# Connect to MongoDB
client = MongoClient()
db = client.ffp
예제 #17
0
def test_size_limit_normalize_saaty():
    y = dict.fromkeys([i[0] for i in itertools.combinations(alphabet, 1)], 1)
    cy = ahpy.Compare('CR Test', y, random_index='saaty')
    assert cy.local_weights == values


a_m = {('b', 'c'): 1}
b_m = {('d', 'e'): 4}
d_m = {('f', 'g'): 2}

c_m = {'x': 2, 'y': 4, 'z': 4}
e_m = {'x': 1, 'y': 2, 'z': 3}
f_m = {'x': 2, 'y': 4, 'z': 4}
g_m = {'x': 1, 'y': 2, 'z': 3}

a = ahpy.Compare('a', a_m)
b = ahpy.Compare('b', b_m)
c = ahpy.Compare('c', c_m)
d = ahpy.Compare('d', d_m)
e = ahpy.Compare('e', e_m)
f = ahpy.Compare('f', f_m)
g = ahpy.Compare('g', g_m)

a.add_children([b, c])
b.add_children([d, e])
d.add_children([f, g])


def test_master_a():
    assert a.report(verbose=True) == {'name': 'a', 'global_weight': 1.0, 'local_weight': 1.0,
                                      'target_weights': {'z': 0.4233, 'y': 0.3844, 'x': 0.1922},