Packing Problem Module

This module encapsulates and formalizes all aspects and rules of the Online Packing Problem.

For each instant, the algorithm receives k options of items, each one with a value and a cost-vector. The algorithm chooses which option to pack, and then waits until receiving the options for the next instant. The algorithm can also choose to pack no items at a given instant. Also, it may not pack any item that that causes a violation of the capacity constraint in some dimension.

class packing_problem.PackingProblem(capacity: Union[float, int], cost_dimension: int)[source]

Class that enforces all aspects of the online packing problem.

This class is statefull, meaning it carries the current state of the game, and some methods depend on that state.

Parameters
capacityfloat or int

The capacity for the problem (same in every dimension).

cost_dimensionint

The dimension of the cost vector.

Methods

set_current_inputs(values, costs)

Set items’ values and costs for the current instant.

item_fits(idx)

Checks if current instant’s item of index idx fits in capacity constraints.

pack(idx)

Pack current instant’s item of index idx.

end_packing()

Ends the packing phase.

get_capacity()

Get capacity of the problem instance.

get_options_per_instant()

Get the number of available items in each instant.

get_available_values()

Get the value of the items that are available for the current instant.

get_available_costs()

Get the cost of the items that are available for the current instant.

get_cost_dimension()

Get the dimension of the cost vectors.

get_available_costs()List[List[List[Union[int, float]]]][source]

Get costs of all the available items for past and current instants.

Returns
list of list of list of (int or float)

List contianing, for each instant, a list with the cost vectors of the available items for that instant.

get_available_values()List[List[Union[int, float]]][source]

Get values of all the available items for past and current instants.

Returns
list of list of (int or float)

List contianing, for each instant, a list with the values of the available items for that instant.

get_capacity()Union[int, float][source]

Get the problem capacity.

Returns
int or float

Previously set problem capacity.

get_cost_dimension()[source]

Get the dimension of the cost vectors.

Returns
int

The dimension of the cost vectors.

get_options_per_instant()int[source]

Get the number of available items per instant.

Returns
int

Number of available items per instant.

item_fits(idx: int)bool[source]

Checks that currently available item of index idx fits the capacity constriants.

Parameters
idxint

Index of the item to be verified.

Returns
bool

True if the item fits the constraints, False otherwise.

pack(idx: int)Union[int, float][source]

Pack item of index idx, from the currently available.

Parameters
idxint

Index of the item to pack.

Returns
int or float

Total value of the packed items so far.

Raises
Exception

An item was already packed for the current instant.

Exception

Index for the item out of bounds.

Exception

Chosen item exceed capacity in some dimension.