opt.single_objective.comb.max_ones_count_problem package

Submodules

opt.single_objective.comb.max_ones_count_problem.command_line module

The command_line module is used for obtaining execution parameters for execution of the optimizers for max ones problem.

opt.single_objective.comb.max_ones_count_problem.command_line.parse_arguments()

The parse_arguments function parses execution parameters for execution of the optimizers for max ones problem.

opt.single_objective.comb.max_ones_count_problem.max_ones_count_problem module

class opt.single_objective.comb.max_ones_count_problem.max_ones_count_problem.MaxOnesCountProblem(dim: int)

Bases: Problem

Class representing the Ones Count Max Problem.

This class inherits from the Problem class and is used to define and solve the Ones Count Max Problem. The problem is defined by a dimension, which represents the number of variables in the problem.

dimension

The dimension of the problem.

Type:

int

__init__(dim

int): Initializes a new instance of the MaxOnesCountProblem class.

from_dimension(dimension

int): Creates a new MaxOnesCountProblem instance when the dimension is specified.

__load_from_file__(file_path

str, data_format: str) -> int: Static function that reads problem data from a file.

from_input_file(input_file_path

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

__copy__() MaxOnesCountProblem

Internal copy of the MaxOnesCountProblem problem.

copy() MaxOnesCountProblem

Copy the MaxOnesCountProblem problem.

dimension() int

Property getter for the dimension 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 MaxOnesCountProblem instance.

__str__() str

String representation of the MaxOnesCountProblem structure.

__repr__() str

Representation of the MaxOnesCountProblem instance.

__format__(spec

str) -> str: Formatted MaxOnesCountProblem instance.

copy()

Copy the MaxOnesCountProblem problem

Returns:

new MaxOnesCountProblem instance with the same properties

Return type:

MaxOnesCountProblem

property dimension: int

Property getter for dimension of the target problem

Returns:

dimension of the target problem instance

Return type:

int

classmethod from_dimension(dimension: int)

Additional constructor. Create new MaxOnesCountProblem instance when dimension is specified

Parameters:

dimension (int) – dimension of the problem

classmethod from_input_file(input_file_path: str, input_format: str)

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

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

  • input_format (str) – format of the input

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

String representation of the MaxOneProblem 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.max_ones_count_problem.max_ones_count_problem_bit_array_solution module

The ones_count_max_problem_bit_array_solution contains class MaxOnesCountProblemBitArraySolution, that represents solution of the Ones Count Max Problem, where BitArray representation of the problem has been used.

class opt.single_objective.comb.max_ones_count_problem.max_ones_count_problem_bit_array_solution.MaxOnesCountProblemBitArraySolution(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

calculate_quality_directly(representation: BitArray, problem: Problem) QualityOfSolution

Fitness calculation of the max ones 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()

Copy the MaxOnesCountProblemBitArraySolution

Returns:

new MaxOnesCountProblemBitArraySolution instance with the same properties

Return type:

MaxOnesCountProblemBitArraySolution

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

native_representation(representation_str: str) BitArray

Obtain BitArray representation from string representation of the BitArray binary solution of the Max Ones 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.max_ones_count_problem.max_ones_count_problem_bit_array_solution.random() x in the interval [0, 1).

opt.single_objective.comb.max_ones_count_problem.max_ones_count_problem_ilp_linopy module

class opt.single_objective.comb.max_ones_count_problem.max_ones_count_problem_ilp_linopy.MaxOnesCountProblemIntegerLinearProgrammingSolution(sol: MaxOnesCountProblemIntegerLinearProgrammingSolver)

Bases: SolutionVoidObject

string_representation()

String representation of the target solution

Parameters:

representation (R_co) – internal representation of the solution

Returns:

string representation of the solution

Return type:

str

class opt.single_objective.comb.max_ones_count_problem.max_ones_count_problem_ilp_linopy.MaxOnesCountProblemIntegerLinearProgrammingSolver(output_control: OutputControl = None, problem: MaxOnesCountProblem = None)

Bases: Optimizer

copy()

Copy the current algorithm

Returns:

new MaxOnesCountProblemIntegerLinearProgrammingSolver instance with the same properties

Return type:

:class:MaxOnesCountProblemIntegerLinearProgrammingSolver

classmethod from_construction_tuple(construction_params: MaxOnesCountProblemIntegerLinearProgrammingSolverConstructionParameters = None)

Additional constructor. Create new MaxOnesCountProblemIntegerLinearProgrammingSolver instance from construction parameters

Parameters:

construction_params (MaxOnesCountProblemIntegerLinearProgrammingSolverConstructionParameters) – parameters for construction

property model: Model

Property getter for the ILP model

Returns:

model of the problem

Return type:

Model

optimize() MaxOnesCountProblemIntegerLinearProgrammingSolution

Uses ILP model in order to solve MaxOnesCountProblem

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

String representation of the ‘MaxOnesCountProblemIntegerLinearProgrammingSolver’ 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

class opt.single_objective.comb.max_ones_count_problem.max_ones_count_problem_ilp_linopy.MaxOnesCountProblemIntegerLinearProgrammingSolverConstructionParameters(problem: Problem = None, output_control: OutputControl | None = None)

Bases: object

Instance of the class MaxOnesCountProblemIntegerLinearProgrammingSolverConstructionParameters represents constructor parameters for max ones problem ILP solver.

property output_control: OutputControl

Property getter for the output control

Returns:

output control

Return type:

OutputControl

property problem: Problem

Property getter for the output control

Returns:

problem that is solved

Return type:

Problem

opt.single_objective.comb.max_ones_count_problem.max_ones_count_problem_int_solution module

The ones_count_max_problem_int_solution contains class MaxOnesCountProblemIntSolution, that represents solution of the Ones Count Max Problem, where int representation of the problem has been used.

class opt.single_objective.comb.max_ones_count_problem.max_ones_count_problem_int_solution.MaxOnesCountProblemIntSolution(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[int, str]

argument(representation: int) str

Argument of the target solution for specific problem

Parameters:

representation (int) – internal representation of the solution

Returns:

solution representation as string

Return type:

str

calculate_quality_directly(representation: int, problem: Problem) QualityOfSolution

Fitness calculation of the max ones binary int solution

Parameters:
  • representation (int) – native representation of the solution whose fitness, objective and feasibility is calculated

  • problem (Problem) – problem that is solved

Returns:

objective value, fitness value and feasibility of the solution instance

Return type:

QualityOfSolution

copy()

Copy the MaxOnesCountProblemIntSolution

Returns:

new MaxOnesCountProblemIntSolution instance with the same properties

Return type:

MaxOnesCountProblemIntSolution

init_from(representation: int, problem: Problem) None

Initialization of the solution, by setting its native representation

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

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

init_random(problem: MaxOnesCountProblem) None

Random initialization of the solution

Parameters:

problem (Problem) – problem which is solved by solution

native_representation(representation_str: str) int

Obtain int representation from string representation of the integer binary solution of the Max Ones problem

Parameters:

representation_str (str) – solution’s representation as string

Returns:

solution’s representation as int

Return type:

int

obtain_feasible_representation(problem: Problem) int

Helper function that modifies representation to be feasible

Parameters:

problem (Problem) – problem which is solved by solution

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.max_ones_count_problem.solver module

The opt.single_objective.comb.ones_count_max_problem.solver contains programming code that optimize Max Ones Problem with various optimization techniques.

opt.single_objective.comb.max_ones_count_problem.solver.main()

This function executes solver.

Which solver will be executed depends of command-line parameter algorithm.

Module contents