Skip to content

Commit

Permalink
🎨 pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Nov 24, 2024
1 parent c46b1cf commit 15e873e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 36 deletions.
30 changes: 15 additions & 15 deletions src/mqt/qao/karp/karp_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def graph_coloring(
edges = list(graph.edges())
unique_vertices = set(graph.nodes())

unique_vertices = set(sorted(unique_vertices))
unique_vertices = set(unique_vertices)
{vertex: idx for idx, vertex in enumerate(unique_vertices, 1)}

problem = Problem()
Expand Down Expand Up @@ -592,7 +592,7 @@ def vertex_cover(
edges = list(graph.edges())
unique_vertices = set(graph.nodes())

unique_vertices = set(sorted(unique_vertices))
unique_vertices = set(unique_vertices)

problem = Problem()
variables = Variables()
Expand Down Expand Up @@ -760,7 +760,7 @@ def clique(
edges = list(graph.edges())
unique_vertices = set(graph.nodes())

unique_vertices = set(sorted(unique_vertices))
unique_vertices = set(unique_vertices)
{vertex: idx for idx, vertex in enumerate(unique_vertices, 1)}

problem = Problem()
Expand Down Expand Up @@ -954,7 +954,7 @@ def hamiltonian_path(
edges = set(graph.edges())
unique_vertices = set(graph.nodes())

unique_vertices = set(sorted(unique_vertices))
unique_vertices = set(unique_vertices)

problem = Problem()
variables = Variables()
Expand Down Expand Up @@ -1089,7 +1089,9 @@ def check_hamiltonian_path_solution(graph: nx.Graph, solution: list[int]) -> dic
return {"Valid Solution": True}

@staticmethod
def _hamiltonian_path_tsp(filename: str, cycle: bool = False, a: float = 1, b: float = 1) -> tuple[Any, Any, Any, Any]:
def _hamiltonian_path_tsp(
filename: str, cycle: bool = False, a: float = 1, b: float = 1
) -> tuple[Any, Any, Any, Any]:
"""Sets up the Hamiltonian path or Travelling Salesman Problem (TSP) as an optimization problem.
Args:
Expand Down Expand Up @@ -1129,7 +1131,7 @@ def _hamiltonian_path_tsp(filename: str, cycle: bool = False, a: float = 1, b: f
edges.add((u, v))
edges.add((v, u))

unique_vertices = set(sorted(unique_vertices))
unique_vertices = set(unique_vertices)

variables = Variables()

Expand Down Expand Up @@ -1236,7 +1238,7 @@ def travelling_salesman(
max_weight = max(weights)
a = max_weight * b + 1

unique_vertices = set(sorted(unique_vertices))
unique_vertices = set(unique_vertices)

variables = Variables()

Expand Down Expand Up @@ -1439,7 +1441,7 @@ def independent_set(
edges = list(graph.edges())
unique_vertices = set(graph.nodes())

unique_vertices = set(sorted(unique_vertices))
unique_vertices = set(unique_vertices)
{vertex: idx for idx, vertex in enumerate(unique_vertices, 1)}

a = b + 1
Expand Down Expand Up @@ -1653,7 +1655,7 @@ def max_cut(
edges = list(graph.edges())
unique_vertices = set(graph.nodes())

unique_vertices = set(sorted(unique_vertices))
unique_vertices = set(unique_vertices)

problem = Problem()
variables = Variables()
Expand Down Expand Up @@ -1751,8 +1753,8 @@ def directed_feedback_vertex_set(
msg = "'solve' must be True if 'solver_method', 'read_solution', 'solver_params', or 'visualize' are provided."
raise ValueError(msg)

unique_vertices:set[Any] = set()
edges:list[Any] = []
unique_vertices: set[Any] = set()
edges: list[Any] = []

if isinstance(input_data, str):
filename = input_data
Expand Down Expand Up @@ -1783,7 +1785,7 @@ def directed_feedback_vertex_set(

a = b * 3.0

unique_vertices = set(sorted(unique_vertices))
unique_vertices = set(unique_vertices)

variables = Variables()
y_vars = {v: variables.add_binary_variable(f"y_{v}") for v in unique_vertices}
Expand Down Expand Up @@ -2078,9 +2080,7 @@ def directed_feedback_edge_set(
return feedback_edge_set

@staticmethod
def check_directed_feedback_edge_set_solution(
graph: nx.DiGraph, solution: list[tuple[int, int]]
) -> dict[Any, Any]:
def check_directed_feedback_edge_set_solution(graph: nx.DiGraph, solution: list[tuple[int, int]]) -> dict[Any, Any]:
"""Validates a solution for the directed feedback edge set problem, ensuring the removal.
of specified edges results in an acyclic directed graph.
Expand Down
37 changes: 16 additions & 21 deletions src/mqt/qao/karp/karp_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def set_cover(
unique_elements.update(elements)
len(unique_elements)

unique_elements = set(sorted(unique_elements))
unique_elements = set(unique_elements)

problem = Problem()
variables = Variables()
Expand Down Expand Up @@ -179,9 +179,7 @@ def set_cover(
return solution_sets

@staticmethod
def check_set_cover_solution(
all_sets: Any, solution: Any
) -> dict[Any, Any]:
def check_set_cover_solution(all_sets: Any, solution: Any) -> dict[Any, Any]:
"""Validates a set cover solution by checking if all elements are covered.
Args:
Expand Down Expand Up @@ -344,9 +342,7 @@ def set_packing(
return solution_sets

@staticmethod
def check_set_packing_solution(
all_sets: Any, solution: Any
) -> dict[Any, Any]:
def check_set_packing_solution(all_sets: Any, solution: Any) -> dict[Any, Any]:
"""Validates a set packing solution by ensuring no sets overlap.
Args:
Expand Down Expand Up @@ -710,9 +706,7 @@ def three_d_matching(
pass

@staticmethod
def check_three_d_matching(
x: list[int], y: list[int], z: list[int], solution: Any
) -> dict[Any, Any]:
def check_three_d_matching(x: list[int], y: list[int], z: list[int], solution: Any) -> dict[Any, Any]:
"""Validates a 3D matching solution by ensuring each element in the solution matches exactly one element
from each of the sets x, y, and z, and that there are no repeated or mismatched elements.
Expand All @@ -735,11 +729,14 @@ def check_three_d_matching(
"""
used_elements: dict[Any, Any] = {}
errors: dict[Any, Any] = {"Invalid Triplets": [], "Non-matching Elements": [], "Repeated Elements": [], "Unused Elements": []}
errors: dict[Any, Any] = {
"Invalid Triplets": [],
"Non-matching Elements": [],
"Repeated Elements": [],
"Unused Elements": [],
}

for triplet in solution:


x1, y1, z1 = triplet

if x1 not in x or y1 not in y or z1 not in z:
Expand Down Expand Up @@ -830,7 +827,7 @@ def exact_cover(
unique_elements.update(elements)
len(unique_elements)

unique_elements = set(sorted(unique_elements))
unique_elements = set(unique_elements)

problem = Problem()
variables = Variables()
Expand Down Expand Up @@ -898,9 +895,7 @@ def exact_cover(
return solution_sets

@staticmethod
def check_exact_cover_solution(
sets: Any, solution: Any
) -> dict[Any, Any]:
def check_exact_cover_solution(sets: Any, solution: Any) -> dict[Any, Any]:
"""Validates an exact cover solution by ensuring each element is covered exactly once
and that there are no overlapping or missing elements.
Expand Down Expand Up @@ -984,7 +979,7 @@ def set_to_string(sets_list: list[tuple[int, list[int]]], weighted: bool) -> str
def print_solution(
problem_name: str = "",
file_name: str = "",
solution: str = "",
solution: str = "",
summary: str = "",
) -> None:
"""Prints the formatted solution of a problem to the console.
Expand All @@ -1007,7 +1002,7 @@ def save_solution(
problem_name: str = "",
file_name: str = "",
solution: str = "",
summary: str = "",
summary: str = "",
txt_outputname: str = "",
) -> None:
"""Saves the formatted solution of a problem to a specified file.
Expand All @@ -1029,7 +1024,7 @@ def save_solution(
print(f"Solution written to {txt_outputname}")

@staticmethod
def convert_dict_to_string(dictionary: dict [Any, Any]) -> str:
def convert_dict_to_string(dictionary: dict[Any, Any]) -> str:
"""Converts a dictionary of solution validation results into a readable string format.
Args:
Expand All @@ -1046,4 +1041,4 @@ def convert_dict_to_string(dictionary: dict [Any, Any]) -> str:
for sub_key, sub_value in value.items():
if sub_value:
result += f"\n'{sub_key}': {sub_value}"
return result
return result

0 comments on commit 15e873e

Please sign in to comment.