Module Reference

class pyObjective.Variable(name, value, bounds, description=None)
__init__(name, value, bounds, description=None)

Create a variable

Parameters
  • name (str) – name for the variable

  • value (float) – numerical value of the variable. May be used as initial guess or to check model compilation.

  • bounds ((lower float, upper float)) – range of possible values

  • description (str, optional) – longer description of variable, for easy referencing in results.

Returns

object

Return type

Variable

__call__(vec=[], mode=None)

Returns an appropriate form of the variable.

Parameters
  • vec (1D array or list) – vector to substitute into variables

  • mode – type of return on calling the variable.

Returns

If mode is ‘float’ or ‘value’, the variables value is returned (float). If mode is ‘index’, the index of this variable within the vector is returned (int). If mode is ‘obj’, the returned style is such that it can be used by scipy’s optimize features (vec[int])

Return type

object

class pyObjective.Model
__init__()

Initializes the model.

add_var(var)

Adds a variable to the model. Also updates indices and variable lists. :param var: Variable to be added :type var: Variable

solve(solveOptions={})

Solves the model. Uses scipy’s dual_annealing method to efficiently find global optimal. In the future, I will try to make it generic enough to use a solver of your choice.

Parameters

solveOptions (dict) – dictionary of all additional parameters that can be provided to scipy.optimize.dual_annealing()

Returns

result dictionary as returned by Scipy Also stores the solution within the model object (accessible by model.solution and model.solution_vector)

Return type

OptimizeResult

evaluate(vec)

Evaluates the cost for the model for a given vector. :param vec: vector of variable values :type vec: ndarray, list of floats

Returns

cost evaluated for this vector

Return type

float

display_results()

Simple method to display the cost and the variables neatly.