discrete_optimization.facility package

Subpackages

Submodules

discrete_optimization.facility.parser module

discrete_optimization.facility.parser.get_data_available(data_folder: str | None = None, data_home: str | None = None) list[str][source]

Get datasets available for facility.

Params:
data_folder: folder where datasets for facility whould be find.

If None, we look in “facility” subdirectory of data_home.

data_home: root directory for all datasets. Is None, set by

default to “~/discrete_optimization_data “

discrete_optimization.facility.parser.parse(input_data: str) Facility2DProblem[source]
discrete_optimization.facility.parser.parse_file(file_path: str) Facility2DProblem[source]

discrete_optimization.facility.problem module

Implementation of the facility location problem with capacity constraint (https://en.wikipedia.org/wiki/Facility_location_problem#Capacitated_facility_location)

Facility location problem consist in choosing where to locate facilities and allocate customers to those. Each customers have a demand and facility have a capacity. The sum of demand of customers allocated to a given location can’t exceed the capacity of the facility.

class discrete_optimization.facility.problem.Customer(index: 'int', demand: 'float', location: 'Point')[source]

Bases: object

demand: float
index: int
location: Point
class discrete_optimization.facility.problem.Facility(index: 'int', setup_cost: 'float', capacity: 'float', location: 'Point')[source]

Bases: object

capacity: float
index: int
location: Point
setup_cost: float
class discrete_optimization.facility.problem.Facility2DProblem(facility_count: int, customer_count: int, facilities: list[Facility], customers: list[Customer])[source]

Bases: FacilityProblem

evaluate_customer_facility(facility: Facility, customer: Customer) float[source]

Implementation of a distance based cost for allocation of facility to customers.

It uses the euclidian distance as cost.

Parameters:

Returns: a float cost

class discrete_optimization.facility.problem.FacilityProblem(facility_count: int, customer_count: int, facilities: list[Facility], customers: list[Customer])[source]

Bases: AllocationProblem[Customer, Facility]

Base class for the facility problem.

facility_count

number of facilities

Type:

int

customer_count

number of customers

Type:

int

facilities

list of facilities object, facility has a setup cost, capacity and location

Type:

list[Facility]

customers

list of customers object, which has demand and location.

Type:

list[Customer]

evaluate(variable: FacilitySolution) dict[str, float][source]

Computes the KPI of a FacilitySolution.

Parameters:

variable (FacilitySolution) – solution to evaluate

Returns: dictionnary of kpi, see get_objective_register() for details of kpi.

evaluate_cost(variable: FacilitySolution) dict[str, Any][source]

Compute the allocation cost of the solution along with setup cost too.

Parameters:

variable (FacilitySolution) – facility solution to evaluate.

Returns: a dictionnary containing the cost of allocation (“cost”), setup cost (“setup_cost”), and details by facilities (“details”)

abstractmethod evaluate_customer_facility(facility: Facility, customer: Customer) float[source]

Compute the cost of allocating a customer to a facility. This function is not implemented by default.

Parameters:

Returns (float): a cost as a float

get_attribute_register() EncodingRegister[source]

Returns how the Solution should be encoded.

Useful to find automatically available mutations for local search. Used by genetic algorithms Ga and Nsga.

This needs only to be implemented in child classes when GA or LS solvers are to be used.

Returns (EncodingRegister): content of the encoding of the solution

get_dummy_solution() FacilitySolution[source]

Returns Dummy solution (that is not necessary fulfilling the constraints)

All customers are allocated to the first facility (which usually will break the capacity constraint) Returns (FacilitySolution): a dummy solution

get_objective_register() ObjectiveRegister[source]

Returns the objective definition.

Returns (ObjectiveRegister): object defining the objective criteria.

get_solution_type() type[Solution][source]

Returns the class implementation of a Solution.

Returns (class): class object of the given Problem.

satisfy(variable: FacilitySolution) bool[source]

Satisfaction function of a facility solution.

We only check that the capacity constraint is fulfilled. We admit that the values of the vector are in the allowed range.

Parameters:

variable (FacilitySolution) – facility solution to check satisfaction

Returns (bool): true if solution satisfies constraint.

property tasks_list: list[Customer]

List of all tasks to schedule or allocate to.

property unary_resources_list: list[Facility]

Available unary resources.

It can correspond to employees (rcpsp-multiskill), teams (workforce-scheduling), or a mix of several types.

class discrete_optimization.facility.problem.FacilitySolution(problem: FacilityProblem, facility_for_customers: list[int], dict_details: dict[str, Any] | None = None)[source]

Bases: AllocationSolution[Customer, Facility]

Solution object for facility location

problem

facility problem instance

Type:

FacilityProblem

facility_for_customers

for each customers, specify the index of the facility

Type:

list[int]

dict_details

giving more metrics of the solution such as the capacities used, the setup cost etc.

Type:

dict

See problem.evaluate
Type:

sol

change_problem(new_problem: Problem) None[source]

If relevant to the optimisation problem, change the underlying problem instance for the solution.

This method can be used to evaluate a solution for different instance of problems. It should be implemented in child classes when caching subresults depending on the problem.

Parameters:

new_problem (Problem) – another problem instance from which the solution can be evaluated

Returns: None

copy() FacilitySolution[source]

Deep copy of the solution.

The copy() function should return a new object containing the same input as the current object, that respects the following expected behaviour: -y = x.copy() -if do some inplace change of y, the changes are not done in x.

Returns: a new object from which you can manipulate attributes without changing the original object.

is_allocated(task: Customer, unary_resource: Facility) bool[source]

Return the usage of the unary resource for the given task.

Parameters:
  • task

  • unary_resource

Returns:

lazy_copy() FacilitySolution[source]

This function should return a new object but possibly with mutable attributes from the original objects.

A typical use of lazy copy is in evolutionary algorithms or genetic algorithm where the use of local move don’t need to do a possibly costly deepcopy.

Returns (Solution): copy (possibly shallow) of the Solution

problem: FacilityProblem
class discrete_optimization.facility.problem.Point(x: 'float', y: 'float')[source]

Bases: object

x: float
y: float
discrete_optimization.facility.problem.length(point1: Point, point2: Point) float[source]

Classic euclidian distance between two points.

Parameters:
  • point1 (Point) – origin point

  • point2 (Point) – target point

Returns (float): euclidian distance between the 2 points

discrete_optimization.facility.solvers_map module

discrete_optimization.facility.solvers_map.look_for_solver(domain: FacilityProblem) list[type[FacilitySolver]][source]
discrete_optimization.facility.solvers_map.look_for_solver_class(class_domain: type[FacilityProblem]) list[type[FacilitySolver]][source]
discrete_optimization.facility.solvers_map.return_solver(method: type[FacilitySolver], problem: FacilityProblem, **kwargs: Any) FacilitySolver[source]
discrete_optimization.facility.solvers_map.solve(method: type[FacilitySolver], problem: FacilityProblem, **kwargs: Any) ResultStorage[source]

discrete_optimization.facility.utils module

discrete_optimization.facility.utils.compute_matrix_distance_facility_problem(problem: FacilityProblem)[source]

Module contents