pyJaya package

pyJaya.consts module

Constants module

pyJaya.population module

Population class

class pyJaya.population.Population(minimax, solutions=[])[source]

Bases: object

Population class

Parameters

minimax (int) – Objective function to be (0: minimized or 1: maximized).

divideInTo(n=2)[source]

Divide the population into n subpopulations

Parameters

n (int, optional) – Number of subpopulations. Defaults to 2.

Returns

Subpopulations list.

Return type

list

divideInToWithElitist(n=2)[source]

Divide the population into n subpopulations with elitism

Parameters

n (int, optional) – Number of subpopulations. Defaults to 2.

Returns

Subpopulations list.

Return type

list

generate(numSolutions, listVars, functionToEvaluate, space, listConstraints)[source]

Population generator

Parameters
  • numSolutions (int) – Number of solutions.

  • listVars (list) – Range list.

  • functionToEvaluate (funtion) – Function to minimize or maximize.

  • space (bool) – Spaced numbers over a specified interval.

  • listConstraints (list, optional) – Constraint list. Defaults to [].

getBestAndWorst()[source]

Best and worst value and solution

Returns

Best value, worst value, best solution and worst solution.

Return type

dict

merge(listPopulation)[source]

Merge subpopulations and sort your solutions

Parameters

listPopulation (list) – Population list.

size()[source]

Get population size

Returns

Number of solutions in the population.

Return type

int

sorted()[source]

Sort the solutions

Returns

List sorted solutions.

Return type

list

toMaximize()[source]

Switch to maximize function

pyJaya.solution module

Solution class

class pyJaya.solution.Solution(listVars, functionToEvaluate, listConstraints=[])[source]

Bases: object

Solution class

Parameters
  • listVars (list) – Range list.

  • functionToEvaluate (funtion) – Function to minimize or maximize.

  • listConstraints (list, optional) – Constraint list. Defaults to [].

constraintsOK(solution)[source]

Check that the solution satisfies the constraints

Parameters

solution (Solution) – Solution to check.

Returns

True if it satisfies the constraints, False if not.

Return type

Bool

evaluate()[source]

Evaluate the solution

Returns

Result when evaluating the solution.

Return type

Float

generate()[source]

Generate a solution

setSolution(solution)[source]

Set solution

Parameters

solution (list or np.array) – Solution to be assigned.

pyJaya.variables module

class pyJaya.variables.Variable[source]

Bases: abc.ABC

Variable class

abstract convert()[source]

Client must define it self

abstract get()[source]

Client must define it self

abstract validate()[source]

Client must define it self

class pyJaya.variables.VariableBinary[source]

Bases: pyJaya.variables.Variable

VariableBinary class

convert(item)[source]

Converts an item to a possible value in the range

Parameters

item (int or float) – Value to convert.

Returns

Value in the range.

Return type

int

get()[source]

Returns an integer in the possible range

Returns

Integer in the range.

Return type

int

validate()[source]

Client must define it self

class pyJaya.variables.VariableFloat(outside_first=- 100.0, outside_second=100.0)[source]

Bases: pyJaya.variables.Variable

VariableFloat class

Parameters
  • outside_first (int, optional) – Lowest possible value in the range of the variable. Defaults to -100.0.

  • outside_second (int, optional) – Largest possible value in the range of the variable. Defaults to 100.0.

convert(item)[source]

Converts an item to a possible value in the range

Parameters

item (int or float) – Value to convert.

Returns

Value in the range.

Return type

float

get()[source]

Returns an float in the possible range

Returns

Float in the range.

Return type

float

validate()[source]

Validate that the variables are float

Raises

NotImplementedError – “The numbers should be float”.

class pyJaya.variables.VariableInt(outside_first=- 100, outside_second=100)[source]

Bases: pyJaya.variables.Variable

VariableInt class

Parameters
  • outside_first (int, optional) – Lowest possible value in the range of the variable. Defaults to -100.

  • outside_second (int, optional) – Largest possible value in the range of the variable. Defaults to 100.

convert(item)[source]

Converts an item to a possible value in the range

Parameters

item (int or float) – Value to convert.

Returns

Value in the range.

Return type

int

get()[source]

Returns an integer in the possible range

Returns

Integer in the range.

Return type

int

validate()[source]

Validate that the variables are integers

Raises

NotImplementedError – “The numbers should be integer”.

Module contents

Top-level package for pyJaya.