Optimisation

Submodules

Platypus (pywr.optimisation.platypus)

class pywr.optimisation.platypus.PlatypusWrapper(*args, **kwargs)

Bases: pywr.optimisation.BaseOptimisationWrapper

A helper class for running pywr optimisations with platypus.

evaluate(solution)
class pywr.optimisation.platypus.PywrRandomGenerator(*args, **kwargs)

Bases: platypus.operators.RandomGenerator

A Platypus Generator that injects current and/or alternative setups of the Pywr model into the population.

When use_current is true the first Solution returned from the generate method is taken from the wrapper (i.e. the Pywr model being wrapped) as the current values of the variable Parameters. This allows the population to be seeded with the current model configuration, which is often an initial solution. Additional solutions can be provided in as an iterable of solutions. These can come from an alternative source such as previous optimisation.

Parameters
wrapperPlatypusWrapper

Wrapper from which to grab the current model and decision variables.

use_current: Bool

Whether to generate an initial solution using the model’s current configuration. Default is true. Set this to False and pass some solutions to use pre-generated

solutionsList of dicts

An iterable of initial solutions to use (default is None). If given these alternative solutions are provided to Platypus in order. Each item in the list should be a dictionary containing keys for each of the variable Parameters in the optimisation. The value of each key should be another dictionary container keys “doubles” and/or “integers” to provide the appropriate values as dictated by the Parameter’s type.

generate(problem)
pywr.optimisation.platypus.count_constraints(constraints)

Count the number of constraints.

Recorders that are doubled bounded will create two constraints in the platypus problem.

Pygmo (pywr.optimisation.pygmo)

class pywr.optimisation.pygmo.PygmoWrapper(pywr_model_json, *args, **kwargs)

Bases: pywr.optimisation.BaseOptimisationWrapper

fitness(solution)
get_bounds()

Return the variable bounds.

get_nec()
get_nic()
get_nobj()

Module contents

class pywr.optimisation.BaseOptimisationWrapper(pywr_model_json, *args, **kwargs)

Bases: object

A helper class for running pywr optimisations with platypus.

customise_model(model)
make_model()
property model
property model_constraints
property model_objectives
property model_variable_map
property model_variables
class pywr.optimisation.ModelCache

Bases: object

pywr.optimisation.cache_constraints(model)
pywr.optimisation.cache_objectives(model)
pywr.optimisation.cache_variable_parameters(model)
pywr.optimisation.clear_global_model_cache()

Clear the module level model cache.