Esempio n. 1
0
 def test_random_route_walk_too_short_criteria(self):
     g = self.random_walk_route_test_graph()
     res = helpers.random_route_walk(g, 'N0', 'N5', 0)
     self.assertEqual(len(res), 0)
     res = helpers.random_route_walk(g, 'N0', 'N5', 1)
     self.assertEqual(len(res), 0)
     res = helpers.random_route_walk(g, 'N0', 'N5', 2)
     self.assertEqual(len(res), 0)
Esempio n. 2
0
def upwalker_counter(g, meta, vf_g, arguments):
    N = g.vcount()
    progress = progressbar1.DummyProgressBar(end=10, width=15)
    if arguments.progressbar:
        progress = progressbar1.AnimatedProgressBar(end=len(meta), width=15)

    # trace_up_map = {}
    # random_up_map = {}

    trace_up_counter = []
    random_up_counter = []

    for m in meta:
        progress += 1
        progress.show_progress()

        trace = m[helpers.TRACE]
        trace_dir = vft.trace_to_string(g, trace)
        trace_up_count = trace_dir.count('U')
        trace_up_counter.append(trace_up_count)
        # trace_up_map[trace_up_count] = trace_up_map.get(trace_up_count, 0) +
        # 1

        s, t = trace[0], trace[-1]
        s_idx, t_idx = vft.node_to_nodeid(g, s), vft.node_to_nodeid(g, t)

        random_vf_route = helpers.random_route_walk(vf_g,
                                                    s_idx,
                                                    t_idx + N,
                                                    len(trace),
                                                    named=False,
                                                    weight_field='VFweight')
        random_vf_route = vft.vf_route_converter(random_vf_route, N)
        random_vf_dir = vft.trace_to_string(g, random_vf_route)
        random_vf_count = random_vf_dir.count('U')
        random_up_counter.append(random_vf_count)
        # random_up_map[random_vf_count] = random_up_map.get(random_vf_count,
        # 0) + 1

    real_counter = collections.Counter(trace_up_counter)
    real_up = ' '.join(
        ['%s: %s' % (k, real_counter[k]) for k in sorted(list(real_counter))])
    random_counter = collections.Counter(random_up_counter)
    random_up = ' '.join([
        '%s: %s' % (k, random_counter[k]) for k in sorted(list(random_counter))
    ])

    logger.info('')
    logger.info('Real trace UP counter: %s' % real_up)
    logger.info('Random vf trace up counter: %s' % random_up)

    helpers.save_to_json(arguments.out, {
        'REAL': dict(real_counter),
        'RANDOM': dict(random_counter)
    })

    keys = sorted(set(list(real_counter) + list(random_counter)))
    logger.info('IDX;REAL;RANDOM')
    for k in keys:
        logger.info('%s;%d;%d' % (k, real_counter[k], random_counter[k]))
Esempio n. 3
0
 def test_random_route_walk_two_paralell_and_one_dead_end(self):
     g = self.random_walk_route_test_graph()
     g.add_vertices(2)
     g.vs[6]['name'] = 'N6'
     g.vs[7]['name'] = 'N7'
     g.add_edges([[6, 7], [1, 6]])
     g.delete_vertices([
         'N3',
     ])
     first_route = 0
     second_route = 0
     anomaly = 0
     for probe in xrange(0, 10000):
         routes = helpers.random_route_walk(g, 'N0', 'N5', 1000, named=True)
         route_statement = len(routes) == 4 or len(routes) == 3
         self.assertTrue(route_statement)
         if routes == ['N0', 'N1', 'N4', 'N5']:
             first_route += 1
         elif routes == ['N0', 'N2', 'N5']:
             second_route += 1
         else:
             anomaly += 1
     self.assertEqual(anomaly, 0)
     self.assertTrue(abs(first_route / 10000.0 - 0.50) < 0.1)
     self.assertTrue(abs(second_route / 10000.0 - 0.50) < 0.1)
Esempio n. 4
0
 def test_random_route_walk_only_one_route(self):
     g = self.random_walk_route_test_graph()
     g.delete_vertices(['N3', 'N4'])
     for probe in xrange(0, 1000):
         routes = helpers.random_route_walk(g, 'N0', 'N5', 3, named=True)
         self.assertEqual(len(routes), 3)
         self.assertEqual(routes, ['N0', 'N2', 'N5'])
Esempio n. 5
0
 def test_random_route_walk_loop(self):
     g = self.random_walk_route_test_graph()
     g.delete_edges([(g.vs.find('N0').index, g.vs.find('N2').index),
                     (g.vs.find('N2').index, g.vs.find('N5').index),
                     (g.vs.find('N4').index, g.vs.find('N5').index),
                     (g.vs.find('N1').index, g.vs.find('N4').index)])
     g.add_edges([['N3', 'N2'], ['N2', 'N4'], ['N4', 'N3']])
     for probe in xrange(0, 1000):
         route = helpers.random_route_walk(g, 'N0', 'N5', 100, named=True)
         self.assertEqual(len(route), len(set(route)))
         self.assertEqual(len(route), 4)
         self.assertEqual(route, ['N0', 'N1', 'N3', 'N5'])
Esempio n. 6
0
 def test_random_route_walk_weighted_edges(self):
     g = self.random_walk_route_test_graph()
     weights = [2, 1000, 1, 1000, 100, 1, 0]
     g.es['w'] = weights
     for probe in xrange(0, 1000):
         route = helpers.random_route_walk(g,
                                           'N0',
                                           'N5',
                                           500,
                                           named=True,
                                           weight_field='w')
         self.assertEqual(len(route), len(set(route)))
         self.assertEqual(len(route), 4)
         self.assertEqual(route, ['N0', 'N1', 'N3', 'N5'])
Esempio n. 7
0
def ba_generator(ba_graph, sh_paths, stretch, vf_g, progressbar=False):
    vf_count = 0
    trace_count = 0
    lp_count = 0
    progress = progressbar1.DummyProgressBar(end=10, width=15)

    if progressbar:
        progress = progressbar1.AnimatedProgressBar(end=len(sh_paths),
                                                    width=15)
    for (s, t), shl in sh_paths:
        progress += 1
        progress.show_progress()
        logger.debug('SH from %s to %s is %d' % (s, t, shl))
        random_route = helpers.random_route_walk(ba_graph, s, t, shl + stretch)
        logger.debug('Random route: %s' % random_route)
        real_stretch = len(random_route) - shl

        if real_stretch != stretch:
            continue

        trace_count += 1

        is_vf = vft.is_valley_free(ba_graph,
                                   random_route,
                                   vfmode=vft.CLOSENESS)
        logger.debug(
            'Trace edge dir: %s' %
            vft.trace_to_string(ba_graph, random_route, vfmode=vft.CLOSENESS))
        logger.debug('Is VF: %s' % is_vf)
        if is_vf:
            is_lp = vft.is_local_preferenced(ba_graph,
                                             random_route,
                                             first_edge=True,
                                             vfmode=vft.CLOSENESS,
                                             vf_g=vf_g)
        else:
            is_lp = 0
        logger.debug('Is LP: %s' % is_lp)

        vf_count += int(is_vf)
        lp_count += int(is_lp)

    logger.info('Stretch %d' % stretch)
    logger.info('Trace count: %d' % trace_count)
    logger.info('VF count: %d' % vf_count)
    logger.info('LP count: %d' % lp_count)

    return (stretch, trace_count, vf_count, lp_count)
Esempio n. 8
0
 def test_random_route_walk_merged_routes(self):
     # A visszalepesekkel tiltolistara kerult node nem zavar be
     # Nem zavarhat, hiszen melysegi kereses tortenik, de azert vizsgaljuk
     # meg
     g = self.random_walk_route_test_graph()
     g.delete_edges([
         (g.vs.find('N0').index, g.vs.find('N2').index),
     ])
     g.add_vertex(name='N6')
     g.add_edge('N5', 'N6')
     for probe in xrange(0, 1000):
         route = helpers.random_route_walk(g, 'N0', 'N2', 100, named=True)
         self.assertEqual(len(route), len(set(route)))
         self.assertEqual(len(route), 5)
         self.assertIn(route, [['N0', 'N1', 'N3', 'N5', 'N2'],
                               ['N0', 'N1', 'N4', 'N5', 'N2']])
Esempio n. 9
0
 def test_random_route_walk_double_step_back(self):
     g = self.random_walk_route_test_graph()
     g.add_edges([
         ['N4', 'N3'],
     ])
     weights = [1, 1, 3, 10, 1000, 1000, 2, 0]
     g.es['w'] = weights
     g.delete_edges([(g.vs.find('N5').index, g.vs.find('N4').index),
                     (g.vs.find('N5').index, g.vs.find('N3').index)])
     for prob in xrange(0, 1000):
         route = helpers.random_route_walk(g,
                                           'N0',
                                           'N3',
                                           10,
                                           named=True,
                                           weight_field='w')
         self.assertEqual(len(route), len(set(route)))
         self.assertEqual(len(route), 3)
         self.assertEqual(route, ['N0', 'N1', 'N3'])
Esempio n. 10
0
 def test_random_route_walk_visited_nodes_are_correct(self):
     g = self.random_walk_route_test_graph()
     g.add_edges([
         ['N4', 'N3'],
     ])
     weights = [2, 1000, 1, 0, 5, 1000, 0, 1]
     g.es['w'] = weights
     for prob in xrange(0, 1000):
         route = helpers.random_route_walk(g,
                                           'N0',
                                           'N5',
                                           500,
                                           named=True,
                                           weight_field='w')
         self.assertEqual(len(route), len(set(route)))
         self.assertTrue(4 <= len(route) <= 5)
         self.assertIn(
             route,
             [['N0', 'N1', 'N3', 'N5'], ['N0', 'N1', 'N4', 'N3', 'N5']])
Esempio n. 11
0
 def test_random_route_walk_two_paralell_routes(self):
     g = self.random_walk_route_test_graph()
     g.delete_vertices(['N3'])
     first_route = 0
     second_route = 0
     anomaly = 0
     for probe in xrange(0, 10000):
         routes = helpers.random_route_walk(g, 'N0', 'N5', 4, named=True)
         route_statement = len(routes) == 4 or len(routes) == 3
         self.assertTrue(route_statement)
         if routes == ['N0', 'N1', 'N4', 'N5']:
             first_route += 1
         elif routes == ['N0', 'N2', 'N5']:
             second_route += 1
         else:
             anomaly += 1
     self.assertEqual(anomaly, 0)
     self.assertTrue(abs(first_route / 10000.0 - 0.50) < 0.1)
     self.assertTrue(abs(second_route / 10000.0 - 0.50) < 0.1)
Esempio n. 12
0
 def test_random_route_walk_covered_routes(self):
     g = self.random_walk_route_test_graph()
     first_route = 0
     second_route = 0
     third_route = 0
     anomaly = 0
     for probe in xrange(0, 10000):
         route = helpers.random_route_walk(g, 'N0', 'N5', 4, named=True)
         route_statement = len(route) == 4 or len(route) == 3
         self.assertTrue(route_statement)
         if route == ['N0', 'N1', 'N4', 'N5']:
             first_route += 1
         elif route == ['N0', 'N2', 'N5']:
             second_route += 1
         elif route == ['N0', 'N1', 'N3', 'N5']:
             third_route += 1
         else:
             anomaly += 1
     self.assertEqual(anomaly, 0)
     self.assertTrue(abs(first_route / 10000.0 - 0.25) < 0.1)
     self.assertTrue(abs(second_route / 10000.0 - 0.50) < 0.1)
     self.assertTrue(abs(third_route / 10000.0 - 0.25) < 0.1)
Esempio n. 13
0
def purify(g,
           meta_original,
           out,
           count=1000,
           try_per_race=1,
           show_progress=False,
           with_lp=True):

    empty = 0
    # remove traces with already calculated random paths
    logger.warn('[r]ONLY NOT FILLED PATHS[/]')
    meta_filled = [
        x for x in meta_original if helpers.RANDOM_WALK_RUN_COUNT not in x
    ]

    # Filter if interested only in routes of stretch 1
    # meta_filled = [x for x in meta_original
    #                if x[helpers.TRACE_LEN]-x[helpers.SH_LEN] == 1]

    ## traces with a maximum stretch
    # logger.warn('[r]!!!ONLY WITH STRETCH[/]')
    # meta = [x for x in meta if x[helpers.STRETCH] > -1]

    # # shorter meta records
    # logger.warn('[r]!!!ONLY SHORT TRACES[/]')
    # meta = [x for x in meta if len(x[helpers.TRACE]) < 5]

    # meta_map = {tuple(x[helpers.TRACE]): x for x in meta_filled}

    logger.info('All trace count: %d' % len(meta_filled))
    tr_count = min(len(meta_filled), count)
    meta_random = random.sample(meta_filled, tr_count)
    logger.info('Chosen subset count: %d' % len(meta_random))

    # real_vf_degree = [x for x in meta_random if x[helpers.IS_VF_DEGREE] == 1]
    # real_nonvf_degree = [x for x in meta_random if x[helpers.IS_VF_DEGREE] == 0]
    # assert len(real_nonvf_degree) == tr_count - len(real_vf_degree)

    # real_vf_prelabeled = [x for x in meta_random if x[helpers.IS_VF_PRELABELED] == 1]
    # real_nonvf_prelabeled = [x for x in meta_random if x[helpers.IS_VF_PRELABELED] == 0]
    # assert len(real_nonvf_prelabeled) == tr_count - len(real_vf_prelabeled)

    # real_vf_closeness = [x for x in meta_random if x[helpers.IS_VF_CLOSENESS] == 1]
    # real_nonvf_closeness = [x for x in meta_random if x[helpers.IS_VF_CLOSENESS] == 0]
    # assert len(real_nonvf_closeness) == tr_count - len(real_vf_closeness)

    # logger.info('Real vf degree: %f[%d]' % ((len(real_vf_degree) / float(tr_count),
    #                                  len(real_vf_degree))))
    # logger.info('Real nonvf degree: %f[%d]' % ((len(real_nonvf_degree) / float(tr_count),
    #                                     len(real_nonvf_degree))))

    # logger.info('Real vf prelabeled: %f[%d]' % ((len(real_vf_prelabeled) / float(tr_count),
    #                                  len(real_vf_prelabeled))))
    # logger.info('Real nonvf prelabeled: %f[%d]' % ((len(real_nonvf_prelabeled) / float(tr_count),
    #                                     len(real_nonvf_prelabeled))))
    # logger.info('Real vf closeness: %f[%d]' % ((len(real_vf_closeness)/float(tr_count), len(real_vf_closeness))))
    # logger.info('Real nonvf closeness: %f[%d]' % ((len(real_nonvf_closeness)/float(tr_count), len(real_nonvf_closeness))))

    # traceroutes = [x[helpers.TRACE] for x in meta_random]
    # traceroutes = vft.trace_in_vertex_id(g, traceroutes)

    try:
        meta_random[0][helpers.TRACE]
    except Exception:
        meta_random = [{helpers.TRACE: x} for x in meta_random]

    progress = progressbar1.DummyProgressBar(end=10, width=15)
    if show_progress:
        progress = progressbar1.AnimatedProgressBar(end=len(meta_random),
                                                    width=15)

    stretch_list = []
    max_stretch = max(
        [x[helpers.TRACE_LEN] - x[helpers.SH_LEN] for x in meta_random])
    for stretch in range(0, max_stretch + 1):
        metas = [
            x for x in meta_random
            if x[helpers.TRACE_LEN] - x[helpers.SH_LEN] == stretch
        ]
        stretch_list.extend(list(repeat(stretch, len(metas))))

    # print(stretch_list)
    lenghts = random.shuffle(stretch_list)

    strx_array = []

    for idx, trace_meta in enumerate(meta_random):
        progress += 1
        progress.show_progress()
        # print(trace_meta[helpers.TRACE])
        shl = trace_meta[helpers.SH_LEN]
        trace = vft.trace_in_vertex_id(g, [
            trace_meta[helpers.TRACE],
        ])
        if len(trace) != 1:
            print 'PROBLEM'
            print trace_meta
            continue
        trace = trace[0]
        # print(trace)
        random_walk_closeness_route_vf = 0
        random_walk_closeness_route_lp_soft = 0
        random_walk_closeness_route_lp_hard = 0
        random_walk_degree_route_vf = 0
        random_walk_degree_route_lp_soft = 0
        random_walk_degree_route_lp_hard = 0
        random_walk_prelabeled_route_vf = 0
        random_walk_prelabeled_route_lp_soft = 0
        random_walk_prelabeled_route_lp_hard = 0

        s, t = trace[0], trace[-1]
        for counter in xrange(0, try_per_race):
            # random_path = helpers.random_route_walk(g, s, t, len(trace)) # Modified
            random_path = helpers.random_route_walk(
                g, s, t, shl + stretch_list[idx])  # Modified
            if len(random_path) == 0:
                empty += 1
            if vft.is_valley_free(g, random_path, vfmode=vft.CLOSENESS):
                random_walk_closeness_route_vf += 1
                if (len(random_path) == shl + 1):
                    strx_array.append(1)
                if with_lp:
                    lp_soft = vft.is_local_preferenced(g,
                                                       random_path,
                                                       first_edge=True,
                                                       vfmode=vft.CLOSENESS)
                    lp_hard = vft.is_local_preferenced(g,
                                                       random_path,
                                                       first_edge=False,
                                                       vfmode=vft.CLOSENESS)
                    if lp_soft:
                        random_walk_closeness_route_lp_soft += 1
                    if lp_hard:
                        random_walk_closeness_route_lp_hard += 1
            else:
                if (len(random_path) == shl + 1):
                    strx_array.append(0)

            # if vft.is_valley_free(g, random_path, vfmode=vft.DEGREE):
            #     random_walk_degree_route_vf += 1
            #     if with_lp:
            #         lp_soft = vft.is_local_preferenced(g, random_path,
            #                                            first_edge=True,
            #                                            vfmode=vft.DEGREE)
            #         lp_hard = vft.is_local_preferenced(g, random_path,
            #                                            first_edge=False,
            #                                            vfmode=vft.DEGREE)
            #         if lp_soft:
            #             random_walk_degree_route_lp_soft += 1
            #         if lp_hard:
            #             random_walk_degree_route_lp_hard += 1

            # if vft.is_valley_free(g, random_path, vfmode=vft.PRELABELED):
            #     random_walk_prelabeled_route_vf += 1
            #     if with_lp:
            #         lp_soft = vft.is_local_preferenced(g, random_path,
            #                                            first_edge=True,
            #                                            vfmode=vft.PRELABELED)
            #         lp_hard = vft.is_local_preferenced(g, random_path,
            #                                            first_edge=False,
            #                                            vfmode=vft.PRELABELED)
            #         if lp_soft:
            #             random_walk_prelabeled_route_lp_soft += 1
            #         if lp_hard:
            #             random_walk_prelabeled_route_lp_hard += 1

            # sanity check


#             if random_path[0] != s or random_path[-1] != t:
#                 logger.error('ALERT')

            if len(random_path) != len(set(random_path)):
                logger.error('LENGTH ERROR')

        extra_meta = {
            helpers.RANDOM_WALK_RUN_COUNT:
            try_per_race,
            helpers.RANDOM_WALK_VF_CLOSENESS_ROUTE:
            random_walk_closeness_route_vf,
            helpers.RANDOM_WALK_VF_DEGREE_ROUTE:
            random_walk_degree_route_vf,
            helpers.RANDOM_WALK_VF_PRELABELED_ROUTE:
            random_walk_prelabeled_route_vf,
        }
        if with_lp:
            extra_meta.update({
                helpers.RANDOM_WALK_LP_SOFT_CLOSENESS_ROUTE:
                random_walk_closeness_route_lp_soft,
                helpers.RANDOM_WALK_LP_HARD_CLOSENESS_ROUTE:
                random_walk_closeness_route_lp_hard,
                helpers.RANDOM_WALK_LP_SOFT_DEGREE_ROUTE:
                random_walk_degree_route_lp_soft,
                helpers.RANDOM_WALK_LP_HARD_DEGREE_ROUTE:
                random_walk_degree_route_lp_hard,
                helpers.RANDOM_WALK_LP_SOFT_PRELABELED_ROUTE:
                random_walk_prelabeled_route_lp_soft,
                helpers.RANDOM_WALK_LP_HARD_PRELABELED_ROUTE:
                random_walk_prelabeled_route_lp_hard
            })

        trace_meta.update(extra_meta)

    ## save modified meta
    # all meta_* get only references from meta_original
    helpers.save_to_json(out, meta_random)
    # meta_mod = [x for x in meta_map.itervalues()]
    # helpers.save_to_json(out, meta_mod)

    # calculate results
    # real_vf = [x[helpers.IS_VF_CLOSENESS] for x in meta_random]
    # real_vf_ratio = np.mean(real_vf)

    random_walk_vf_ratio_per_element = [
        x[helpers.RANDOM_WALK_VF_CLOSENESS_ROUTE] /
        x[helpers.RANDOM_WALK_RUN_COUNT] for x in meta_random
    ]
    random_walk_vf_ratio = np.mean(random_walk_vf_ratio_per_element)
    # print results
    logger.info('')
    logger.info('Empty: %d' % empty)
    logger.info('Tested trace count: %d' % len(meta_random))
    # logger.info('VF ratio in tested traces: %f' % real_vf_ratio)
    logger.info('VF ratio in random walks: %f' % random_walk_vf_ratio)
    logger.info('VF ratio in random walks for path stretch 1: %f' %
                np.mean(strx_array))
Esempio n. 14
0
def purify(g, meta, flags, try_per_trace, show_progress=False):

    # generate valley-free graph
    if flags[FLAG_PRELABELED]:
        logger.info('Generate VF_G_PRE')
        vf_g_pre = vft.convert_to_vf(g, vfmode=vft.PRELABELED)
    else:
        logger.info('Skip prelabeled graph')

    if flags[FLAG_DEGREE]:
        logger.info('Generate VF_G_DEGREE')
        vf_g_degree = vft.convert_to_vf(g, vfmode=vft.DEGREE)
    else:
        logger.info('Skip degree graph')

    if flags[FLAG_CLOSENESS]:
        logger.info('Generate VF_G_CLOSENESS')
        vf_g_closeness = vft.convert_to_vf(g, vfmode=vft.CLOSENESS)
    else:
        logger.info('Skip closeness graph')

    # Randomize stretch dispersion
    stretches = [x[helpers.HOP_STRETCH] for x in meta]
    # a veletlen stretchek az eredeti stretchek veletlen, nem
    # visszateveses mintavetelezese. Mindez annyiszor, ahany
    # veletlen utat akarunk generalni minden valos trace vegpontja
    # kozott.
    stretch_list = [random.sample(stretches, len(stretches))
                    for x in xrange(0, try_per_trace)]
    # A kovetkezo ciklusban minden meta sorhoz rogton kiszamolunk
    # annyi random utat, amennyit parameterben megadtunk. Ehhez at kell
    # alakitani a stretch lista strukturat, hogy minden elem egy meta sorhoz
    # tartalmazza a random stretch ertekeket
    #
    # Pelda: elozo lepesnel kijott ez: [ [1,2,3,4], [2,4,1,3], [3,1,4,2] ]
    # vagyis elso lepesben a metaban tarolt tracek rendre 1,2,3,4 stretchet
    # kell felvegyenek, a masodikban 2,4,1,3 stb. A ciklusban viszont a meta
    # elso elemehez rogton ki akarjuk szamolni a veletlen stretchekhez tartozo
    # random utakat, vagyis [ [1,2,3], [2,4,1], [3,1,4], [4,3,2] ] formaban
    # van szukseg az ertekekre
    stretch_list = zip(*stretch_list)

    progress = progressbar1.DummyProgressBar(end=10, width=15)
    if show_progress:
        progress = progressbar1.AnimatedProgressBar(end=len(meta), width=15)

    for idx, record in enumerate(meta):
        progress += 1
        progress.show_progress()

        trace = vft.trace_in_vertex_id(g, [record[helpers.TRACE], ])
        if len(trace) != 1:
            print 'PROBLEM'
            print record
            continue
        trace = trace[0]

        if len(trace) == 1: continue

        sh_len = record[helpers.SH_LEN]
        s, t = trace[0], trace[-1]

        is_vf_prelabeled_l = []
        is_lp_prelabeled_hard_l = []
        is_lp_prelabeled_soft_l = []

        is_vf_degree_l = []
        is_lp_degree_hard_l = []
        is_lp_degree_soft_l = []

        is_vf_closeness_l = []
        is_lp_closeness_hard_l = []
        is_lp_closeness_soft_l = []

        stretch_dist = stretch_list[idx]
        real_stretch_dist = []
        for current_stretch in stretch_dist:
            random_length = sh_len + current_stretch
            random_path = helpers.random_route_walk(g, s, t, random_length)
            real_stretch_dist.append(len(random_path) - sh_len)
            if len(random_path) == 0:
                empty += 1

            if flags[FLAG_PRELABELED]:
                (is_vf_prelabeled,
                 is_lp_prelabeled_soft,
                 is_lp_prelabeled_hard) = vf_attributes(g,random_path,
                                                   vft.PRELABELED,
                                                   flags[FLAG_LP_SOFT],
                                                   flags[FLAG_LP_HARD],
                                                   vf_g_pre)
                is_vf_prelabeled_l.append(is_vf_prelabeled)
                is_lp_prelabeled_soft_l.append(is_lp_prelabeled_soft)
                is_lp_prelabeled_hard_l.append(is_lp_prelabeled_hard)

            if flags[FLAG_DEGREE]:
                (is_vf_degree,
                 is_lp_degree_soft,
                 is_lp_degree_hard) = vf_attributes(g, random_path,
                                                    vft.DEGREE,
                                                    flags[FLAG_LP_SOFT],
                                                    flags[FLAG_LP_HARD],
                                                    vf_g_degree)
                is_vf_degree_l.append(is_vf_degree)
                is_lp_degree_soft_l.append(is_lp_degree_soft)
                is_lp_degree_hard_l.append(is_lp_degree_hard)

            if flags[FLAG_CLOSENESS]:
                (is_vf_closeness,
                 is_lp_closeness_soft,
                 is_lp_closeness_hard) = vf_attributes(g, random_path,
                                                       vft.CLOSENESS,
                                                       flags[FLAG_LP_SOFT],
                                                       flags[FLAG_LP_HARD],
                                                       vf_g_closeness)
                is_vf_closeness_l.append(is_vf_closeness)
                is_lp_closeness_soft_l.append(is_lp_closeness_soft)
                is_lp_closeness_hard_l.append(is_lp_closeness_hard)

        result = {
            helpers.RANDOM_GULYAS_WALK_ROUTES_RQ_STRETCH: stretch_dist,
            helpers.RANDOM_GULYAS_WALK_ROUTES_STRETCH: real_stretch_dist,
            helpers.RANDOM_GULYAS_WALK_ROUTES_VF_PRELABELED: is_vf_prelabeled_l,
            helpers.RANDOM_GULYAS_WALK_ROUTES_VF_DEGREE: is_vf_degree_l,
            helpers.RANDOM_GULYAS_WALK_ROUTES_VF_CLOSENESS: is_vf_closeness_l,
            helpers.RANDOM_GULYAS_WALK_ROUTES_LP_SOFT_PRELABELED: is_lp_prelabeled_soft_l,
            helpers.RANDOM_GULYAS_WALK_ROUTES_LP_HARD_PRELABELED: is_lp_prelabeled_hard_l,
            helpers.RANDOM_GULYAS_WALK_ROUTES_LP_SOFT_DEGREE: is_lp_degree_soft_l,
            helpers.RANDOM_GULYAS_WALK_ROUTES_LP_HARD_DEGREE: is_lp_degree_hard_l,
            helpers.RANDOM_GULYAS_WALK_ROUTES_LP_SOFT_CLOSENESS: is_lp_closeness_soft_l,
            helpers.RANDOM_GULYAS_WALK_ROUTES_LP_HARD_CLOSENESS: is_lp_closeness_hard_l,
        }

        record.update(result)
Esempio n. 15
0
 def test_random_route_walk_no_loops(self):
     g = self.random_walk_route_test_graph()
     for probe in xrange(0, 1000):
         route = helpers.random_route_walk(g, 'N0', 'N5', 100, named=True)
         self.assertEqual(len(route), len(set(route)))
Esempio n. 16
0
 def test_random_route_walk_keep_limits(self):
     g = self.random_walk_route_test_graph()
     for probe in xrange(0, 1000):
         route = helpers.random_route_walk(g, 'N0', 'N5', 3, named=True)
         self.assertEqual(len(route), 3)
         self.assertEqual(route, ['N0', 'N2', 'N5'])