Skip to content

Commit

Permalink
- Use member initializers instead of constructor. Allows for showing …
Browse files Browse the repository at this point in the history
…defaults in doc tooltips or when going to definition. Matches trajopt_sqp.

- Clean up comments
  • Loading branch information
rjoomen authored and Levi-Armstrong committed Nov 21, 2023
1 parent 806a40a commit 3f14fad
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 60 deletions.
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
Expand Down
1 change: 1 addition & 0 deletions trajopt_optimizers/trajopt_sqp/include/trajopt_sqp/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum class CostPenaltyType
*/
struct SQPParameters
{
/** @brief Minimum ratio exact_improve/approx_improve to accept step */
double improve_ratio_threshold = 0.25;
/** @brief NLP converges if trust region is smaller than this */
double min_trust_box_size = 1e-4;
Expand Down
70 changes: 34 additions & 36 deletions trajopt_sco/include/trajopt_sco/optimizers.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once
#include <trajopt_common/macros.h>
TRAJOPT_IGNORE_WARNINGS_PUSH
#include <array>
#include <functional>
#include <string>
#include <array>
TRAJOPT_IGNORE_WARNINGS_POP

#include <trajopt_sco/modeling.hpp>
Expand Down Expand Up @@ -83,46 +83,44 @@ class Optimizer

struct BasicTrustRegionSQPParameters
{
double improve_ratio_threshold; // minimum ratio true_improve/approx_improve
// to accept step
double min_trust_box_size; // if trust region gets any smaller, exit and
// report convergence
double min_approx_improve; // if model improves less than this, exit and
// report convergence
double min_approx_improve_frac; // if model improves less than this, exit and
// report convergence
double max_iter; // The max number of iterations
double trust_shrink_ratio; // if improvement is less than
// improve_ratio_threshold, shrink trust region by
// this ratio
double trust_expand_ratio; // if improvement is less than
// improve_ratio_threshold, shrink trust region by
// this ratio
double cnt_tolerance; // after convergence of penalty subproblem, if
// constraint violation is less than this, we're done
/** @brief Minimum ratio exact_improve/approx_improve to accept step */
double improve_ratio_threshold = 0.25;
/** @brief If trust region gets any smaller, exit and report convergence */
double min_trust_box_size = 1e-4;
/** @brief If model improves less than this, exit and report convergence */
double min_approx_improve = 1e-4;
/** @brief If model improves less than this, exit and report convergence */
double min_approx_improve_frac = static_cast<double>(-INFINITY);
/** @brief The max number of iterations */
double max_iter = 50;
/** @brief If improvement is less than improve_ratio_threshold, shrink trust region by this ratio */
double trust_shrink_ratio = 0.1;
/** @brief If improvement is less than improve_ratio_threshold, expand trust region by this ratio */
double trust_expand_ratio = 1.5;
/** @brief After convergence of penalty subproblem, if constraint violation is less than this, we're done */
double cnt_tolerance = 1e-4;
/** @brief Max number of times that the constraints' cost will be increased */
double max_merit_coeff_increases;
/** @brief Max number of times the QP solver can fail before optimization is aborted*/
int max_qp_solver_failures;

double merit_coeff_increase_ratio; // ratio that we increate coeff each time
/** @brief Max time in seconds that the optimizer will run*/
double max_time;
double max_merit_coeff_increases = 5;
/** @brief Max number of times the QP solver can fail before optimization is aborted */
int max_qp_solver_failures = 3;
/** @brief Ratio that we increase coeff each time */
double merit_coeff_increase_ratio = 10;
/** @brief Max time in seconds that the optimizer will run */
double max_time = static_cast<double>(INFINITY);
/** @brief Initial coefficient that is used to scale the constraints. The total constaint cost is constaint_value *
* coeff * merit_coeff */
double initial_merit_error_coeff;
double initial_merit_error_coeff = 10;
/** @brief If true, merit coeffs will only be inflated for the constaints that failed. This can help when there are
* lots of constaints*/
bool inflate_constraints_individually;
double trust_box_size; // current size of trust region (component-wise)

bool log_results; // Log results to file
std::string log_dir; // Directory to store log results (Default: /tmp)

* lots of constraints */
bool inflate_constraints_individually = true;
/** @brief Current size of trust region (component-wise) */
double trust_box_size = 1e-1;
/** @brief Log results to file */
bool log_results = false;
/** @brief Directory to store log results */
std::string log_dir = "/tmp";
/** @brief If greater than one, multi threaded functions are called */
int num_threads;

BasicTrustRegionSQPParameters();
int num_threads = 0;
};

class BasicTrustRegionSQP : public Optimizer
Expand Down
23 changes: 0 additions & 23 deletions trajopt_sco/src/optimizers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ TRAJOPT_IGNORE_WARNINGS_PUSH
#include <cmath>
#include <chrono>
#include <cstdio>
#include <thread>
TRAJOPT_IGNORE_WARNINGS_POP

#include <trajopt_sco/expr_ops.hpp>
Expand Down Expand Up @@ -76,28 +75,6 @@ void Optimizer::initialize(const DblVec& x)
results_.x = x;
}

BasicTrustRegionSQPParameters::BasicTrustRegionSQPParameters()
{
improve_ratio_threshold = 0.25;
min_trust_box_size = 1e-4;
min_approx_improve = 1e-4;
min_approx_improve_frac = static_cast<double>(-INFINITY);
max_iter = 50;
trust_shrink_ratio = 0.1;
trust_expand_ratio = 1.5;
cnt_tolerance = 1e-4;
max_merit_coeff_increases = 5;
max_qp_solver_failures = 3;
merit_coeff_increase_ratio = 10;
max_time = static_cast<double>(INFINITY);
initial_merit_error_coeff = 10;
inflate_constraints_individually = true;
trust_box_size = 1e-1;
log_results = false;
log_dir = "/tmp";
num_threads = 0;
}

BasicTrustRegionSQP::BasicTrustRegionSQP(const OptProb::Ptr& prob) { ctor(prob); }
void BasicTrustRegionSQP::setProblem(OptProb::Ptr prob) { ctor(prob); }
void BasicTrustRegionSQP::setParameters(const BasicTrustRegionSQPParameters& param) { param_ = param; }
Expand Down

0 comments on commit 3f14fad

Please sign in to comment.