Optimization Problem Types¶
Classes for defining optimization problem objects.

class
DiscreteOpt
(length, fitness_fn, maximize=True, max_val=2)[source]¶ Class for defining discretestate optimization problems.
Parameters:  length (int) – Number of elements in state vector.
 fitness_fn (fitness function object) – Object to implement fitness function for optimization.
 maximize (bool, default: True) – Whether to maximize the fitness function.
Set
False
for minimization problem.  max_val (int, default: 2) – Number of unique values that each element in the state vector can take. Assumes values are integers in the range 0 to (max_val  1), inclusive.

class
ContinuousOpt
(length, fitness_fn, maximize=True, min_val=0, max_val=1, step=0.1)[source]¶ Class for defining continuousstate optimisation problems.
Parameters:  length (int) – Number of elements in state vector.
 fitness_fn (fitness function object) – Object to implement fitness function for optimization.
 maximize (bool, default: True) – Whether to maximize the fitness function.
Set
False
for minimization problem.  min_val (float, default: 0) – Minimum value that each element of the state vector can take.
 max_val (float, default: 1) – Maximum value that each element of the state vector can take.
 step (float, default: 0.1) – Step size used in determining neighbors of current state.

class
TSPOpt
(length, fitness_fn=None, maximize=False, coords=None, distances=None)[source]¶ Class for defining travelling salesperson optimisation problems.
Parameters:  length (int) – Number of elements in state vector. Must equal number of nodes in the tour.
 fitness_fn (fitness function object, default: None) – Object to implement fitness function for optimization. If
None
, thenTravellingSales(coords=coords, distances=distances)
is used by default.  maximize (bool, default: False) – Whether to maximize the fitness function.
Set
False
for minimization problem.  coords (list of pairs, default: None) – Ordered list of the (x, y) coordinates of all nodes. This assumes
that travel between all pairs of nodes is possible. If this is not the
case, then use distances instead. This argument is ignored if
fitness_fn is not
None
.  distances (list of triples, default: None) – List giving the distances, d, between all pairs of nodes, u and v, for
which travel is possible, with each list item in the form (u, v, d).
Order of the nodes does not matter, so (u, v, d) and (v, u, d) are
considered to be the same. If a pair is missing from the list, it is
assumed that travel between the two nodes is not possible. This
argument is ignored if fitness_fn or coords is not
None
.