Пример #1
0
 def init_image_original(self):
     # set init image
     display_graph(self.residual_graph,
                   'dinic_init',
                   source=self.source,
                   sink=self.sink,
                   size_graph='s')
     return mpimg.imread('dinic_init.png')
Пример #2
0
    def init_image(self):

        display_graph(self.graph, filename="blocking_flow_init", source=self.source, sink=self.sink)
        # Find blocking_flow and store in self.block_flow
        self.block_flow, self.block_flow_mat = self.blocking_flow()
        self.idx = 0
        self.current_flow = 0
        print 'found blockflow', self.block_flow
        return mpimg.imread('blocking_flow_init.png')
Пример #3
0
    def next_image(self):
        if self.done:
            return None
        else:
            # self.idx keeps track of current image displayed in GUI
            if self.idx >= len(self.states):
                self.done = True
                return None

            # Display the sequence of images
            display_graph(self.states[self.idx][1],
                          filename="blocking_flow_next",
                          highlight_path=self.states[self.idx][0],
                          capacities=self.adj_matrix_capacitites,
                          source=self.source, sink=self.sink)
            self.current_flow = self.states[self.idx][2]
            print 'curr state', self.states[self.idx]
            self.idx += 1
            if self.idx >= len(self.states):
                self.done = True
            return mpimg.imread('blocking_flow_next.png')
Пример #4
0
def display_from(email_addr):
    emails = Message.objects(from_str=email_addr).all()
    count = emails.count()
    print "%s emails found authored by '%s'" % (count, email_addr)
    g = graph.generate_graph(emails)
    graph.display_graph(g)
Пример #5
0
def show_chat_freq_graph(event):
    chat_graph.display_graph()
Пример #6
0
def main() -> None:
    xa = list()
    ya = list()

    length = int()

    lagrange = Polynomial()
    newton = Polynomial()
    square = Polynomial()

    print(color.Fore.CYAN + "\t\t\t\t\tЛабораторная работа №1")

    while True:
        try:
            print(color.Fore.CYAN + "Введите значения Х (через пробел): " +
                  color.Fore.RESET,
                  end='')
            xa = dispenser(input())

            print(color.Fore.CYAN + "Введите значения Y (через пробел): " +
                  color.Fore.RESET,
                  end='')
            ya = dispenser(input())

            if len(xa) != len(ya):
                raise RuntimeError

            print(color.Fore.CYAN + "Введите значения M: " + color.Fore.RESET,
                  end='')
            ma = int(input())

            if ma >= len(xa):
                raise ReferenceError

            lagrange = lagrange_polynomial(xa, ya)

            print(color.Fore.CYAN + "Полином Лагранжа: " + color.Fore.RESET,
                  end='')
            print_polynomial(lagrange)

            newton = newton_polynomial(xa, ya)

            print(color.Fore.CYAN + "Полином Ньютона: " + color.Fore.RESET,
                  end='')
            print_polynomial(newton)

            square = square_polynomial(xa, ya, ma)

            print(color.Fore.CYAN + f"Полином среднеквад. co степ {ma}: " +
                  color.Fore.RESET,
                  end='')
            print_polynomial(square)

            graph.display_graph(xa, ya, (lagrange, newton, square), ma)

        except ReferenceError:
            print(color.Fore.RED +
                  "Значение m > n. Введите значения повторно." +
                  color.Fore.RESET)

        except RuntimeError:
            print(
                color.Fore.RED +
                "Количество значений Х и Y не совпадает. Введите значения повторно."
                + color.Fore.RESET)

        except ValueError:
            print(color.Fore.RED +
                  "Вы ввели неправильные значения Х или Y. Попробуйте снова." +
                  color.Fore.RESET)

        except:
            print(color.Fore.RED + "Неизвестная ошибка." + color.Fore.RESET)
def find_important(G, n):
  scores = nx.betweenness_centrality(G).items()
  l = [ ] 
  for (item, score) in scores:
    l.append((score, item))
  l.sort(reverse=True)
  important = []
  for i in range(n):
    important.append(l[i][1])
  return important
  
if __name__ == '__main__':
  g = graph.get_graph('/data/512/10000-twitter.gexf', limit=10000)
  top_subgraphs = graph.get_subgraphs(g, k=1)
  g = top_subgraphs[0]
  graph.display_graph(g)
  #t = find_best_params(g)
  #t2 = find_best_weighted_params(g)

  labels, score_1 = scluster(g, 4, 3)
  graph.display_graph_clusters(g, labels)

  important = find_important(g, 4)
  labels, score_2 = weighted_scluster(g, 4, 3, important)
  graph.display_graph_clusters(g, labels)

  print score_1, score_2

  # Sample
  # g = sample_graph()
  # important = find_important(g, 2)
Пример #8
0
 def init_image_original(self):
     # set init image
     display_graph(self.residual_graph, 'dinic_init', source=self.source, sink=self.sink, size_graph = 's')
     return mpimg.imread('dinic_init.png')