solution#

class Solution(problem_size: int, batch_size: int, instance_name: str, iterations: int, objective_values: Tensor, solve_time: float, pp_time: float, optimal_value: float, best_value: float, num_frac_values: int, solution_vector: list, variables: dict, evolution_file: str | None = None, device: str = 'cpu', solution_performance: dict | None = None, best_objective_value: float | None = None)[source]#

Bases: object

Define the solution class of a solve.

Parameters:
  • problem_size (int) – The size of the problem solved.

  • batch_size (int) – The number of times the problem instance was solved simultaneously.

  • instance_name (str) – The name of the problem instance.

  • objective_values (torch.Tensor) – The objective values of the solutions found by the solver.

  • iterations (int) – The iteration number for this problem size.

  • solve_time (float) – The effective time to solve the problem instance only once.

  • pp_time (float) – Time to post-process the problem.

  • optimal_value (float) – The optimal objective value for the given problem instance.

  • best_value (float) – The best objective value for the given problem instance.

  • num_frac_values (int) – Number of fractional values in the solutions of given problem instance.

  • solution_vector (list) – Vector of solution to the problem instance found using Gurobi.

  • variables (dict) –

    A dict object to store solution related variables. Some fields might be solver-dependent, such as mu, sigma and s. - problem_variables (torch.Tensor): The values of the problem

    variables found by the solver.

  • evolution_file (str, optional) – The filename of the evolution file, if it exists.

  • device (str, optional) – Device to use, one of: “cpu” or “cuda”. Defaults to “cpu”.

solution_performance#

A dictionary contains the following fields - optimal (float): The fraction of the solutions that were within the 0.1% of optimal value. - one_percent (float): The fraction of the solutions that were within the 1% of optimal value. - two_percent (float): The fraction of the solutions that were within the 2% of optimal value. - three_percent (float): The fraction of the solutions that were within the 3% of optimal value. - four_percent (float): The fraction of the solutions that were within the 4% of optimal value. - five_percent (float): The fraction of the solutions that were within the 5% of optimal value. - ten_percent (float): The fraction of the solutions that were within the 10% of optimal value. Defaults to None.

Type:

dict

best_objective_value#

The best objective value found by the solver.

Type:

float

batch_size: int#
best_objective_value: float = None#
best_value: float#
device: str = 'cpu'#
evolution_file: str = None#
get_metadata_dict() dict[source]#

Return the metadata dictonary. Excluding the tensor fields in solution by filtering out the fields where repr sets to False.

Returns:

metadata of the solution.

Return type:

dict

get_solution_stats()[source]#

A method that calculates the fraction of solutions that were optimal, within 1%, 2%, 3%, 4%, 5% and 10% of optimal value and update the solution.

instance_name: str#
iterations: int#
num_frac_values: int#
objective_values: Tensor#
optimal_value: float#
pp_time: float#
problem_size: int#
save_tensor_to_file(tensor_name, file_dir='.', file_name=None)[source]#

Save the tensor that exists in the solution variables dictionary to a file.

Parameters:
  • tensor_name (str) – The name (key) that identifies the tensor in the solution.variable dictionary.

  • file_dir (str) – The directory of the file. Default to current directory.

  • file_name (str) – The name of the file storing tensor. If not provided, defaults to the same name as tensor_name.

Raises:
  • Exception – Failed to create the folder path.

  • Exception – Tensor_name not exists in Solution.

  • Exception – A tensor object cannot be obtained by tensor_name.

solution_performance: dict = None#
solution_vector: list#
solve_time: float#
variables: dict#