problem_instance#

class DeviceType(value)[source]#

Bases: Enum

The devices that can be used by pytorch

CPU_DEVICE = 'cpu'#
CUDA_DEVICE = 'cuda'#
class InstanceType(value)[source]#

Bases: Enum

Enumerate instance types.

TEST = 'test'#
TUNING = 'tuning'#
class ProblemInstance(device='cpu', instance_type='tuning', file_path=None, file_delimiter='\t', name=None, solution_bounds=(0.0, 1.0))[source]#

Bases: object

Defines a BoxQP problem instance.

Problem instance constructor.

Parameters:
  • device (str, optional) – Defines which GPU (or the CPU) to use. Defaults to “cpu”.

  • instance_type (str, optional) – The type of the instance. Defaults to “tuning”.

  • file_path (str, optional) – Path to file of problem instance. Defaults to None.

  • file_delimiter (str, optional) – The type of delimiter used in the file. Defaults to “ “.

  • name (str, optional) – The name of the problem instance. If not given, defaults to the file name when an instance is loaded.

  • solution_bounds (tuple(float), optional) – The minimum and maximum value allowed (inclusively) in the solution vector. The first value is the minimum, the second is the maximum. Defaults to (0.0,1.0).

problem_size#

instance size. Defaults to None.

Type:

int

optimal_sol#

the optimal solution via Gurobi to the problem. Defaults to None.

Type:

float

best_sol#

the best solution via BFGS. Defaults to None

Type:

float

optimality#

indicates whether the solution is optimal (True or False). Defaults to None.

Type:

bool

sol_time_gb#

the time for Gurobi to solve it

Type:

float

sol_time_bfgs#

the time for BFGS to solve it

Type:

float

num_frac_values#

number of fractional values in the solution

Type:

int

q_matrix#

Q matrix of the QP problem. Defaults to None.

Type:

torch.tensor

v_vector#

V vector of the QP problem. Defaults to None.

Type:

torch.tensor

solution_vector#

the vector of solution to the problem instance found using Gurobi

Type:

list

scaled_by#

scaling value of the coefficient. Defaults to 1.

Type:

float

compute_energy(confs)[source]#

Compute the objective value for the given BoxQP instance using the formula ‘0.5 xQx + Vx’, where ‘x’ is the vector of variables.

Parameters:

confs (torch.Tensor) – Configurations for which to compute energy

Returns:

Energy of configurations.

Return type:

torch.Tensor

load_instance(device='cpu', instance_type='tuning', file_path=None, file_delimiter=None)[source]#

Loads in a box constraint problem from a file.

Parameters:
  • device (str, optional) – Device to use. Defaults to “cpu”.

  • instance_type (str, optional) – The type of the instance. Defaults to “tuning”.

  • file_path (str, optional) – Path to instance file. Defaults to None.

  • file_delimiter (str, optional) – Delimiter used in the instance file. If not specified, the file_delimiter value assigned at instance initialization will be used.

Raises:
  • Exception – File path is not specified.

  • Exception – Error reading the instance file.

scale_coefs(scaling_factor)[source]#

Divides the coefficients of the problem stored in this instance by the given factor. Note that consecutive calls to this function will stack, e.g. scaling the problem by 4 twice would have the same result as scaling the original problem by 16.

Parameters:
  • scaling_factor (torch.Tensor) – The amount by which the

  • scaled. (coefficients should be) –

property solution_bounds#

The minimum and maximum value allowed (inclusively) in the solution vector. The first value is the minimum, the second is the maximum.

Returns:

The minimum and maximum solution bounds.

Return type:

tuple(float)