OpenGoddard package

Submodules

OpenGoddard.optimize module

OpenGoddard.optimize - Optimal Trajectories module with PseudoSpectral Method

class OpenGoddard.optimize.Condition(length=0)

Bases: object

OpenGoddard.optimize Condition class

thin wrappper of numpy zeros and hstack

Examples

for examples in equality function.

Initial condtion : x[0] = 0.0

Termination Condition : x[-1] = 100

>>> result = Condition()
>>> result.equal(x[0], 0.0)
>>> result.equal(x[-1], 100)
>>> return result()

for examples in inequality function

Inequation condtion : 0.0 <= x <= 100

>>> result = Condition()
>>> result.lower_bound(x, 0.0)
>>> result.upper_bound(x, 100)
>>> return result()
add(arg, unit=1.0)

add condition

Parameters:arg (array_like) – condition
change_value(index, value)
equal(arg1, arg2, unit=1.0)

add equation constraint condition in Problem equality function

arg1 = arg2

Parameters:
  • arg1 (float or array_like) – right side of the equation
  • arg2 (float or array_like) – left side of the equation
  • unit (float, optional) – argX / unit (default : 1.0)

Notes

It must be used in equality function.

lower_bound(arg1, arg2, unit=1.0)

add inequation constraint condition in Problem inequality function

arg1 >= arg2

Parameters:
  • arg1 (array like) – arg1 is greater than or equal to arg2
  • arg2 (float or array like) – arg1 is greater than or equal to arg2
  • unit (float, optional) – argX / unit (default : 1.0)

Notes

It must be used in inequality function.

upper_bound(arg1, arg2, unit=1.0)

add inequation constraint condition in Problem inequality function

arg1 <= arg2

Parameters:
  • arg1 (array like) – arg1 is less than or equal to arg2
  • arg2 (float or array like) – arg1 is less than or equal to arg2
  • unit (float, optional) – argX / unit (default : 1.0)

Notes

It must be used in inequality function.

class OpenGoddard.optimize.Dynamics(prob, section=0)

Bases: object

OpenGoddard.optimize Condition class.

thin wrapper for dynamics function. Behave like a dictionary type.

Examples

Dynamics class must be used in dynamics function. It is an example of the equation of motion of thrust and free fall. Thrust is controllable.

\[ \begin{align}\begin{aligned}\dot{x} &= v\\\dot{v} &= T/m - g\end{aligned}\end{align} \]
>>> def dynamics(prob, obj, section):
>>>     x = prob.states(0, section)
>>>     v = prob.states(1, section)
>>>     T = prob.controls(0, section)
>>>     g = 9.8
>>>     m = 1.0
>>>     dx = Dynamics(prob, section)
>>>     dx[0] = v
>>>     dx[1] = T / m - g
>>>     return dx()
class OpenGoddard.optimize.Guess

Bases: object

Class for initial value guess for optimization.

Collection of class methods

classmethod constant(time, const)

return constant values that array size is same as time length

Parameters:
  • time (array_like) –
  • const (float) – set value
Returns:

(N, ) ndarray

classmethod cubic(time, y0, yprime0, yf, yprimef)

return cubic function values that array size is same as time length

Parameters:
  • time (array_like) – time
  • y0 (float) – initial value
  • yprime0 (float) – slope of initial value
  • yf (float) – final value
  • yprimef (float) – slope of final value
Returns:

(N, ) ndarray

classmethod linear(time, y0, yf)

return linear function values that array size is same as time length

Parameters:
  • time (array_like) – time
  • y0 (float) – initial value
  • yf (float) – final value
Returns:

(N, ) ndarray

classmethod plot(x, y, title='', xlabel='', ylabel='')

plot wrappper

Parameters:
  • x (array_like) – array on the horizontal axis of the plot
  • y (array_like) – array on the vertical axis of the plot
  • title (str, optional) – title
  • xlabel (str, optional) – xlabel
  • ylabel (str, optional) – ylabel
classmethod zeros(time)

return zeros that array size is same as time length

Parameters:time (array_like) –
Returns:(N, ) ndarray
class OpenGoddard.optimize.Problem(time_init, nodes, number_of_states, number_of_controls, maxIterator=100, method='LGL')

Bases: object

OpenGoddard Problem class.

Parameters:
  • time_init (list of float) – [time_start, time_section0, time_section0, , , time_final]
  • nodes (int) – number of nodes
  • number_of_states (list) – number of states
  • number_of_controls (list) – number of controls
  • maxIterator (int) – iteration max
Variables:
  • nodes (int) – time nodes.
  • number_of_states (int) – number of states.
  • number_of_controls (int) – number of controls
  • number_of_section (int) – number of section
  • number_of_param (int) – number of inner variables
  • div (list) – division point of inner variables
  • tau – Gauss nodes
  • w – weights of Gaussian quadrature
  • D – differentiation matrix of Gaussian quadrature
  • time – time
  • maxIterator (int) – max iterator
  • time_all_section – all section time
  • unit_states (list of float) – canonical unit of states
  • unit_controls (list of float) – canonical unit of controls
  • unit_time (float) – canonical unit of time
  • p ((N,) ndarray) – inner variables for optimization
  • dynamics (function) – function list, list of function of dynamics
  • knot_states_smooth (list of True/False) – list of states are smooth on phase knots
  • cost (function) – cost function
  • running_cost (function, optional) – (default = None)
  • cost_derivative (function, optional) – (default = None)
  • equality (function) – (default = None)
  • inequality (function) – (default = None)
controls(control, section)

getter specify section controls array

Parameters:
  • control (int) – control number
  • section (int) – section number
Returns:

1-D array of controls

Return type:

controls (ndarray)

controls_all_section(control)

get controls array

Parameters:control (int) – control number
Returns:1-D array of all section control
Return type:controls_all_section ((N, ) ndarray)
index_controls(control, section, index=None)
index_states(state, section, index=None)

get index of state at specific section

Parameters:
  • state (int) – state
  • section (int) – section
  • index (int, optional) – index
Returns:

index of states

Return type:

index_states (int)

index_time_final(section)
method_LG(n)

Legendre-Gauss Pseudospectral method Gauss nodes are roots of \(P_n(x)\).

Parameters:n (int) – number of nodes
Returns:nodes, weight, differentiation_matrix
Return type:ndarray, ndarray, ndarray
method_LGL(n)

Legendre-Gauss-Lobatto Pseudospectral method Gauss-Lobatto nodes are roots of \(P'_{n-1}(x)\) and -1, 1.

Parameters:n (int) – number of nodes
Returns:nodes, weight, differentiation_matrix
Return type:ndarray, ndarray, ndarray

References

Fariba Fahroo and I. Michael Ross. “Advances in Pseudospectral Methods for Optimal Control”, AIAA Guidance, Navigation and Control Conference and Exhibit, Guidance, Navigation, and Control and Co-located Conferences http://dx.doi.org/10.2514/6.2008-7309

method_LGR(n)

Legendre-Gauss-Radau Pseudospectral method Gauss-Radau nodes are roots of \(P_n(x) + P_{n-1}(x)\).

Parameters:n (int) – number of nodes
Returns:nodes, weight, differentiation_matrix
Return type:ndarray, ndarray, ndarray
plot(title_comment='')

plot inner variables that to be optimized

Parameters:title_comment (str) – string for title
set_controls(control, section, value)

set value to control at all section

Parameters:
  • control (int) – control
  • section (int) – section
  • value (int) – value
set_controls_all_section(control, value_all_section)

set value to control at all section

Parameters:
  • control (int) – control
  • value_all_section (int) – value
set_states(state, section, value)

set value to state at specific section

Parameters:
  • state (int) – state
  • section (int) – section
  • value (int) – value
set_states_all_section(state, value_all_section)

set value to state at all section

Parameters:
  • state (int) – state
  • value_all_section (int) – value
set_time_final(section, value)

set value to final time at specific section

Parameters:
  • section (int) – seciton
  • value (float) – value
set_unit_controls(control, section, value)

set a canonical unit value to the control at a specific section

Parameters:
  • control (int) – control
  • section (int) – section
  • value (float) – value
set_unit_controls_all_section(control, value)

set a canonical unit value to the control at all sections

Parameters:
  • control (int) – control
  • value (float) – value
set_unit_states(state, section, value)

set a canonical unit value to the state at a specific section

Parameters:
  • state (int) – state
  • section (int) – section
  • value (float) – value
set_unit_states_all_section(state, value)

set a canonical unit value to the state at all sections

Parameters:
  • state (int) – state
  • value (float) – value
set_unit_time(value)

set a canonical unit value to the time

Parameters:value (float) – value
solve(obj, display_func=<function Problem._dummy_func>, **options)

solve NLP

Parameters:
  • obj (object instance) – instance
  • display_func (function) – function to display intermediate values
  • ftol (float, optional) – Precision goal for the value of f in the stopping criterion, (default: 1e-6)
  • maxiter (int, optional) – Maximum number of iterations., (default : 25)

Examples

“prob” is Problem class’s instance.

>>> prob.solve(obj, display_func, ftol=1e-12)
states(state, section)

getter specify section states array

Parameters:
  • state (int) – state number
  • section (int) – section number
Returns:

1-D array of state

Return type:

states ((N,) ndarray)

states_all_section(state)

get states array

Parameters:state (int) – state number
Returns:1-D array of all section state
Return type:states_all_section ((N,) ndarray)
time_final(section)

get time at section “end”

Parameters:section (int) – section
Returns:time at section end
Return type:time_final (int)
time_final_all_section()

get time at “end”

Parameters:section (int) – section
Returns:time at end
Return type:time_final_all_section (int)
time_knots()

get time at knot point

Returns:time at knot point
Return type:time_knots (list)
time_start(section)

get time at section “start”

Parameters:section (int) – section
Returns:time at section start
Return type:time_start (int)
time_to_tau(time)
time_update()

get time array after optimization

Returns:
(N,) ndarray
time array
Return type:time_update
to_csv(filename='OpenGoddard_output.csv', delimiter=', ')

output states, controls and time to csv file

Parameters:
  • filename (str, optional) – csv filename
  • delimiter – (str, optional) : default ”,”

Module contents