Near-linear optimization tool tailored for s/c trajectory design.
This is a modernization of the original Fortran 77 code from: pyoptgra. It has been extensively refactored. The old common blocks were removed, and all data is now encapsulated in a single optgra class.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private, | parameter | :: | wp | = | real64 |
Real working precision if not specified [8 bytes] |
| integer, | public, | parameter | :: | optgra_wp | = | wp |
Working real precision |
| integer(kind=ip), | private, | parameter | :: | name_len | = | 80 |
max string length for var names |
| integer(kind=ip), | private, | parameter | :: | str_len | = | 256 |
max string length for str prints |
FUNCTION FOR VALUES INPUT AND OUTPUT NOT SCALED
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in), | dimension(:) | :: | varvec |
size is Numvar |
|
| real(kind=wp), | intent(out), | dimension(:) | :: | Valcon |
size is Numcon+1 |
|
| integer, | intent(in) | :: | i |
JW: THIS IS NOT DOCUMENTED ? IFLAG? |
FUNCTION FOR VALUES AND DERIVATIVES INPUT AND OUTPUT NOT SCALED
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in), | dimension(:) | :: | varvec |
size is Numvar |
|
| real(kind=wp), | intent(out), | dimension(:) | :: | convec |
size is Numcon+1 |
|
| real(kind=wp), | intent(out), | dimension(:,:) | :: | Dercon |
size is Numcon+1,Numvar |
Main class for OPTGRA algorithm.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=ip), | private | :: | numvar | = | 0 |
number of variables |
|
| real(kind=wp), | private, | dimension(: ), allocatable | :: | varval | |||
| integer(kind=ip), | private, | dimension(: ), allocatable | :: | vartyp | |||
| real(kind=wp), | private, | dimension(: ), allocatable | :: | varsca | |||
| character(len=name_len), | private, | dimension(: ), allocatable | :: | varstr | |||
| integer(kind=ip), | private, | dimension(: ), allocatable | :: | varlen | |||
| real(kind=wp), | private, | dimension(: ), allocatable | :: | varref | |||
| real(kind=wp), | private, | dimension(: ), allocatable | :: | vardes | |||
| real(kind=wp), | private, | dimension(: ), allocatable | :: | vargrd | |||
| real(kind=wp), | private, | dimension(: ), allocatable | :: | vardir | |||
| real(kind=wp), | private, | dimension(: ), allocatable | :: | funvar | |||
| real(kind=wp), | private, | dimension(: ), allocatable | :: | senvar | |||
| integer(kind=ip), | private | :: | numcon | = | 0 |
number of constraints |
|
| real(kind=wp), | private, | dimension(: ), allocatable | :: | conval | |||
| integer(kind=ip), | private, | dimension(: ), allocatable | :: | contyp | |||
| integer(kind=ip), | private, | dimension(: ), allocatable | :: | conpri | |||
| real(kind=wp), | private, | dimension(: ), allocatable | :: | consca | |||
| character(len=name_len), | private, | dimension(: ), allocatable | :: | constr | |||
| integer(kind=ip), | private, | dimension(: ), allocatable | :: | conlen | |||
| real(kind=wp), | private, | dimension(: ), allocatable | :: | conref | |||
| real(kind=wp), | private, | dimension(: ), allocatable | :: | senqua | |||
| real(kind=wp), | private, | dimension(: ), allocatable | :: | sencon | |||
| real(kind=wp), | private, | dimension(: ), allocatable | :: | sendel | |||
| integer(kind=ip), | private, | dimension(: ), allocatable | :: | senact | |||
| integer(kind=ip), | private | :: | optmet | = | 2 |
optimization method |
|
| integer(kind=ip), | private | :: | maxite | = | 10 |
maximum number of iterations |
|
| integer(kind=ip), | private | :: | corite | = | 10 | ||
| integer(kind=ip), | private | :: | optite | = | 10 | ||
| integer(kind=ip), | private | :: | divite | = | 10 | ||
| integer(kind=ip), | private | :: | cnvite | = | 10 | ||
| real(kind=wp), | private | :: | Varmax | = | 10.0_wp |
maximum distance per iteration |
|
| real(kind=wp), | private | :: | varsnd | = | 1.0_wp |
perturbation for 2nd order derivatives |
|
| real(kind=wp), | private | :: | varstp | = | 1.0_wp | ||
| integer(kind=ip), | private | :: | varder | = | 1 |
derivatives computation mode |
|
| real(kind=wp), | private, | dimension(: ), allocatable | :: | varper | |||
| integer(kind=ip), | private | :: | loglun | = | output_unit |
log file unit |
|
| integer(kind=ip), | private | :: | loglev | = | 1 |
log level |
|
| integer(kind=ip), | private | :: | loglup | = | output_unit |
pygmo log file unit |
|
| integer(kind=ip), | private | :: | verbos | = | 0 |
pygmo verbosity |
|
| integer(kind=ip), | private | :: | fevals | = | 0 |
pygmo: number of const fun evals |
|
| integer(kind=ip), | private | :: | pygfla | = | 0 |
pygmo: flag indicating status of optimization |
|
| integer(kind=ip), | private | :: | numite | = | 0 |
number of iterations |
|
| integer(kind=ip), | private | :: | matlev | = | 0 | ||
| integer(kind=ip), | private | :: | tablun | = | output_unit |
logical unit for writing table |
|
| integer(kind=ip), | private | :: | tablev | = | 0 |
level of tab |
|
| integer(kind=ip), | private | :: | senopt | = | 0 |
sensitivity optimization mode |
|
| integer(kind=ip), | private | :: | numact | = | 0 | ||
| integer(kind=ip), | private, | dimension(: ), allocatable | :: | actcon | |||
| integer(kind=ip), | private, | dimension(: ), allocatable | :: | confix | |||
| integer(kind=ip), | private, | dimension(: ), allocatable | :: | conact | |||
| real(kind=wp), | private, | dimension(:,:), allocatable | :: | conder | |||
| real(kind=wp), | private, | dimension(:,:), allocatable | :: | conred | |||
| real(kind=wp), | private, | dimension(:,:), allocatable | :: | sender | |||
| procedure(calval_f), | private, | pointer | :: | calval | => | null() |
function for values |
| procedure(calder_f), | private, | pointer | :: | calder | => | null() |
function for derivatives |
| procedure, public :: initialize | set up the problem |
| procedure, public :: solve => ogexec | solve the problem |
| procedure, public :: destroy => ogclos | free memory when finished |
| procedure, public :: ogsens | |
| procedure, public :: ogssst | |
| procedure, public :: oggsst | |
| procedure, private :: ogrigt | |
| procedure, private :: ogincl | |
| procedure, private :: ogexcl | |
| procedure, private :: ogeval | |
| procedure, private :: ogcorr | |
| procedure, private :: ogopti | |
| procedure, private :: ogleft | |
| procedure, private :: ogpwri | |
| procedure, private :: ogwrit | |
| procedure, private :: ogpwri_start | |
| procedure, private :: ogpwri_end |
LEFT-MULTIPLIES VECTOR LOWER TRIANGULAR MATRIX OBTAINED BY REDUCTION AND SUBSEQUENT INVERSION OF DERIVATIVES OF ACTIVE CONSTRAINTS
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | Actinp(me%Numcon) |
VECTOR INITAL |
VECTOR FINAL
RIGHT-MULTIPLIES VECTOR LOWER TRIANGULAR MATRIX OBTAINED BY REDUCTION AND SUBSEQUENT INVERSION OF DERIVATIVES OF ACTIVE CONSTRAINTS
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | Actinp(me%Numcon) |
VECTOR INITAL |
VECTOR FINAL
Initialize the class. This should be the first routine called.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(out) | :: | me | |||
| integer(kind=ip), | intent(in) | :: | Numvar |
NUMBER OF VARIABLES |
||
| integer(kind=ip), | intent(in) | :: | Numcon |
NUMBER OF CONSTRAINTS |
||
| procedure(calval_f) | :: | Calval |
FUNCTION FOR VALUES -> INPUT AND OUTPUT NOT SCALED |
|||
| procedure(calder_f) | :: | Calder |
FUNCTION FOR VALUES AND DERIVATIVES -> INPUT AND OUTPUT NOT SCALED |
|||
| real(kind=wp), | intent(in) | :: | Delcon(Numcon+1) |
CONSTRAINTS DELTAS (CONSTRAINT + MERIT CONVERGENCE THRESHOLDS) |
||
| integer(kind=ip), | intent(in) | :: | Conpri(Numcon+1) |
CONSTRAINTS PRIORITY (1:NUMCON) -> 1-N |
||
| real(kind=wp), | intent(in) | :: | Consca(Numcon+1) |
|
||
| character(len=name_len), | intent(in) | :: | Constr(Numcon+1) |
CONIABLES NAME STRING |
||
| integer(kind=ip), | intent(in) | :: | Conlen(Numcon+1) |
CONIABLES NAME LENGTH |
||
| integer(kind=ip), | intent(in) | :: | Contyp(Numcon+1) |
CONSTRAINTS TYPE (1:NUMCON) |
||
| integer(kind=ip), | intent(in) | :: | Varder |
DERIVATIVES COMPUTATION MODE |
||
| real(kind=wp), | intent(in) | :: | Varper(Numvar) |
VARIABLES PERTURBATION FOR DERIVATIVES -> NOT SCALED |
||
| real(kind=wp), | intent(in) | :: | Varmax |
MAXIMUM DISTANCE PER ITERATION -> SCALED |
||
| real(kind=wp), | intent(in) | :: | Varsnd |
PERTURBATION FOR 2ND ORDER DERIVATIVES -> SCALED |
||
| integer(kind=ip), | intent(in) | :: | Maxite |
maximum number of iterations |
||
| integer(kind=ip), | intent(in) | :: | Itecor |
number of constraint correction iterations in the beginning. If no feasible solution is found within that many iterations, Optgra aborts |
||
| integer(kind=ip), | intent(in) | :: | Iteopt |
some other iter input ? |
||
| integer(kind=ip), | intent(in) | :: | Itediv |
some other iter input ? |
||
| integer(kind=ip), | intent(in) | :: | Itecnv |
some other iter input ? |
||
| integer(kind=ip), | intent(in) | :: | Loglup |
LOGICAL UNIT FOR WRITING PYGMO LOG |
||
| integer(kind=ip), | intent(in) | :: | Verbos |
VERBOSITY LEVEL: |
||
| integer(kind=ip), | intent(in) | :: | Senopt |
sensitivity optimization mode |
||
| real(kind=wp), | intent(in) | :: | Varsca(Numvar) |
VARIABLES SCALE FACTOR |
||
| character(len=name_len), | intent(in) | :: | Varstr(Numvar) |
VARIABLES NAME STRING |
||
| integer(kind=ip), | intent(in) | :: | Varlen(Numvar) |
VARIABLES NAME LENGTH |
||
| integer(kind=ip), | intent(in) | :: | Vartyp(Numvar) |
VARIABLES TYPE |
||
| integer(kind=ip), | intent(in) | :: | Loglun |
LOGICAL UNIT FOR WRITING LOG |
||
| integer(kind=ip), | intent(in) | :: | Loglev |
LEVEL OF LOG: |
||
| integer(kind=ip), | intent(in) | :: | Matlev |
LEVEL OF LOG: |
||
| integer(kind=ip), | intent(in) | :: | Tablun |
logical unit for writing table |
||
| integer(kind=ip), | intent(in) | :: | Tablev |
LEVEL OF TAB |
||
| integer(kind=ip), | intent(in) | :: | Optmet |
OPTIMIZATION METHOD: |
DEALLOCATION OF ARRAYS
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me |
CORRECTION PART
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(inout) | :: | Varacc | |||
| integer(kind=ip), | intent(out) | :: | Finish | |||
| real(kind=wp) | :: | Toterr | ||||
| real(kind=wp) | :: | Norerr | ||||
| logical, | intent(out) | :: | error |
if there was a fatal error |
COMPUTES SCALED CONTRAINTS+MERIT AND DERIVATIVES FROM SCALED VARIABLES
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | Valvar(me%Numvar) |
SCALED VARIABLES:
|
||
| real(kind=wp), | intent(out) | :: | Valcon(me%Numcon+1) |
SCALED CONTRAINTS+MERIT AND DERIVATIVES: |
||
| integer(kind=ip), | intent(in) | :: | Varder |
DERIVATIVES COMPUTATION MODE |
||
| real(kind=wp), | intent(out) | :: | Dercon(me%Numcon+1,me%Numvar) |
derivatives of scaled valcon w.r.t. scaled valvar:
|
REMOVE CONSTRAINT TO ACTIVE SET AND REDUCES DERIVATIVES
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| integer(kind=ip), | intent(in) | :: | Exc |
CONSTRAINT TO BE REMOVED SEQUENCE NUMBER IN ACTIVE LIST |
||
| logical, | intent(out) | :: | error |
if there was a fatal error (constraints singular) |
Main routine.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(inout) | :: | Valvar(me%Numvar) |
VARIABLES VALUE -> NOT SCALED |
||
| real(kind=wp), | intent(out) | :: | Valcon(me%Numcon+1) |
CONSTRAINTS VALUE (1:NUMCON) MERIT VALUE (1+NUMCON) -> NOT SCALED |
||
| integer(kind=ip), | intent(out) | :: | Finopt |
TERMINATION STATUS |
||
| integer(kind=ip), | intent(out) | :: | Finite |
? |
NEAR-LINEAR OPTIMIZATION TOOL SENSITIVITY ANALYSIS
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(out) | :: | Varsen(me%Numvar) |
STORED VARIABLES VALUE |
||
| real(kind=wp), | intent(out) | :: | Quasen(me%Numcon+1) |
STORED CONSTRAINTS CORRECTION VECTOR |
||
| real(kind=wp), | intent(out) | :: | Consen(me%Numcon+1) |
STORED CONSTRAINTS VALUE |
||
| integer(kind=ip), | intent(out) | :: | Actsen(me%Numcon+1) |
STORED CONSTRAINTS ACTIVE |
||
| real(kind=wp), | intent(out) | :: | Dersen(me%Numcon+1,me%Numvar) |
STORED DERIVATIVE |
||
| integer(kind=ip), | intent(out) | :: | Actsav(me%Numcon+1) |
STORED ACTIVE CONSTRAINTS |
||
| integer(kind=ip), | intent(out) | :: | Consav(me%Numcon+4) |
STORED ACTIVE CONSTRAINTS |
||
| real(kind=wp), | intent(out) | :: | Redsav(me%Numcon+3,me%Numvar) |
STORED DERIVATIVE |
||
| real(kind=wp), | intent(out) | :: | Dersav(me%Numcon+3,me%Numvar) |
STORED DERIVATIVE |
||
| integer(kind=ip), | intent(out) | :: | Actnum |
NUMBER OF ACTIVE CONSTRAINTS |
ADDS CONSTRAINT TO ACTIVE SET AND REDUCES DERIVATIVES
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| integer(kind=ip), | intent(in) | :: | Inc |
CONSTRAINT TO BE INCLUDED |
OPTIMIZATION PART
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(inout) | :: | Varacc |
ITERATION SCALED DISTANCE ACCUMULATED |
||
| integer(kind=ip), | intent(out) | :: | Finish |
0=LIMIT 1=OPTIM |
||
| real(kind=wp) | :: | Desnor | ||||
| logical, | intent(out) | :: | error |
if there was a fatal error |
WRITE OPTIMIZATION LOG IN PYGMO FORMAT
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | Objval |
OBJECTIVE VALUE |
||
| integer(kind=ip), | intent(in) | :: | Numvio |
NUMBER OF VIOLATED CONSTRAINTS |
||
| real(kind=wp), | intent(in) | :: | Convio |
TOTAL CONSTRAINT VIOLATION |
WRITE OPTIMIZATION END RESULT IN PYGMO FORMAT
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | Objval |
OBJECTIVE VALUE |
||
| integer(kind=ip), | intent(in) | :: | Numvio |
NUMBER OF VIOLATED CONSTRAINTS |
||
| real(kind=wp), | intent(in) | :: | Convio |
TOTAL CONSTRAINT VIOLATION |
WRITE OPTIMIZATION LOG IN PYGMO FORMAT
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me |
NEAR-LINEAR OPTIMIZATION TOOL SENSITIVITY ANALYSIS
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| integer(kind=ip), | intent(out) | :: | Consta(me%Numcon) |
CONSTRAINT STATUS (0=PAS 1=ACT) |
||
| real(kind=wp), | intent(out) | :: | Concon(me%Numcon+1,me%Numcon) |
SENSITIVITY OF CONTRAINTS+MERIT W.R.T. ACTIVE CONSTRAINTS |
||
| real(kind=wp), | intent(out) | :: | Convar(me%Numcon+1,me%Numvar) |
SENSITIVITY OF CONTRAINTS+MERIT W.R.T. PARAMETERS |
||
| real(kind=wp), | intent(out) | :: | Varcon(me%Numvar,me%Numcon) |
SENSITIVITY OF VARIABLES W.R.T. ACTIVE CONSTRAINTS |
||
| real(kind=wp), | intent(out) | :: | Varvar(me%Numvar,me%Numvar) |
SENSITIVITY OF VARIABLES W.R.T. PARAMETERS -> NOT SCALED |
NEAR-LINEAR OPTIMIZATION TOOL SENSITIVITY ANALYSIS
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | Varsen(me%Numvar) |
STORED VARIABLES VALUE |
||
| real(kind=wp), | intent(in) | :: | Quasen(me%Numcon+1) |
STORED CONSTRAINTS CORRECTION VECTOR |
||
| real(kind=wp), | intent(in) | :: | Consen(me%Numcon+1) |
STORED CONSTRAINTS VALUE |
||
| integer(kind=ip), | intent(in) | :: | Actsen(me%Numcon+1) |
STORED CONSTRAINTS ACTIVE |
||
| real(kind=wp), | intent(in) | :: | Dersen(me%Numcon+1,me%Numvar) |
STORED DERIVATIVE |
||
| integer(kind=ip), | intent(in) | :: | Actsav(me%Numcon+1) |
STORED ACTIVE CONSTRAINTS |
||
| integer(kind=ip), | intent(in) | :: | Consav(me%Numcon+4) |
STORED ACTIVE CONSTRAINTS |
||
| real(kind=wp), | intent(in) | :: | Redsav(me%Numcon+3,me%Numvar) |
STORED DERIVATIVE |
||
| real(kind=wp), | intent(in) | :: | Dersav(me%Numcon+3,me%Numvar) |
STORED DERIVATIVE |
||
| integer(kind=ip), | intent(in) | :: | Actnum |
Write a message to the log.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(optgra), | intent(inout) | :: | me | |||
| integer(kind=ip), | intent(in) | :: | Lev |
only print if |
||
| character(len=*), | intent(in) | :: | Str |
string to print |