def get_results(self):
     for f in self.parent.upper_frame.right_frame.list_files:
         structure = read_file(join("Data/all", f), f in listFiles)
         if self.parent.upper_frame.left_frame.algo.get() == 0:
             preferences = structure["preferences"]
             if self.parent.upper_frame.left_frame.filtered.get():
                 preferences, nb_voters, nb_unique = remove_last_ballots(
                     preferences)
             candidates = structure["candidates"]
             ensemble, best = bnb(len(preferences), preferences, candidates)
             axes, card = find_axes2(best[0][0], candidates)
             axes = filter_symmetric_axes(axes)
             for axis in axes:
                 self.results.append((f, axis))
         else:
             if self.parent.upper_frame.left_frame.dissimilarity.get() == 0:
                 dissimilarity_function = dissimilarity_and_n
             elif self.parent.upper_frame.left_frame.dissimilarity.get(
             ) == 1:
                 dissimilarity_function = dissimilarity_and_or
             else:
                 dissimilarity_function = dissimilarity_over_over
             if f in listFiles:
                 t, permutations = find_axis_from_structure(
                     structure, dissimilarity_function,
                     self.parent.upper_frame.left_frame.weighted.get())
             else:
                 t, permutations = find_axis_from_structure(
                     structure,
                     dissimilarity_function,
                     self.parent.upper_frame.left_frame.weighted.get(),
                     unwanted_candidates=[2, 3, 7, 11])
             permutations = filter_symmetric_axes(permutations[1])
             for permutation in permutations:
                 self.results.append((f, permutation))
 def get_results(self):
     for f in self.parent.upper_frame.right_frame.list_files:
         structure = read_file(join("Data/all", f), f in listFiles)
         if self.parent.upper_frame.left_frame.algo.get() == 0:
             preferences = structure["preferences"]
             if self.parent.upper_frame.left_frame.filtered.get():
                 preferences, nb_voters, nb_unique = remove_last_ballots(preferences)
             candidates = structure["candidates"]
             ensemble, best = bnb(len(preferences), preferences, candidates)
             axes, card = find_axes2(best[0][0], candidates)
             axes = filter_symmetric_axes(axes)
             for axis in axes:
                 self.results.append((f, axis))
         else:
             if self.parent.upper_frame.left_frame.dissimilarity.get() == 0:
                 dissimilarity_function = dissimilarity_and_n
             elif self.parent.upper_frame.left_frame.dissimilarity.get() == 1:
                 dissimilarity_function = dissimilarity_and_or
             else:
                 dissimilarity_function = dissimilarity_over_over
             if f in listFiles:
                 t, permutations = find_axis_from_structure(structure, dissimilarity_function,
                                                            self.parent.upper_frame.left_frame.weighted.get())
             else:
                 t, permutations = find_axis_from_structure(structure, dissimilarity_function,
                                                            self.parent.upper_frame.left_frame.weighted.get(),
                                                            unwanted_candidates=[2, 3, 7, 11])
             permutations = filter_symmetric_axes(permutations[1])
             for permutation in permutations:
                 self.results.append((f, permutation))
def calculate_bnb(self, file, vrow, filtered):
    structure = read_file("Data/all/" + str(file), file in listFiles)
    if not filtered:
        preferences = structure["preferences"]
        candidates = structure["candidates"]
        Label(self, text=str(structure["nb_voters"])).grid(row=vrow, column=3)
        Label(self, text=str(structure["nb_unique_orders"])).grid(row=vrow,
                                                                  column=5)
    else:
        preferences_bis = structure["preferences"]
        preferences, nb_voters, nb_unique = remove_last_ballots(
            preferences_bis)
        candidates = structure["candidates"]
        Label(self, text=str(nb_voters)).grid(row=vrow, column=3)
        Label(self, text=str(nb_unique)).grid(row=vrow, column=5)

    t1 = time()
    ensemble, best = bnb(len(preferences), preferences, candidates)
    t2 = time()
    Label(self, text=str(best[1])).grid(row=vrow, column=7)
    Label(self, text=str(len(best[0][0]))).grid(row=vrow, column=9)
    if not filtered:
        Label(self, text=str(best[1] * 100.0 / structure["nb_voters"])).grid(
            row=vrow, column=11)
    else:
        Label(self, text=str(best[1] * 100.0 / nb_voters)).grid(row=vrow,
                                                                column=11)
    axes, card = find_axes2(best[0][0], candidates)

    Label(self, text=str(len(axes))).grid(row=vrow, column=13)
    Label(self, text=str(t2 - t1)).grid(row=vrow, column=15)
def calculate_bnb(self, file, vrow, filtered):
    structure = read_file("Data/all/" + str(file), file in listFiles)
    if not filtered:
        preferences = structure["preferences"]
        candidates = structure["candidates"]
        Label(self, text=str(structure["nb_voters"])).grid(row=vrow, column=3)
        Label(self, text=str(structure["nb_unique_orders"])).grid(row=vrow, column=5)
    else:
        preferences_bis = structure["preferences"]
        preferences, nb_voters, nb_unique = remove_last_ballots(preferences_bis)
        candidates = structure["candidates"]
        Label(self, text=str(nb_voters)).grid(row=vrow, column=3)
        Label(self, text=str(nb_unique)).grid(row=vrow, column=5)

    t1 = time()
    ensemble, best = bnb(len(preferences), preferences, candidates)
    t2 = time()
    Label(self, text=str(best[1])).grid(row=vrow, column=7)
    Label(self, text=str(len(best[0][0]))).grid(row=vrow, column=9)
    if not filtered:
        Label(self, text=str(best[1] * 100.0 / structure["nb_voters"])).grid(row=vrow, column=11)
    else:
        Label(self, text=str(best[1] * 100.0 / nb_voters)).grid(row=vrow, column=11)
    axes, card = find_axes2(best[0][0], candidates)

    Label(self, text=str(len(axes))).grid(row=vrow, column=13)
    Label(self, text=str(t2 - t1)).grid(row=vrow, column=15)
Beispiel #5
0
def axes_to_latex_graph_bnb(f, axis, name=None):
    """
    Returns the LaTeX code to display the axis
    :param structure: structure extracted from a file or directory
    :param axis: axis corresponding to the file, according to wikipedia
    :param name: name that will be given to the figures
    :param dissimilarity_function: function to use to calculate dissimilarity between 2 candidates
    :param weighted: if True, matrices scores are calculated with the weighted gradient
    :param unwanted_candidates: list of candidates to exclude from the search
    :return: string containing the LaTeX code
    """

    structure = read_file(f)
    preferences = structure["preferences"]
    candidates = [i + 1 for i in range(len(structure["candidates"]))]
    bb, best = bnb(len(preferences), preferences, candidates)
    permutations, card = find_axes2(best[0][0], candidates)

    matches = get_matches(axis)
    length_unit = str(len(permutations[0]) + 1)
    res = "\\section{" + str(name) + "}" if name else ""
    res += "\\begin{center}\n"

    for permutation in permutations:
        # beginning of the environment
        res += "\\begin{figure}\n"
        res += "\\begin{tikzpicture}[x=\\textwidth/" + length_unit + ", y=\\textwidth/" + length_unit + "]\n"
        # Adding the x and y axes
        res += "\\draw[->, >=latex] (0,0) -- (" + length_unit + ",0);\n"
        res += "\\draw[->, >=latex] (0,0) -- (0, 5.5);\n"
        #res += "\\draw[->, >=latex] (0,0) -- (" + length_unit + ",0);\n"
        #res += "\\draw[->, >=latex] (0,0) -- (0," + length_unit + ");\n"
        # Adding the legend below the x axis
        for i in range(len(permutation)):
            res += "\\draw (" + str(i + 1) + ",-0.1) node[below] {" + str(
                permutation[i]) + "};\n"

        res += "\\draw plot[ultra thick]coordinates{"
        temp = ""  # string for the circles marking the dots
        for i in range(len(permutation)):
            if permutation[i] in matches:
                res += "(" + str(i + 1) + "," + str(
                    matches[permutation[i]]) + ")"
                temp += "\\draw[fill=black] (" + str(i + 1) + "," + str(
                    matches[permutation[i]]) + ") circle (0.1);\n"
        res += "};\n"
        res += temp  # ading the circles
        res += "\\end{tikzpicture}\n"
        if name:
            res += "\\caption{Permutation " + str(
                permutations.index(permutation)) + " of " + name + "}\n"
        res += "\\end{figure}\n"

    res += "\\end{center}\n\\clearpage\n"

    return res
Beispiel #6
0
def axes_to_latex_graph_bnb(f, axis, name=None):
    """
    Returns the LaTeX code to display the axis
    :param structure: structure extracted from a file or directory
    :param axis: axis corresponding to the file, according to wikipedia
    :param name: name that will be given to the figures
    :param dissimilarity_function: function to use to calculate dissimilarity between 2 candidates
    :param weighted: if True, matrices scores are calculated with the weighted gradient
    :param unwanted_candidates: list of candidates to exclude from the search
    :return: string containing the LaTeX code
    """

    structure = read_file(f)
    preferences = structure["preferences"]
    candidates = [i+1 for i in range(len(structure["candidates"]))]
    bb, best = bnb(len(preferences), preferences, candidates)
    permutations, card = find_axes2(best[0][0], candidates)

    matches = get_matches(axis)
    length_unit = str(len(permutations[0]) + 1)
    res = "\\section{" + str(name) + "}" if name else ""
    res += "\\begin{center}\n"

    for permutation in permutations:
        # beginning of the environment
        res += "\\begin{figure}\n"
        res += "\\begin{tikzpicture}[x=\\textwidth/" + length_unit + ", y=\\textwidth/" + length_unit + "]\n"
        # Adding the x and y axes
        res += "\\draw[->, >=latex] (0,0) -- (" + length_unit + ",0);\n"
        res += "\\draw[->, >=latex] (0,0) -- (0, 5.5);\n"
        #res += "\\draw[->, >=latex] (0,0) -- (" + length_unit + ",0);\n"
        #res += "\\draw[->, >=latex] (0,0) -- (0," + length_unit + ");\n"
        # Adding the legend below the x axis
        for i in range(len(permutation)):
            res += "\\draw (" + str(i+1) + ",-0.1) node[below] {" + str(permutation[i]) + "};\n"

        res += "\\draw plot[ultra thick]coordinates{"
        temp = ""  # string for the circles marking the dots
        for i in range(len(permutation)):
            if permutation[i] in matches:
                res += "(" + str(i+1) + "," + str(matches[permutation[i]]) + ")"
                temp += "\\draw[fill=black] (" + str(i+1) + "," + str(matches[permutation[i]]) + ") circle (0.1);\n"
        res += "};\n"
        res += temp  # ading the circles
        res += "\\end{tikzpicture}\n"
        if name:
            res += "\\caption{Permutation " + str(permutations.index(permutation)) + " of " + name + "}\n"
        res += "\\end{figure}\n"

    res += "\\end{center}\n\\clearpage\n"

    return res