opt.single_objective.comb.min_multi_cut_problem package

Submodules

opt.single_objective.comb.min_multi_cut_problem.min_multi_cut_problem module

class opt.single_objective.comb.min_multi_cut_problem.min_multi_cut_problem.MinMultiCutProblem(graph: Graph, source_terminal_pairs: list[tuple[int, int]])

Bases: Problem

Class representing the Minimum Multi Cut Problem.

This class inherits from the Problem class and is used to define and solve the Minimum Multi Cut Problem. The problem is defined by a graph and a list of source terminal pairs.

graph

Graph.

Type:

nx.Graph

source_terminal_pairs

list of pairs that represent source and terminal nodes

Type:

list[tuple[int,int]]

__init__(graph

nx.Graph, source_terminal_pairs: list): Initializes a new instance of the MinMultiCutProblem class.

__load_from_files__(graph_file_path

str, source_terminal_pairs_file_path: str) -> tuple: Static function that reads problem data from files.

from_input_files(graph_file_path

str, source_terminal_pairs_file_path: str): Creates a new MinMultiCutProblem instance when the input file and input format are specified.

__copy__() MinMultiCutProblem

Internal copy of the MinMultiCutProblem problem.

copy() MinMultiCutProblem

Copy the MinMultiCutProblem problem.

graph() nx.Graph

Property getter for the graph of the target problem.

source_terminal_pairs() list[tuple[int, int]]

Property getter for the source_terminal_pairs of the target problem.

string_rep(delimiter

str, indentation: int = 0, indentation_symbol: str = ‘’, group_start: str = ‘{’, group_end: str = ‘}’) -> str: String representation of the MinMultiCutProblem instance.

__str__() str

String representation of the MinMultiCutProblem structure.

__repr__() str

Representation of the MinMultiCutProblem instance.

__format__() str

Formatted MinMultiCutProblem instance.

copy() MinMultiCutProblem

Copy the MinMultiCutProblem problem

Returns:

new MinMultiCutProblem instance with the same properties

Return type:

MinMultiCutProblem

classmethod from_graph_and_source_terminal_pairs(graph: Graph, source_terminal_pairs: list)

Additional constructor. Create new MinMultiCutProblem instance when graph and source_terminal_pairs are specified

Parameters:
  • graph (nx.Graph) – graph of the problem

  • source_terminal_pairs (list[tuple[int,int]]) – source_terminal_pairs of the problem

classmethod from_input_files(graph_file_path: str, source_terminal_pairs_file_path: str) MinMultiCutProblem

Additional constructor. Create new MinMultiCutProblem instance when input file and input format are specified

Parameters:
  • input_file_path (str) – path of the input file with problem graph

  • source_terminal_pairs_file_path (str) – path of the input file with problem source_terminal_pairs

Returns:

class instance

Return type:

MinMultiCutProblem

property graph: Graph

Property getter for graph of the target problem

Returns:

graph of the target problem instance

Return type:

nx.Graph

property source_terminal_pairs: list[tuple[int, int]]

Property getter for source_terminal_pairs of the target problem

Returns:

source_terminal_pairs of the target problem instance

Return type:

list

string_rep(delimiter: str, indentation: int = 0, indentation_symbol: str = '', group_start: str = '{', group_end: str = '}') str

String representation of the MinMultiCutProblem instance

Parameters:
  • delimiter (str) – delimiter between fields

  • indentation (int, optional, default value 0) – level of indentation

  • indentation_symbol (str, optional, default value '') – indentation symbol

  • group_start (str, optional, default value '{') – group start string

  • group_end (str, optional, default value '}') – group end string

Returns:

string representation of instance that controls output

Return type:

str

opt.single_objective.comb.min_multi_cut_problem.min_multi_cut_problem_bit_array_solution module

The minimum_multi_cut_problem_bit_array_solution contains class MinMultiCutProblemBitArraySolution, that represents solution of the Minimum Multi Cut Problem, where BitArray representation of the problem has been used.

class opt.single_objective.comb.min_multi_cut_problem.min_multi_cut_problem_bit_array_solution.MinMultiCutProblemBitArraySolution(random_seed: int | None = None, evaluation_cache_is_used: bool = False, evaluation_cache_max_size: int = 0, distance_calculation_cache_is_used: bool = False, distance_calculation_cache_max_size: int = 0)

Bases: Solution[BitArray, str]

argument(representation: BitArray) str

Argument of the target solution

Parameters:

representation (BitArray) – internal representation of the solution

Returns:

solution code

Return type:

str

calc_fitness(representation: BitArray, graph: Graph, source_terminal_pairs: list[tuple[int, int]]) tuple[bool, float, float]
calculate_quality_directly(representation: BitArray, problem: MinMultiCutProblem) QualityOfSolution

Fitness calculation of the minimum multi cut binary BitArray solution

Parameters:
  • representation (BitArray) – native representation of solution whose fitness is calculated

  • problem (Problem) – problem that is solved

Returns:

objective value, fitness value and feasibility of the solution instance

Return type:

QualityOfSolution

copy() MinMultiCutProblemBitArraySolution

Copy the MinMultiCutProblemBitArraySolution

Returns:

new MinMultiCutProblemBitArraySolution instance with the same properties

Return type:

MinMultiCutProblemBitArraySolution

copy_from(original) None

Copy all data from the original target solution

init_from(representation: BitArray, problem: Problem) None

Initialization of the solution, by setting its native representation

Parameters:
  • representation (BitArray) – representation that will be ste to solution

  • problem (Problem) – problem which is solved by solution

init_random(problem: Problem) None

Random initialization of the solution

Parameters:

problem (Problem) – problem which is solved by solution

is_feasible_sol(representation: BitArray, graph: Graph, source_terminal_pairs: list[tuple[int, int]]) bool
native_representation(representation_str: str) BitArray

Obtain BitArray representation from string representation of the BitArray binary solution of the Minimum Multi Cut problem

Parameters:

representation_str (str) – solution’s representation as string

Returns:

solution’s representation as BitArray

Return type:

BitArray

representation_distance_directly(solution_code_1: str, solution_code_2: str) float

Calculating distance between two solutions determined by its code

Parameters:
  • solution_code_1 (str) – solution code for the first solution

  • solution_code_2 (str) – solution code for the second solution

Returns:

distance between two solutions represented by its code

Return type:

float

string_rep(delimiter: str = '\n', indentation: int = 0, indentation_symbol: str = '   ', group_start: str = '{', group_end: str = '}') str

String representation of the solution instance

Parameters:
  • delimiter (str) – delimiter between fields

  • indentation (int, optional, default value 0) – level of indentation

  • indentation_symbol (str, optional, default value '') – indentation symbol

  • group_start (str, optional, default value '{') – group start string

  • group_end (str, optional, default value '}') – group end string

Returns:

string representation of instance that controls output

Return type:

str

opt.single_objective.comb.min_multi_cut_problem.min_multi_cut_problem_bit_array_solution.random() x in the interval [0, 1).

Module contents