discrete_optimization.facility package

Subpackages

Submodules

discrete_optimization.facility.facility_model 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.facility_model.Customer(index: int, demand: float, location: discrete_optimization.facility.facility_model.Point)[source]

Bases: object

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

Bases: object

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

Bases: Problem

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”)

abstract 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

evaluate_from_encoding(int_vector: List[int], encoding_name: str) Dict[str, float][source]

Evaluate function based on direct integer vector (used in GA algorithms only)

Parameters:
  • int_vector (List[int]) – vector encoding the solution

  • encoding_name (str) – name of encoding (see get_attribute_register) for available encoding

Returns: kpi of the solution

get_attribute_register() EncodingRegister[source]

Returns how the Solution should be encoded.

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.

class discrete_optimization.facility.facility_model.FacilityProblem2DPoints(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.facility_model.FacilitySolution(problem: Problem, facility_for_customers: List[int], dict_details: Dict[str, Any] | None = None)[source]

Bases: Solution

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.

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.

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

class discrete_optimization.facility.facility_model.Point(x: float, y: float)[source]

Bases: object

x: float
y: float
discrete_optimization.facility.facility_model.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.facility_parser module

discrete_optimization.facility.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.facility_parser.parse(input_data: str) FacilityProblem2DPoints[source]
discrete_optimization.facility.facility_parser.parse_file(file_path: str) FacilityProblem2DPoints[source]

discrete_optimization.facility.facility_solvers module

discrete_optimization.facility.facility_solvers.look_for_solver(domain: FacilityProblem) List[Type[SolverFacility]][source]
discrete_optimization.facility.facility_solvers.look_for_solver_class(class_domain: Type[FacilityProblem]) List[Type[SolverFacility]][source]
discrete_optimization.facility.facility_solvers.return_solver(method: Type[SolverFacility], problem: FacilityProblem, **kwargs: Any) SolverFacility[source]
discrete_optimization.facility.facility_solvers.solve(method: Type[SolverFacility], problem: FacilityProblem, **kwargs: Any) ResultStorage[source]

Module contents