discrete_optimization.multibatching package

Subpackages

Submodules

discrete_optimization.multibatching.parser module

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

Get datasets available for multibatching.

Parameters:
  • data_folder – folder where datasets for multibatching should be found. If None, we look in “multibatching” subdirectory of data_home.

  • data_home – root directory for all datasets. If None, set by default to “~/discrete_optimization_data”

Returns:

List of absolute paths to JSON files in the data folder.

discrete_optimization.multibatching.parser.parse_file(file_path: str, scale_capacity: float = 1.0, scale_size: float = 1.0, scale_co2: float = 1.0) MultibatchingProblem[source]

Parse a JSON file into a MultibatchingProblem.

Parameters:
  • file_path – Path to the JSON file.

  • scale_capacity – scaling factor for transport capacities (default: 1.0)

  • scale_size – scaling factor for product sizes (default: 1.0)

  • scale_co2 – scaling factor for CO2 emissions (default: 1.0)

Returns:

MultibatchingProblem instance.

discrete_optimization.multibatching.parser.parse_json_to_problem(json_data: dict, scale_capacity: float = 1.0, scale_size: float = 1.0, scale_co2: float = 1.0) MultibatchingProblem[source]

Parse a JSON dictionary into a MultibatchingProblem object.

Parameters:
  • json_data – Dictionary with keys: - “transportResources”: dict mapping transport IDs to transport data - “products”: dict mapping product IDs to product data - “locations”: dict mapping location IDs to location data - “routes”: dict mapping route IDs to route data - “settings”: dict with problem settings

  • scale_capacity – scaling factor for transport capacities (default: 1.0)

  • scale_size – scaling factor for product sizes (default: 1.0)

  • scale_co2 – scaling factor for CO2 emissions (default: 1.0)

Returns:

MultibatchingProblem instance.

discrete_optimization.multibatching.problem module

class discrete_optimization.multibatching.problem.Location(id: Hashable, name: str = '', net_supply: dict[discrete_optimization.multibatching.problem.Product, int]=<factory>)[source]

Bases: object

id: Hashable
name: str = ''
net_supply: dict[Product, int]
class discrete_optimization.multibatching.problem.MultibatchingProblem(transport_types: list[TransportType], products: list[Product], locations: list[Location], transport_links: list[TransportLink])[source]

Bases: Problem

check_feasibility_per_product(verbose=False) bool[source]

TODO : no need of max_flow in the current code (we put a big capacity) Checks if a feasible flow exists for each product independently. For each product, this method builds a flow network and solves a maximum flow problem to determine if the total supply can meet the total demand through the available transport links. :param verbose: If True, prints messages for each product’s

feasibility check.

Returns:

True if all products have a feasible flow, False otherwise.

Return type:

bool

check_flows(solution: MultibatchingSolution)[source]
evaluate(variable: MultibatchingSolution) dict[str, float][source]

Evaluate a given solution object for the given problem.

This method should return a dictionnary of KPI, that can be then used for mono or multiobjective optimization.

Parameters:

variable (Solution) – the Solution object to evaluate.

Returns: dictionnary of float kpi for the solution.

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_consumer_location(product: Product)[source]

Returns the location where a given product is consumed (i.e net-supply<0)

get_max_nb_trips(solution: MultibatchingSolution) int[source]

Look for the most number of individual trip on a given solution

get_objective_register() ObjectiveRegister[source]

Returns the objective definition.

Returns (ObjectiveRegister): object defining the objective criteria.

get_outgoing_tl_from_location(location: Location)[source]

Returns all transport link that goes out of a given location

get_solution_type() type[Solution][source]

Returns the class implementation of a Solution.

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

get_supplier_location(product: Product)[source]

Returns the location where a given product is done (i.e net-supply>0)

get_total_demand(product: Product)[source]
get_total_supply(product: Product)[source]

Robust Heuristic: Identifies which transport links are relevant for each product.

It builds a specific graph G_p for each product P, containing only the TransportLinks compatible with P (i.e. link.transport_type in p.valid_transports).

A link (u, v) is relevant for product P if there exists ANY pair of (Source s, Sink d) for P such that:

dist_p(s, u) + link_len(u, v) + dist_p(v, d) <= (1 + tolerance) * dist_p(s, d)

satisfy(variable: MultibatchingSolution) bool[source]

Checks if a given MultibatchingSolution is feasible.

Feasibility conditions checked: 1. Flow Conservation: For each location and product, the total incoming flow

plus local supply must equal total outgoing flow plus local demand.

  1. Packing Capacity: For each PackingTransport, the total size of products packed must not exceed the capacity of its associated TransportType.

  2. Product-Transport Compatibility: Each product in a PackingTransport must be valid for the TransportType of its TransportLink.

  3. Non-negative Frequencies: nb_packing must be non-negative.

  4. Non-negative Packed Units: Units in product_packing must be non-negative.

  5. Integer Packing Units: Units in product_packing must be integers (as per problem definition).

  6. Positive Frequency for Non-empty Packing: If nb_packing is > 0, then product_packing cannot be empty. (This is usually implicitly handled by solver, but explicit check for robustness).

class discrete_optimization.multibatching.problem.MultibatchingSolution(problem: MultibatchingProblem, list_flows: list[PackingTransport])[source]

Bases: Solution

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() Solution[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.

class discrete_optimization.multibatching.problem.PackingTransport(transport_link: TransportLink, product_packing: dict[Product, int], nb_packing: int)[source]

Bases: object

Represent a packing going through a transport link, containing a set of product. nb_packing is optional, it can represent a frequency of the same packing going through the edge.

nb_packing: int
product_packing: dict[Product, int]
class discrete_optimization.multibatching.problem.Product(id: int, name: str = '', size: int = 0, value: int = 0, valid_transports: frozenset[discrete_optimization.multibatching.problem.TransportType] = <factory>)[source]

Bases: object

id: int
name: str = ''
size: int = 0
valid_transports: frozenset[TransportType]
value: int = 0

Bases: object

Represent an edge (location1, location2, transport_type) in the logistic graph

distance: int
id: str
location_l1: Location
location_l2: Location
max_trips: int | None = None
transport_type: TransportType
class discrete_optimization.multibatching.problem.TransportType(id: int, cost: int, speed: int, emissions: int, capacity: int, name: str = None)[source]

Bases: object

capacity: int
cost: int
emissions: int
id: int
name: str = None
speed: int
discrete_optimization.multibatching.problem.analyse_solution(base_solution: MultibatchingSolution, new_solution: MultibatchingSolution)[source]

Compare 2 solutions, link per link, only looking at the number of trips

discrete_optimization.multibatching.problem.compute_graph_for_product(problem: MultibatchingProblem, product: Product) DiGraph[source]

discrete_optimization.multibatching.utils module

discrete_optimization.multibatching.utils.generate_multibatching_problem(num_locations: int = 6, num_transport_types: int = 2, num_products: int = 2, min_dist: int = 1, max_dist: int = 10, min_capacity: int = 10, max_capacity: int = 20, min_product_size: int = 1, max_product_size: int = 5, min_product_value: int = 100, max_product_value: int = 1000, min_tt_cost: int = 10, max_tt_cost: int = 100, min_tt_speed: float = 0.1, max_tt_speed: float = 1.0, min_tt_emissions: int = 10, max_tt_emissions: int = 100, max_links_per_pair: int = 2, demand_sparsity: float = 0.5, max_demand_abs: int = 50, seed: int = None) MultibatchingProblem[source]

Generate a random MultibatchingProblem instance.

Creates a multibatching logistics problem with random transport networks, products, locations, and supply/demand. The problem models the optimization of product transport across multiple locations using different transport types (e.g., trucks, trains), considering costs, emissions, and capacity constraints.

The generator ensures: - Supply/demand balance: Total supply equals total demand for each product - Product-transport compatibility: Each product can only use valid transport types - Network connectivity: Transport links connect locations based on available transport types

Parameters:
  • num_locations – Number of distinct locations in the network.

  • num_transport_types – Number of distinct transport resource types (e.g., truck, train).

  • num_products – Number of distinct products to transport.

  • min_dist – Minimum distance for transport links.

  • max_dist – Maximum distance for transport links.

  • min_capacity – Minimum capacity for transport types.

  • max_capacity – Maximum capacity for transport types.

  • min_product_size – Minimum size/volume for products.

  • max_product_size – Maximum size/volume for products.

  • min_product_value – Minimum value for products.

  • max_product_value – Maximum value for products.

  • min_tt_cost – Minimum cost per unit distance for transport types.

  • max_tt_cost – Maximum cost per unit distance for transport types.

  • min_tt_speed – Minimum speed for transport types.

  • max_tt_speed – Maximum speed for transport types.

  • min_tt_emissions – Minimum emissions per unit distance for transport types.

  • max_tt_emissions – Maximum emissions per unit distance for transport types.

  • max_links_per_pair – Maximum number of transport links (with different transport types) between any pair of locations. Setting this to 1 creates a simple network where each location pair has at most one transport option.

  • demand_sparsity – Proportion of (location, product) pairs that will have non-zero supply/demand (0.0 = no demand anywhere, 1.0 = all pairs have demand).

  • max_demand_abs – Maximum absolute value for supply (+) or demand (-) at any location for any product.

  • seed – Random seed for reproducibility. If None, uses system time.

Returns:

A randomly generated MultibatchingProblem instance with balanced supply/demand.

Module contents