Beispiel #1
0
def generate_fc(init_positions=None,
                n_fc=None,
                radius_fc=None,
                color=(80, 120, 50, 128)):
    """Generar Femto celdas
    :param init_positions: posiciones iniciales
    :param n_fc: número de femtoceldas
    :param radius_fc: radio de femtocelda
    :param color: tuple color for femtocells
    :return:
    """
    if not isinstance(init_positions, np.ndarray):
        init_positions = np.array(init_positions)

    fcs = Group(prefix="F")  # Grupo de femtoceldas
    m, n, _ = init_positions.shape
    space_between_fc = 4
    indx = 0
    pos_y = [i for i in range(m) if i % 4 == 0]
    pos_x = [i + 1 for i in range(n) if i % 4 == 0]
    for i in pos_x:
        for j in pos_y:
            if indx < n_fc:
                position = init_positions[j + 1, i]
                fcs.add(
                    Femtocell(*position,
                              radius=radius_fc,
                              color=color,
                              Id="FC" + str(indx + 1),
                              indx=indx))
                indx += 1
    return fcs
Beispiel #2
0
 def run(this, points):
   points = points.getNext().values
   size = len(points)
   scales = binomials(size)
   out = Group()
   for i in range(this.numPoints):
     t = i / (this.numPoints - 1.0)
     tt = 1 - t
     pos = [0, 0, 0]
     tan = [0, 0, 0]
     for j in range(size):
       top = size - j - 1
       scale = scales[j] * math.pow(t, j) * math.pow(tt, top)
       tanScale = 0
       if j > 0:
         tanScale += j * math.pow(t, j - 1) * math.pow(tt, top)
       if j < size - 1:
         tanScale += (size - j - 1) * math.pow(t, j) * math.pow(tt, top - 1)
       tanScale *= scales[j]
       pos = [pos[0] + scale * points[j][0], pos[1] + scale * points[j][1],
              pos[2] + scale * points[j][2]]
       tan = [tan[0] + tanScale * points[j][0], 
              tan[1] + tanScale * points[j][1],
              tan[2] + tanScale * points[j][2]]
     out.addVector(pos)
     out.addTangent(tan)
   return out
Beispiel #3
0
 def test_orbits4(self):
     self.N = 10
     self.group = Group()
     self.group.insert(Perm()(0, 1, 2))
     self.assertFalse(self.group.is_transitive(points=range(self.N)))
     self.assertTrue(
         self.group.is_transitive(strict=False, points=range(self.N)))
Beispiel #4
0
def generate_cars(init_positions=None,
                  n_cars=None,
                  color=(20, 160, 140, 100),
                  radius_car=16,
                  map_size=None,
                  d2d=True):
    """Genera los autos
    :param init_positions: vector de posiciones iniciales
    :param n_cars: número de autos
    :param color: color de los autos
    :param radius_car: radio de los autos
    :param map_size: tamaño del mapa
    :param d2d: D2D flag
    :return:
    """
    if map_size is None:
        map_size = [1024, 720]
    cars = Group(prefix="C")  # Grupo de carros
    rand_centers = random.sample(init_positions, n_cars)
    i = 1
    for position in rand_centers:
        cars.add(
            Car(x=position[0],
                y=position[1],
                Id="C" + str(i),
                color=color,
                radius=radius_car,
                map_size=map_size,
                d2d=d2d,
                indx=i))
        i += 1
    return cars
Beispiel #5
0
 def test_orbits2(self):
     self.N = 4
     self.group = Group()
     self.group.insert(Perm()(0, 1))
     self.group.insert(Perm()(2, 3))
     self.assertFalse(self.group.is_transitive(points=range(self.N)))
     self.assertEqual(self.group.orbits(range(self.N)), [[0, 1], [2, 3]])
     self.assertEqual(self.group.orbits([0, 1]), [[0, 1]])
     self.assertEqual(self.group.orbits([0, 1, 2]), [[0, 1], [2, 3]])
Beispiel #6
0
 def test_orbits1(self):
     self.N = 3
     self.group = Group()
     self.group.insert(Perm()(0, 1))
     self.assertEqual(self.group.orbits(range(self.N)), [[0, 1], [2]])
     self.assertEqual(self.group.orbits([0, 1]), [[0, 1]])
     self.assertFalse(self.group.is_transitive(points=range(self.N)))
     self.assertTrue(
         self.group.is_transitive(points=range(self.N), strict=False))
Beispiel #7
0
 def test_is_subgroup(self):
     self.group2 = Group()
     # Make cyclic group C_N.
     self.group2.insert(Perm()(*range(self.N)))
     self.assertEqual(self.group2.order(), self.N)
     self.assertTrue(self.group2.is_subgroup(self.group1))
     self.assertTrue(self.group2.is_abelian())
     self.assertFalse(self.group1.is_abelian())
     self.assertFalse(self.group2.is_normal(self.group1))
Beispiel #8
0
 def run(this, group):
   vectors = []
   normals = []
   for i in range(this.numGroups):
     vectors.extend(group.getNext().vectors)
     normals.extend(group.getCurrent().normals)
   out = Group()
   out.vectors = vectors
   out.normals = normals
   return out
Beispiel #9
0
 def test_centralizer(self):
     # Tworze grupe cykliczna.
     self.group2 = Group()
     self.group2.insert(Perm()(*range(self.N)))
     self.assertEqual(self.group2.order(), self.N)
     # centrum grupy abelowej cyklicznej to cala grupa
     self.group3 = self.group2.center()
     self.assertEqual(self.group3.order(), self.N)
     # Dalej dla grupy symetrycznej.
     self.group2 = self.group1.center()
     self.assertEqual(self.group2.order(), 1)
Beispiel #10
0
def do_work(fd_vcf, tsv_pheno, tsv_haplo):
    vcf = Vcf(fd_vcf)
    vcf.load_meta_header()
    grps_pheno, grps_haplo = Group(tsv_pheno), Group(tsv_haplo)
    matrix, a_sites, a_groups = prepare(vcf, grps_pheno, grps_haplo)

    print matrix.shape
    print a_groups
    #values   = np.random.randn(100,100) * 10
    #a_sites  = ['1_100', '2_200', '3_300']
    #a_groups = ['grp1', 'grp1', 'grp2']
    cb_labels = ['HETE', 'HOMO_VAR', 'OTHER', 'NO_COVERAGE', 'HOMO_REF']
    drdplots.Heatmap(matrix, cb_labels, a_sites, a_groups).plot()
Beispiel #11
0
    def __init__(self, name, load=True):
        #Added
        self.users = {}
        self.groups = {}
        self.loggedInAs = None
        all_privs = {'Create_User': True, 'Delete_Tbl': True}
        #admin
        admin = User('admin', 'admin', all_privs, set(), set())
        self.users.update({'admin': admin})
        self.loggedInAs = admin
        #groups
        admin_group = Group('admins', {
            'Create_User': True,
            'Delete_Tbl': True
        }, set(), set())
        self.groups.update({'admins': admin_group})
        viewer_group = Group('admins', {}, set(), set())
        self.groups.update({'viewers': viewer_group})
        #Added
        self.tables = {}
        self._name = name

        self.savedir = f'dbdata/{name}_db'

        if load:
            try:
                self.load(self.savedir)
                print(f'Loaded "{name}".')
                return
            except:
                print(f'"{name}" db does not exist, creating new.')

        # create dbdata directory if it doesnt exist
        if not os.path.exists('dbdata'):
            os.mkdir('dbdata')

        # create new dbs save directory
        try:
            os.mkdir(self.savedir)
        except:
            pass

        # create all the meta tables
        self.create_table('meta_length', ['table_name', 'no_of_rows'],
                          [str, int])
        self.create_table('meta_locks', ['table_name', 'locked'], [str, bool])
        self.create_table('meta_insert_stack', ['table_name', 'indexes'],
                          [str, list])
        self.create_table('meta_indexes', ['table_name', 'index_name'],
                          [str, str])
        self.save()
Beispiel #12
0
def merge_tests(existing_tests, incoming_tests):
    """Given two sets of tests, merge the incoming tests into
    the existing tests."""

    # The merge will take the following steps:
    #   - already seen tests will only have "opt/debug_status" updated
    #   - newly failing tests will be added under the appropriate component
    #    - tests that are no longer failing will be marked as "passes" rather 
    #   than be removed from the resulting set
    #   - tests that were already marked as "passes" and still pass in a
    #   subsequent run of the script will be removed from the result set
    
    newly_failing, newly_passing, passing_removed = [], [], []
    not_seen_group = set(existing_tests.keys())

    def handle_passing_tests(group_name, not_seen):
        for test_name in list(not_seen): # leftover tests are no longer failing/skipped
            if existing_tests[group_name].tests[test_name].opt_status == 'passes' and \
                    existing_tests[group_name].tests[test_name].debug_status == 'passes':
                existing_tests[group_name].tests.pop(test_name)
                passing_removed.append(test_name)
            else:
                existing_tests[group_name].tests[test_name].opt_status = 'passes'
                existing_tests[group_name].tests[test_name].debug_status = 'passes'
                newly_passing.append(test_name)

    for group_name, incoming_group in incoming_tests.items():
        not_seen_group.discard(group_name)
        if group_name not in existing_tests:
            existing_tests[group_name] = Group(group_name, [])
        not_seen = set(existing_tests[group_name].tests.keys())
        for test_name, new_test in incoming_group.tests.items():
            if new_test.name in not_seen:  # test exists, so update fields
                for attr in ['opt_status', 'debug_status', 'xorig_and_fis', 'xorig_and_not_fis']:
                    setattr(existing_tests[group_name].tests[test_name], attr, getattr(new_test, attr))
                not_seen.discard(test_name)
            else: # new test
                existing_tests[group_name].tests[test_name] = new_test
                newly_failing.append(test_name)

        handle_passing_tests(group_name, not_seen)
        if len(existing_tests[group_name].tests) == 0:
            existing_tests.pop(group_name)

    for group_name in list(not_seen_group):
        handle_passing_tests(group_name, existing_tests[group_name].tests)
        existing_tests.pop(group_name)

    return existing_tests, newly_failing, newly_passing, passing_removed
Beispiel #13
0
def main():
    root = tk.Tk()
    root.geometry('890x680+120+50')
    root.resizable(width=False, height=False)

    groups = [
        Group('变电所变电所aaa' + str(i), '主经路主aaabbbb' + str(i),
              '分支线路分支线路支线路' + str(i), '群名称群名称名称aaaaaa' + str(i))
        for i in range(60)
    ]
    templates = [
        Template('Temp' + str(i), 'Content  Content ContentContent ' + str(i))
        for i in range(3)
    ]

    class WxBot:
        pass

    wxbot = WxBot()
    wxbot.self = WxBot()
    wxbot.self.name = '姜'
    frame = MainFrame(root, wxbot, groups, templates)
    frame.pack()

    # tk.Button(root, text='获取选择的群', command=lambda: print(gframe.get_selected())).pack()
    # tk.Button(root, text='search', command=lambda: print(gframe.search(keyword='1'))).pack()

    tk.mainloop()
Beispiel #14
0
def generate_groups(img):
    #give each component a different integer label in the output matrix
    labeled_img = np.zeros(img.shape)

    #all ones --> 8 connectivity (use cross shape for 4 connectivity)
    struct = np.ones((3, 3))
    n_features = label(img, structure=struct, output=labeled_img)

    groups_by_label = {}
    groups = []

    #use labels to put pixels into groups
    for y in range(len(img)):
        for x in range(len(img[0])):
            #foreground pixels
            if img[y][x]:
                curr_label = labeled_img[y][x]

                #create the group if it does not yet exist
                if curr_label not in groups_by_label:
                    groups_by_label[curr_label] = Group(curr_label)
                    groups.append(groups_by_label[curr_label])

                groups_by_label[curr_label].add((y, x))

    return groups
Beispiel #15
0
def get_tests_from_spreadsheet(service, spreadsheet_id, sheet_name):
    """Pulls down the latest copy of an existing Google sheet and 
    generates a list of Groups."""
    res = service.spreadsheets().values().get(spreadsheetId=spreadsheet_id, 
                                              range=sheet_name).execute()
    test_map = Group.from_csv_spreadsheet(res['values'])
    return test_map  # Used for generating 'existing_tests'
Beispiel #16
0
        def add_group(
            chain_map: Dict[Group, list],
            group_name: str,
            charge: int,
            atoms: Set[int],
        ) -> None:
            default = GroupsData.DEFAULTS[group_name]

            if ignore_protonations:
                chain_map[default].append(atoms)
            else:
                # NOTE(flamholz): We rely on the default number of
                # magnesiums being 0 (which it is).
                hydrogens = default.hydrogens + charge - default.charge
                group = Group(group_name, hydrogens, charge, default.nMg)
                if group not in chain_map:
                    # logging.warning('This protonation (%d) level is not
                    # allowed for terminal phosphate groups.' % hydrogens)
                    # logging.warning('Using the default protonation level (
                    # %d) for this name ("%s").' % (default.hydrogens,
                    # default.name))
                    raise GroupDecompositionError(
                        f"The group {group_name} cannot have nH = {hydrogens}"
                    )
                    # chain_map[default].append(atoms)
                else:
                    chain_map[group].append(atoms)
Beispiel #17
0
 def test_is_normal(self):
     a = Perm()(0, 1, 2)
     b = Perm()(0, 1)
     c = Perm()(0, 2, 1)
     G = Group()
     G.insert(a)
     G.insert(b)
     self.assertEqual(G.order(), 6)   # G = S_3
     H = Group()
     H.insert(a)
     H.insert(c)
     self.assertEqual(H.order(), 3)   # H = A_3
     self.assertTrue(H.is_normal(G))
Beispiel #18
0
  def run(this, frames):
    if this.lastFrame is None:
      this.lastFrame = frames.getNext()
    thisFrame = frames.getNext()
    out = Group()
    for i in range(min(len(thisFrame.values), len(this.lastFrame.values))) + [0]:
      out.addVector(this.lastFrame.values[i])
      out.addNormal(this.lastFrame.values[i])
      out.addVector(thisFrame.values[i])
      out.addNormal(thisFrame.values[i])

    this.lastFrame = thisFrame
    return out
Beispiel #19
0
 def test_is_subgroup(self):
     self.group2 = Group()
     # Tworze grupe cykliczna.
     self.group2.insert(Perm()(*range(self.N)))
     self.assertTrue(self.group2.is_subgroup(self.group1))
     self.assertTrue(self.group2.is_abelian())
     self.assertFalse(self.group1.is_abelian())
     self.assertFalse(self.group2.is_normal(self.group1))
Beispiel #20
0
    def test_groupAdd_shouldReturnNewGroupWithAllPeople(self):
        person_3 = Person('George', 'Francis')
        group_2 = Group('test2', [person_3])

        new_group = self.group + group_2

        self.assertEqual(new_group.people, [self.person_1, self.person_2, person_3])
        self.assertEqual(new_group.name, 'test')
Beispiel #21
0
def do_work(fd_vcf, csv):
    vcf = Vcf(fd_vcf)
    vcf.load_meta_header()
    grps = Group(csv)
    #sys.stderr.write("# Of groups loaded: %s\n" % grps.num())
    min_threshold = float(sys.argv[2])
    min_num_all = float(sys.argv[3])
    ComputeSnps(vcf, grps, min_threshold, min_num_all).run()
Beispiel #22
0
 def test_orbits1(self):
     self.N = 3
     self.group = Group()
     self.group.insert(Perm()(0,1))
     self.assertEqual(self.group.orbits(range(self.N)), [[0, 1],[2]])
     self.assertEqual(self.group.orbits([0, 1]), [[0, 1]])
     self.assertFalse(self.group.is_transitive(points=range(self.N)))
     self.assertTrue(self.group.is_transitive(points=range(self.N), strict=False))
Beispiel #23
0
 def test_is_subgroup(self):
     self.group2 = Group()
     # Make cyclic group C_N.
     self.group2.insert(Perm()(*range(self.N)))
     self.assertEqual(self.group2.order(), self.N)
     self.assertTrue(self.group2.is_subgroup(self.group1))
     self.assertTrue(self.group2.is_abelian())
     self.assertFalse(self.group1.is_abelian())
     self.assertFalse(self.group2.is_normal(self.group1))
Beispiel #24
0
class Database:
    '''
    Database class contains tables.
    '''
        #Add
        self.users = {}
        self.groups = {}
        self.loggedInAs = None
        all_privs = {'Create_User' : True, 'Delete_Tbl' : True}
        #admin
        admin = User('admin', 'admin', all_privs, set(), set())
        self.users.update({'admin': admin})
        self.loggedInAs = admin
        #groups
        admin_group = Group('admins', {'Create_User' : True, 'Delete_Tbl' : True}, set(), set())
        self.groups.update({'admins': admin_group})
        viewer_group = Group('admins', {}, set(), set())
        self.groups.update({'viewers': viewer_group})
Beispiel #25
0
 def test_orbits2(self):
     self.N = 4
     self.group = Group()
     self.group.insert(Perm()(0, 1))
     self.group.insert(Perm()(2, 3))
     self.assertFalse(self.group.is_transitive(points=range(self.N)))
     self.assertEqual(self.group.orbits(range(self.N)), [[0, 1],[2, 3]])
     self.assertEqual(self.group.orbits([0, 1]), [[0, 1]])
     self.assertEqual(self.group.orbits([0, 1, 2]), [[0, 1],[2, 3]])
Beispiel #26
0
 def test_group_adding(self):
     p0 = Person('Aliko', 'Dangote')
     p1 = Person('Bill', 'Gates')
     second_group = Group("Second", [p0, p1])
     third = self.first_group + second_group
     expected_name = self.first_group.name
     self.assertEqual(third.name, expected_name)
     expected_len = len(self.first_group) + len(second_group)
     self.assertEqual(len(third), expected_len)
def merge_groups(groups, dist_tol):
    """ Merges untill all groups have at least
    `dist_tol` distance between them
    Parameters
    ----------
    groups :obj:list of `Group`
        groups found using adjacency
    dist_tol : int
        minimum euclidean distance
        to be in same cluster
    Returns
    -------
    :obj:list of `Group`
    """
    #give groups initial labels = indexes
    for i in range(len(groups)):
        groups[i].updateLabel(i)

    uf = UnionFind(len(groups))

    #find labels to merge
    for i in range(len(groups)):
        curr_group = groups[i]
        #only look at groups farther in list
        for j in range(i, len(groups)):
            other_group = groups[j]

            #short circuit if already connected (minimize nearest neighbor calls)
            if not uf.find(curr_group.label, other_group.label):
                if Group.nearby(curr_group, other_group, dist_tol):
                    uf.union(curr_group.label, other_group.label)

    merged_groups = []
    unmerged_groups = []
    #iterate until all merges have been made
    while len(groups) > 0:
        curr_group = groups[0]
        merged_groups.append(curr_group)
        for j in range(1, len(groups)):
            other_group = groups[j]

            #on each iteration, one merged group moves to the new array
            if uf.find(curr_group.label, other_group.label):
                curr_group.merge(other_group)
            #all other groups are kept in the old array
            else:
                unmerged_groups.append(other_group)

        groups = unmerged_groups
        unmerged_groups = []
        
    for g in merged_groups:
        g.compute_info()

    return merged_groups
Beispiel #28
0
 def test_centralizer(self):
     # Tworze grupe cykliczna.
     self.group2 = Group()
     self.group2.insert(Perm()(*range(self.N)))
     self.assertEqual(self.group2.order(), self.N)
     # centrum grupy abelowej cyklicznej to cala grupa
     self.group3 = self.group2.center()
     self.assertEqual(self.group3.order(), self.N)
     # Dalej dla grupy symetrycznej.
     self.group2 = self.group1.center()
     self.assertEqual(self.group2.order(), 1)
Beispiel #29
0
    def logic(self):
        nr_containers = totContainers()
        port = Port("PiraeusPier2", nr_containers)
        threads = []
        groups = []
        nr_groups = 13
        colours = []
        colours.append(pygame.Color(228, 197, 73))
        colours.append(pygame.Color(185, 0, 37))
        colours.append(pygame.Color(78, 87, 111))
        colours.append(pygame.Color(12, 63, 50))
        colours.append(pygame.Color(236, 110, 0))
        colours.append(pygame.Color(68, 22, 33))
        colours.append(pygame.Color(143, 149, 160))
        colours.append(pygame.Color(185, 197, 201))
        colours.append(pygame.Color(35, 127, 125))
        colours.append(pygame.Color(149, 132, 103))
        colours.append(pygame.Color(0, 44, 125))
        colours.append(pygame.Color(0, 160, 213))
        colours.append(pygame.Color(166, 202, 87))
        colours.append(pygame.Color(228, 166, 156))

        for i in range(nr_groups - port.nr_docks):
            groups.append(Group(i, port, "outbound", nr_containers,
                                colours[i]))
        for i in range(nr_groups - port.nr_docks, nr_groups):
            groups.append(Group(i, port, "inbound", nr_containers, colours[i]))
        info = InfoPanel(port, groups)
        for i in range(nr_groups):
            thread = Thread(target=groups[i].manage, name=str(i), daemon=True)
            threads.append(thread)
        """info = Thread(target = info.give_info, name = str(nr_groups + 1), daemon = True)
        threads.append(info)"""
        for t in threads:
            t.start()
        graphics = Graphics(port, groups)
        graphics.display()
        while True:
            pass
Beispiel #30
0
def get_tests_from_report(report):
    """Loads tests from a json report (ie './mach test-info report ...')"""
    if type(report) == 'str':
        with open(report) as f:
            data = json.load(f)['tests']
    else:
        data = report.get('tests')

    test_map = {}
    for group, subtests in data.items():
        g = Group(group, subtests)
        test_map[group] = g
    return test_map  # Used for generating 'incoming_tests'
Beispiel #31
0
    def create_group(self, name, privs, del_privs, sel_privs):
        if self.loggedInAs.can_create():
            del_privileges = dict()
            sel_privileges = dict()

            for priv in del_privs:
                del_privileges.update({priv: True})

            for priv in sel_privs:
                sel_privileges.update({priv: True})
            self.groups.update({name: Group(name, privs, del_privileges, sel_privileges)})
            print("{g} Group has been created".format(g=name))
        else:
            print("You don't have the privileges to create a new Group")
Beispiel #32
0
def build_city(width=1280, height=720, edificesColor=(10, 200, 50)):
    """Contruye una ciudad con edificios
    Args:

    """
    # Para construir la Ciudad
    D = 8  # Separación entre calles (px)
    w = 51  # Ancho de los edificiós (px)
    h = 51  # Largo (altura rectangular) de los edificios (px)

    W = 1024  # Ancho del mapa (px)
    H = 720  # Largo del mapa (px)

    # Calcular número de edificios
    m = int(W / w)  # ¿Cuántos edificios caben a lo ancho del mapa?
    n = int(H / h)  # ¿Cuántos edificios caben a lo largo del mapa?
    edifices = Group(prefix="Edifice")  # Grupo de paredes

    centers_corner = []  # Esquina
    centers_street = []  # Centro calle
    offset_x = 5
    offset_y = 5
    rows = []
    # Contruir ciudad
    for i in range(m):
        for j in range(n):
            x = int(i * w + offset_x)
            y = int(j * h + offset_y)
            edifices.add(Edifice(x, y, w - D, h - D, color=edificesColor))
            rows.append([x + w, y + h])
            centers_street.append([x + w - int(D / 2), y + h - int(D / 2)])
        centers_corner.append(rows)
        rows = []
    # centers_corner = np.array(centers_corner, dtype='uint8')
    centers_corner = np.array(centers_corner)
    return edifices, centers_corner, centers_street
def generate_groups(img, orig_shape, scaled_shape):
    """ Finds groups using adjacency
    (dist_tol = 0)
    Parameters
    ----------
    img :obj:`numpy.ndarray`
        binary foreground image
    orig_shape : tuple
        shape of 2D image before scaling down
    scaled_shape : tuple
        shape of 2D image after scaling down
    Returns
    -------
    :obj:list of `Group`
    """
    #give each component a different integer label in the output matrix
    labeled_img = np.zeros(img.shape)

    #all ones --> 8 connectivity (use cross shape for 4 connectivity)
    struct = np.ones((3, 3))
    n_features = label(img, structure = struct, output = labeled_img)

    groups_by_label = {}
    groups = []

    #use labels to put pixels into groups
    for y in range(len(img)):
        for x in range(len(img[0])):
            #foreground pixels
            if img[y][x]:
                curr_label = labeled_img[y][x]

                #create the group if it does not yet exist
                if curr_label not in groups_by_label:
                    groups_by_label[curr_label] = Group(curr_label, orig_shape, scaled_shape)
                    groups.append(groups_by_label[curr_label])

                groups_by_label[curr_label].add((y, x))

    return groups
Beispiel #34
0
def merge_groups(groups, tol):
    #give groups initial labels = indexes
    for i in range(len(groups)):
        groups[i].updateLabel(i)

    uf = UnionFind(len(groups))

    #find labels to merge
    for i in range(len(groups)):
        curr_group = groups[i]
        #only look at groups farther in list
        for j in range(i, len(groups)):
            other_group = groups[j]

            #short circuit if already connected (minimize nearest neighbor calls)
            if not uf.find(curr_group.label, other_group.label):
                if Group.nearby(curr_group, other_group, tol):
                    uf.union(curr_group.label, other_group.label)

    merged_groups = []
    unmerged_groups = []
    #iterate until all merges have been made
    while len(groups) > 0:
        curr_group = groups[0]
        merged_groups.append(curr_group)
        for j in range(1, len(groups)):
            other_group = groups[j]

            #on each iteration, one merged group moves to the new array
            if uf.find(curr_group.label, other_group.label):
                curr_group.merge(other_group)
            #all other groups are kept in the old array
            else:
                unmerged_groups.append(other_group)

        groups = unmerged_groups
        unmerged_groups = []

    return merged_groups
Beispiel #35
0
def main():
    root = tk.Tk()
    root.geometry('600x720+120+50')
    root.resizable(width=False, height=False)

    groups = [
        Group('变电所变电所' + str(i % 10), '主经路主经路' + str(i % 20),
              '分支线路支线路' + str(i % 50), '台区台区台区台区', '群名称群名称' + str(i))
        for i in range(500)
    ]
    bdz_dict, zxl_dict, fzxl_dict, tq_dict = parse_group_dict(groups)

    gframe = GroupFrame(root, groups)
    sframe = SearchFrame(root, bdz_dict, zxl_dict, fzxl_dict, gframe)
    print(bdz_dict)
    print(zxl_dict)
    print(fzxl_dict)
    sframe.pack()
    gframe.pack()
    # tk.Button(root, text='获取选择的群', command=lambda:print(gframe.get_selected())).pack()
    # tk.Button(root, text='search', command=lambda:print(gframe.search(keyword='1'))).pack()

    tk.mainloop()
Beispiel #36
0
class GroupTest(unittest.TestCase):

    def setUp(self):
        p0 = Person('Aliko', 'Dangote')
        p1 = Person('Bill', 'Gates')
        p2 = Person('Warren', 'Buffet')
        self.first_group = Group('__VIP__', [p0, p1, p2])

    def test_group_init(self):
        self.assertEqual(self.first_group.name, '__VIP__')
        self.assertEqual(self.first_group.people[0].name, 'Aliko')

    def test_group_len_linst_people(self):
        self.assertEqual(len(self.first_group.people), 3)

    def test_group_print(self):
        self.assertEqual(str(self.first_group),
                         'Group __VIP__ with members Aliko Dangote, '
                         'Bill Gates, Warren Buffet')

    def test_group_item_print(self):
        self.assertEqual(self.first_group.__getitem__(0), 'Person 0: Aliko Dangote')

    def test_group_item_print_with_for_cycle(self):
        expected = ['Person 0: Aliko Dangote','Person 1: Bill Gates',
                    'Person 2: Warren Buffet']
        self.assertEqual(list(self.first_group), expected) # list involes iter() method under the hood

    def test_group_adding(self):
        p0 = Person('Aliko', 'Dangote')
        p1 = Person('Bill', 'Gates')
        second_group = Group("Second", [p0, p1])
        third = self.first_group + second_group
        expected_name = self.first_group.name
        self.assertEqual(third.name, expected_name)
        expected_len = len(self.first_group) + len(second_group)
        self.assertEqual(len(third), expected_len)
Beispiel #37
0
 def addGroup(self, name):
     grp = Group(None)
     grp.name = name
     self.groups.append(grp)
Beispiel #38
0
 def result_to_group(self,result):
         #id=result[0]
         grp = Group(result[2],result[1])
         grp.groupID = result[0]
         return grp
Beispiel #39
0
# Import the class Group from the file groups.py

from groups import Group

# Create an instance of the group (5,+)x(9,x)

print("Create a group (5,+)x(9,x)")
G = Group(["add", "mult"], [5, 9])

# print the group components

Gg = G.g("show")
g3 = G.g(3)
print("Element 3 = ", G.g(3))
print("Inverse of element 3 = ", G.inv(g3))

g7 = G.g(7)
g6 = G.g(6)
print("Element 7 = ", g7)
print("Element 6 = ", g6)
print("Multiplication of element 7 and element 6 = ", G.op(g7, g6))
print("Element 7 to the power of 3 = ", G.pow(g7, 3))

print("Group orders:")
Gg = G.g()
Ggo = G.go()
for (g, go) in zip(Gg, Ggo):
    print("Element ", g, " has order ", go)
Beispiel #40
0
 def setUp(self):
     self.N = 4
     # Tworze grupe symetryczna.
     self.group1 = Group()
     self.group1.insert(Perm()(0, 1))
     self.group1.insert(Perm()(*range(self.N)))
Beispiel #41
0
# Importing require modules
from groups import Group
from pure import setCrossProd

# Creating group and subgroup

print("Create (120,+)")
G = Group("add", 120)
G.g("show")
GS = G.sub([15, 30, 60])

# print the sub group components

GSg = GS.g()
GS.g("show")
print("Inverse of element 15 = ", GS.inv(15))
print("Multiplication of 15 and 30 = ", GS.op(15, 30))
print("15 to the power 3 = ", GS.pow(15, 3))

GSgo = GS.go()
for g, go in zip(GSg, GSgo):
    print("Element: ", g, " has order: ", go)
Beispiel #42
0
# Import the class Group from the file groups.py

from groups import Group

# Create an instance of the group (10,+)

G = Group("add", 10)

# print the group elements

G.g("show")

# Create an instance of the group (15,x)

H = Group("mult", 15)

# print the group elements

H.g("show")
Beispiel #43
0
 def test_normal_closure(self):
     n = 5
     # Tworze grupe cykliczna C_5.
     C5 = Group()
     C5.insert(Perm()(*range(n)))
     self.assertEqual(C5.order(), n)
     # Make Sym(5).
     S5 = Group()
     S5.insert(Perm()(*range(n)))
     S5.insert(Perm()(0, 1))
     self.assertEqual(S5.order(), 120)
     A5 = S5.normal_closure(C5)
     self.assertEqual(A5.order(), 60)
     for perm in A5.iterperms():
         self.assertTrue(perm.is_even())
Beispiel #44
0
class TestGroupOrbits(unittest.TestCase):

    def setUp(self): pass

    def test_orbits1(self):
        self.N = 3
        self.group = Group()
        self.group.insert(Perm()(0,1))
        self.assertEqual(self.group.orbits(range(self.N)), [[0, 1],[2]])
        self.assertEqual(self.group.orbits([0, 1]), [[0, 1]])
        self.assertFalse(self.group.is_transitive(points=range(self.N)))
        self.assertTrue(self.group.is_transitive(points=range(self.N), strict=False))

    def test_orbits2(self):
        self.N = 4
        self.group = Group()
        self.group.insert(Perm()(0, 1))
        self.group.insert(Perm()(2, 3))
        self.assertFalse(self.group.is_transitive(points=range(self.N)))
        self.assertEqual(self.group.orbits(range(self.N)), [[0, 1],[2, 3]])
        self.assertEqual(self.group.orbits([0, 1]), [[0, 1]])
        self.assertEqual(self.group.orbits([0, 1, 2]), [[0, 1],[2, 3]])

    def test_orbits3(self):  # grupa cykliczna
        self.N = 10
        self.group = Group()
        self.group.insert(Perm()(*range(self.N)))
        self.assertTrue(self.group.is_transitive(points=range(self.N)))

    def test_orbits4(self):
        self.N = 10
        self.group = Group()
        self.group.insert(Perm()(0, 1, 2))
        self.assertFalse(self.group.is_transitive(points=range(self.N)))
        self.assertTrue(self.group.is_transitive(strict=False, points=range(self.N)))

    def tearDown(self): pass
Beispiel #45
0
 def setUp(self):
     self.N = 4
     # Make symmetric group S_N.
     self.group1 = Group()
     self.group1.insert(Perm()(0, 1))
     self.group1.insert(Perm()(*range(self.N)))
Beispiel #46
0
class TestSubgroup(unittest.TestCase):

    def setUp(self):
        self.N = 4
        # Make symmetric group S_N.
        self.group1 = Group()
        self.group1.insert(Perm()(0, 1))
        self.group1.insert(Perm()(*range(self.N)))

    def test_subgroup_search(self):
        self.assertEqual(self.group1.order(), 24)
        # Dopuszczam permutacje parzyste - grupa alternujaca A_N.
        self.group2 = self.group1.subgroup_search(lambda x: x.is_even())
        self.assertEqual(self.group2.order(), 12)
        self.assertTrue(self.group2.is_transitive(points=range(self.N)))
        #print self.group2

    def test_stabilizer(self):
        self.group2 = self.group1.stabilizer(3)
        self.assertEqual(self.group2.order(), 6)
        #print self.group2

    def test_centralizer(self):
        # Tworze grupe cykliczna.
        self.group2 = Group()
        self.group2.insert(Perm()(*range(self.N)))
        self.assertEqual(self.group2.order(), self.N)
        # centrum grupy abelowej cyklicznej to cala grupa
        self.group3 = self.group2.center()
        self.assertEqual(self.group3.order(), self.N)
        # Dalej dla grupy symetrycznej.
        self.group2 = self.group1.center()
        self.assertEqual(self.group2.order(), 1)

    def test_normalizer(self):
        pass

    def test_normal_closure(self):
        n = 5
        # Tworze grupe cykliczna C_5.
        C5 = Group()
        C5.insert(Perm()(*range(n)))
        self.assertEqual(C5.order(), n)
        # Make Sym(5).
        S5 = Group()
        S5.insert(Perm()(*range(n)))
        S5.insert(Perm()(0, 1))
        self.assertEqual(S5.order(), 120)
        A5 = S5.normal_closure(C5)
        self.assertEqual(A5.order(), 60)
        for perm in A5.iterperms():
            self.assertTrue(perm.is_even())

    def test_derived_subgroup(self):
        pass

    def test_is_subgroup(self):
        self.group2 = Group()
        # Make cyclic group C_N.
        self.group2.insert(Perm()(*range(self.N)))
        self.assertEqual(self.group2.order(), self.N)
        self.assertTrue(self.group2.is_subgroup(self.group1))
        self.assertTrue(self.group2.is_abelian())
        self.assertFalse(self.group1.is_abelian())
        self.assertFalse(self.group2.is_normal(self.group1))

    def test_is_normal(self):
        a = Perm()(0, 1, 2)
        b = Perm()(0, 1)
        c = Perm()(0, 2, 1)
        G = Group()
        G.insert(a)
        G.insert(b)
        self.assertEqual(G.order(), 6)   # G = S_3
        H = Group()
        H.insert(a)
        H.insert(c)
        self.assertEqual(H.order(), 3)   # H = A_3
        self.assertTrue(H.is_normal(G))

    def tearDown(self): pass
Beispiel #47
0
 def test_orbits4(self):
     self.N = 10
     self.group = Group()
     self.group.insert(Perm()(0, 1, 2))
     self.assertFalse(self.group.is_transitive(points=range(self.N)))
     self.assertTrue(self.group.is_transitive(strict=False, points=range(self.N)))
Beispiel #48
0
 def test_orbits3(self):  # grupa cykliczna
     self.N = 10
     self.group = Group()
     self.group.insert(Perm()(*range(self.N)))
     self.assertTrue(self.group.is_transitive(points=range(self.N)))
Beispiel #49
0
class TestSubgroup(unittest.TestCase):

    def setUp(self):
        self.N = 4
        # Tworze grupe symetryczna.
        self.group1 = Group()
        self.group1.insert(Perm()(0, 1))
        self.group1.insert(Perm()(*range(self.N)))

    def test_subgroup_search(self):
        self.assertEqual(self.group1.order(), 24)
        # Dopuszczam permutacje parzyste - grupa alternujaca.
        self.group2 = self.group1.subgroup_search(lambda x: x.is_even())
        self.assertEqual(self.group2.order(), 12)
        self.assertTrue(self.group2.is_transitive(points=range(self.N)))
        #print self.group2

    def test_stabilizer(self):
        self.group2 = self.group1.stabilizer(3)
        self.assertEqual(self.group2.order(), 6)
        #print self.group2

    def test_centralizer(self):
        # Tworze grupe cykliczna.
        self.group2 = Group()
        self.group2.insert(Perm()(*range(self.N)))
        self.assertEqual(self.group2.order(), self.N)
        # centrum grupy abelowej cyklicznej to cala grupa
        self.group3 = self.group2.center()
        self.assertEqual(self.group3.order(), self.N)
        # Dalej dla grupy symetrycznej.
        self.group2 = self.group1.center()
        self.assertEqual(self.group2.order(), 1)

    def test_is_subgroup(self):
        self.group2 = Group()
        # Tworze grupe cykliczna.
        self.group2.insert(Perm()(*range(self.N)))
        self.assertTrue(self.group2.is_subgroup(self.group1))
        self.assertTrue(self.group2.is_abelian())
        self.assertFalse(self.group1.is_abelian())
        self.assertFalse(self.group2.is_normal(self.group1))

    def tearDown(self): pass
Beispiel #50
0
  def run(this):
    out = Group()
    out.addVector((0.5, 0.5, 0.5))
    out.addVector((-0.5, 0.5, 0.5))
    out.addVector((-0.5, -0.5, 0.5))
    out.addVector((0.5, -0.5, 0.5))
    out.addNormal((0.0, 0.0, 1.0))

    out.addVector((0.5, 0.5, -0.5))
    out.addVector((0.5, -0.5, -0.5))
    out.addVector((-0.5, -0.5, -0.5))
    out.addVector((-0.5, 0.5, -0.5))
    out.addNormal((0.0, 0.0, -1.0))
    
    out.addVector((-0.5, 0.5, -0.5))
    out.addVector((-0.5, -0.5, -0.5))
    out.addVector((-0.5, -0.5, 0.5))
    out.addVector((-0.5, 0.5, 0.5))
    out.addNormal((-1.0, 0.0, 0.0))

    out.addVector((0.5, 0.5, -0.5))
    out.addVector((0.5, 0.5, 0.5))
    out.addVector((0.5, -0.5, 0.5))
    out.addVector((0.5, -0.5, -0.5))
    out.addNormal((1.0, 0.0, 0.0))

    out.addVector((0.5, -0.5, -0.5))
    out.addVector((0.5, -0.5, 0.5))
    out.addVector((-0.5, -0.5, 0.5))
    out.addVector((-0.5, -0.5, -0.5))
    out.addNormal((0.0, -1.0, 0.0))

    out.addVector((0.5, 0.5, -0.5))
    out.addVector((-0.5, 0.5, -0.5))
    out.addVector((-0.5, 0.5, 0.5))
    out.addVector((0.5, 0.5, 0.5))
    out.addNormal((0.0, 1.0, 0.0))
    return out