Skip to content

Commit

Permalink
SAVES
Browse files Browse the repository at this point in the history
  • Loading branch information
petarpetrovv committed Nov 24, 2024
1 parent 0ecc21a commit 6b079a6
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/mqt/qao/karp/karp_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from collections import defaultdict
from functools import partial
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal
from typing import TYPE_CHECKING, Any, Literal, Union

import matplotlib.pyplot as plt
import networkx as nx
Expand Down Expand Up @@ -136,8 +136,7 @@ def sat(
clauses = [[str(item[0]), str(item[1])] for item in input_data]
filename = ""
else:
msg = "Invalid input_data type. Expected str or list[tuple[int, int]]."
raise ValueError(msg)
raise ValueError("Invalid input_data type. Expected str or list[tuple[int, int]].")

graph = KarpNumber._create_graph(clauses)

Expand Down Expand Up @@ -305,7 +304,7 @@ def three_sat(
@staticmethod
def check_three_sat_solution(
clauses: list[list[str]], solution: dict[str, float]
) -> dict[str, bool | list[list[str]] | dict[str, str]]:
) -> dict[str, Union[bool, list[list[str]], dict[str, str]]]:
"""Validates a solution for the 3-SAT problem by checking clause satisfaction."""
not_satisfied_clauses = []

Expand Down Expand Up @@ -741,7 +740,7 @@ def number_partition(
@staticmethod
def check_number_partition_solution(
elements: list[int], set_variables: dict[str, float]
) -> dict[str, int | bool | list[int]] | dict[Any, Any]:
) -> dict[str, int | int | bool | list[int]] | dict[Any, Any]:
"""Validates a number partition solution by comparing subset sums."""
set_1 = []
set_2 = []
Expand All @@ -763,7 +762,7 @@ def check_number_partition_solution(
set_2.append(elements[index])
missing_elements.remove(elements[index])

result: dict[str, int | bool | list[int]] = {
result: dict[str, Union[int, bool, list[int]]] = {
"Sum 1": sum_1,
"Sum 2": sum_2,
}
Expand All @@ -785,15 +784,15 @@ def job_sequencing(
b: float = 1,
solve: bool = False,
solver_method: Callable[..., Any] | None = None,
read_solution: Literal["print", "file"] | None = None,
read_solution : Literal["print", "file"] | None = None,
solver_params: dict[str, Any] | None = None,
) -> Problem | list[list[int]]:
"""Initializes and optionally solves a job sequencing problem to minimize scheduling conflicts. Pattern check for files is not included."""
if any([solver_method is not None, read_solution is not None, solver_params is not None]) and not solve:
msg = "'solve' must be True if 'solver_method', 'read_solution', or 'solver_params' are provided."
raise ValueError(msg)

if isinstance(input_data, str):
if isinstance(input_data , str):
filename = input_data
try:
with Path(filename).open(encoding="utf-8") as file:
Expand Down

0 comments on commit 6b079a6

Please sign in to comment.