iwopy.core.memory.Memory

class iwopy.core.memory.Memory[source]

Bases: object

Storage for function results.

Parameters:
  • size (int) – The number of maximally stored results

  • keyf (Function, optional) – The memory key function. Parameters: (vars_int, vars_float), returns key Object

max_size

The number of maximally stored results

Type:

int

data

The stored data. Key: keyf return type, Values: tuples (objs, cons)

Type:

dict

keyf

The memory key function. Parameters: (vars_int, vars_float), returns key Object

Type:

Function

__init__(size, keyf=None)[source]

Methods

__init__(size[, keyf])

clear()

Clears the memory

found_individual(vars_int, vars_float)

Check if entry is found in memory.

found_population(vars_int, vars_float)

Check if entry is found in memory.

lookup_individual(vars_int, vars_float)

Lookup results from memory.

lookup_population(vars_int, vars_float[, target])

Lookup results from memory.

store_individual(vars_int, vars_float, objs, ...)

Store objs and cons data.

store_population(vars_int, vars_float, objs, ...)

Store objs and cons data of a population.

Attributes

size

The number of elements currently stored in memory

__init__(size, keyf=None)[source]
clear()[source]

Clears the memory

found_individual(vars_int, vars_float)[source]

Check if entry is found in memory.

Parameters:
  • vars_int (np.array) – The integer variable values, shape: (n_vars_int,)

  • vars_float (np.array) – The float variable values, shape: (n_vars_float,)

Returns:

found – True if data is available

Return type:

bool

found_population(vars_int, vars_float)[source]

Check if entry is found in memory.

Parameters:
  • vars_int (np.array) – The integer variable values, shape: (n_pop, n_vars_int)

  • vars_float (np.array) – The float variable values, shape: (n_pop, n_vars_float)

Returns:

found – True if data is available, shape: (n_pop,)

Return type:

numpy.ndarray of bool

lookup_individual(vars_int, vars_float)[source]

Lookup results from memory.

Parameters:
  • vars_int (np.array) – The integer variable values, shape: (n_vars_int,)

  • vars_float (np.array) – The float variable values, shape: (n_vars_float,)

Returns:

results – The results (objs, cons) if found, None otherwise

Return type:

tuple or None

lookup_population(vars_int, vars_float, target=None)[source]

Lookup results from memory.

Parameters:
  • vars_int (np.array) – The integer variable values, shape: (n_pop, n_vars_int)

  • vars_float (np.array) – The float variable values, shape: (n_pop, n_vars_float)

  • target (numpy.ndarray, optional) – The results array to write to, shape: (n_pop, n_objs_cmpnts + n_cons_cmpnts)

Returns:

results – None if no results at all found, otherwise array with shape: (n_pop, n_objs_cmpnts + n_cons_cmpnts)

Return type:

numpy.ndarray or None

property size

The number of elements currently stored in memory

Returns:

The number of elements currently stored in memory

Return type:

int

store_individual(vars_int, vars_float, objs, cons)[source]

Store objs and cons data.

Parameters:
  • vars_int (np.array) – The integer variable values, shape: (n_vars_int,)

  • vars_float (np.array) – The float variable values, shape: (n_vars_float,)

  • objs (np.array) – The objective function values, shape: (n_objectives,)

  • con (np.array) – The constraints values, shape: (n_constraints,)

store_population(vars_int, vars_float, objs, cons)[source]

Store objs and cons data of a population.

Parameters:
  • vars_int (np.array) – The integer variable values, shape: (n_pop, n_vars_int)

  • vars_float (np.array) – The float variable values, shape: (n_pop, n_vars_float)

  • objs (np.array) – The objective function values, shape: (n_pop, n_objectives)

  • con (np.array) – The constraints values, shape: (n_pop, n_constraints)