kep_solver.pool module

Handling of KEP pools, which are just the rules, procedures and algorithms for a particular KEP.

class ModelledExchange(exchange, values)

Bases: object

An exchange as modelled, including its value for various objectives and any other relevant information.

__init__(exchange, values)

Constructor for ModelledExchange. Contains the Exchange object, and also the value of this exchange for the various objectives in this model.

Parameters:
  • exchange (Exchange) – The exchange

  • values (list[float]) – The value of this exchange for each objective

property exchange: Exchange

The underlying exchange.

property values: list[float]

The values of this exchange.

class Solution(exchanges, scores, possible, times)

Bases: object

A solution to one instance of a KEP. Contains the exchanges, and the set of objective values attained.

__init__(exchanges, scores, possible, times)

Constructor for Solution. This class essentially just stores any information that may be useful.

Parameters:
  • exchanges (list[ModelledExchange]) – the list of selected exchanges

  • scores (list[float]) – the list of scores achieved for each objective

  • possible (list[ModelledExchange]) – the set of possible exchanges, and their values for each objective

  • times (list[tuple[str, float]]) – The time taken for various operations. Each is a tuple with a string description of the action, and the time (in seconds)

property times: list[tuple[str, float]]

Get the time taken for various operations. Each element of the returned list is a tuple where the first item is a string description of some operation, and the second item is the time taken in seconds.

Returns:

the list of times (and their descriptions)

property selected: list[kep_solver.pool.ModelledExchange]

Get the selected solution.

Returns:

the list of exchanges selected.

property values: list[float]

Get the Objective values of the selected solution.

Returns:

the list of objective values

property possible: list[kep_solver.pool.ModelledExchange]

Return a list of all the possible chains and cycles that may be selected as ModelledExchange objects that contain the value of said exchange for each objective.

Returns:

a list of cycles/chains as ModelledExchange objects

class Pool(objectives, maxCycleLength, maxChainLength, description)

Bases: object

A KEP pool.

__init__(objectives, maxCycleLength, maxChainLength, description)

Constructor for Pool. This represents a set of objectives, and parameters for running matchings (such as maximum cycle and chain lengths).

Parameters:
  • objectives (list[Objective]) – the list of objectives

  • maxCycleLength (int) – The longest cycle length allowed.

  • maxChainLength (int) – The longest chain length allowed. Note that the length of a chain includes the non-directed donor.

  • description (str) – A description of this pool.

property description: str

A description of this pool.

property objectives: list[kep_solver.model.Objective]

The list of objectives for this Pool.

property maxCycleLength: int

The maximum length of cycles in this pool.

property maxChainLength: int

The maximum length of chains in this pool. Note that this includes the non-directed donor, so a chain of length 1 only has a non-directed donor and no recipients.

solve_single(instance, maxCycleLength=None, maxChainLength=None)

Run a single instance through this pool, returning the solution, or None if no solution is found (e.g., if the solver crashes).

Parameters:
  • instance (Instance) – The instance to solve

  • maxCycleLength (Optional[int]) – The longest cycle allowed. If not specified, we use the default from the Pool

  • maxChainLength (Optional[int]) – The longest chain allowed. If not specified, we use the default from the Pool

Return type:

tuple[Optional[Solution], Model]

Returns:

A tuple containing a Solution object, or None if an error occured, as well as the model that was solved.