DART  6.10.1
SnoptInterface.hpp
Go to the documentation of this file.
1 /*
2  RTQL8, Copyright (c) 2011 Georgia Tech Graphics Lab
3  All rights reserved.
4 
5  Author Sehoon Ha
6  Date 06/19/2011
7 */
8 
9 #ifndef DART_OPTIMIZER_SNOPT_SNOPT_INTERFACE_H
10 #define DART_OPTIMIZER_SNOPT_SNOPT_INTERFACE_H
11 
12 #include <vector>
13 #include <Eigen/Dense>
14 #include "dart/optimizer/OptimizerArrayTypes.h"
15 
16 #ifndef ZERO
17 #define ZERO 1.0e-30
18 #endif // ifndef ZERO
19 
20 namespace dart {
21 namespace optimizer {
22 namespace snopt {
23 
25 public:
27  enum UpdateType { Obj = 1, Constr = 2 };
28  enum SlackType { NoSlack = 0, Vslack = 1, Wslack = 2 };
30 
31  struct Slack {
34  double val;
35  };
36 
37  typedef int (*updateFunc) (long mask, int compute_gradients, double *coef_values, void *update_data);
38 
39  SnoptInterface(int constr_total, int coef_total,
40  int nonlin_constr_total, int nonlin_obj_coef, int nonlin_jac_coef,
41  int *constr_eqns, int has_objective, VVD J, VVB JMap, std::vector<double> *constraints,
42  double *objective, std::vector<double> *gradient, updateFunc update_f, void *update_d);
43 
44  SnoptInterface(int has_objective, VVD J, VVB JMap, std::vector<double> *constraints, double *objective,
45  std::vector<double> *gradient, updateFunc update_f, void *update_d);
47 
48  Return solve(double *x, double *lo_bounds, double *hi_bounds, int unit = 4);
49 
50  void clear(long mask, int compute_derivs);
51 
52  void resizeJacobian(int coef_total, int nonlin_coef_total, int constr_total, int nonlin_constr_total);
53  void resizeCoef();
54 
56  int mNumCoef;
60 
61  double *mSolverX;
62  double *mProblemX;
63  double *mBoundsLo;
64  double *mBoundsHi;
66 
68 
70 
71  double *mObj;
72  std::vector<double> *mdObjdCoef;
73 
74  std::vector<double> *mConstr;
76 
77  Eigen::VectorXd mConstrScale;
78  Eigen::VectorXd mCoefScale;
79 
80  VVB mCoefMap;
81  double mReturnedObj;
82 
83  int mOutput;
84  int mSum;
85  bool mCheckTerm;
88  int mBreak;
89 
90  void updateSolverX();
91  void update(long mask, int compute_derivs, double *x);
92  static void checkTermination(int *iAbort, double *xs);
93 
94 
95 protected:
97  void *mUpdateData;
98 
99  void scaleValues(long update_type, int compute_derivs);
100 
101 private:
102  static void snoptObj(int *mode, int *nn_obj, double *x,
103  double *f_obj, double *g_obj, int *nstate,
104  char *cu, int *lencu, int *iu, int *leniu,
105  double *ru, int *lenru);
106  static void snoptJac(int *mode, int *nn_con, int *nn_jac, int *ne_jac,
107  double *x, double *f_con, double *g_con, int *nstate,
108  char *cu, int *lencu, int *iu, int *leniu,
109  double *ru, int *lenru);
110  void fillUpSnoptFormat(VVD jacobian, double **a, int **ha, int **ka);
111  int sparseCount(int col);
112 
113 };
114 
115 } // namespace snopt
116 } // namespace optimizer
117 } // namespace dart
118 
119 #endif // #ifndef DART_OPTIMIZER_SNOPT_SNOPT_INTERFACE_H
120 
Definition: SnoptInterface.hpp:24
double * mSolverX
Definition: SnoptInterface.hpp:61
SlackType
Definition: SnoptInterface.hpp:28
@ Vslack
Definition: SnoptInterface.hpp:28
@ NoSlack
Definition: SnoptInterface.hpp:28
@ Wslack
Definition: SnoptInterface.hpp:28
static void snoptJac(int *mode, int *nn_con, int *nn_jac, int *ne_jac, double *x, double *f_con, double *g_con, int *nstate, char *cu, int *lencu, int *iu, int *leniu, double *ru, int *lenru)
Definition: SnoptInterface.cpp:504
AbnormalType mAbnormal
Definition: SnoptInterface.hpp:87
void fillUpSnoptFormat(VVD jacobian, double **a, int **ha, int **ka)
Definition: SnoptInterface.cpp:538
void clear(long mask, int compute_derivs)
Definition: SnoptInterface.cpp:109
Return
Definition: SnoptInterface.hpp:26
@ Stop
Definition: SnoptInterface.hpp:26
@ Solution
Definition: SnoptInterface.hpp:26
@ UserStop
Definition: SnoptInterface.hpp:26
@ Infeasible
Definition: SnoptInterface.hpp:26
@ Error
Definition: SnoptInterface.hpp:26
void * mUpdateData
Definition: SnoptInterface.hpp:97
static void snoptObj(int *mode, int *nn_obj, double *x, double *f_obj, double *g_obj, int *nstate, char *cu, int *lencu, int *iu, int *leniu, double *ru, int *lenru)
Definition: SnoptInterface.cpp:484
Eigen::VectorXd mConstrScale
Definition: SnoptInterface.hpp:77
int mNumNonlinObjCoef
Definition: SnoptInterface.hpp:58
double * mBoundsLo
Definition: SnoptInterface.hpp:63
void updateSolverX()
Definition: SnoptInterface.cpp:194
VVB mCoefMap
Definition: SnoptInterface.hpp:80
void resizeJacobian(int coef_total, int nonlin_coef_total, int constr_total, int nonlin_constr_total)
Definition: SnoptInterface.cpp:135
double * mProblemX
Definition: SnoptInterface.hpp:62
bool mTermination
Definition: SnoptInterface.hpp:86
void update(long mask, int compute_derivs, double *x)
Definition: SnoptInterface.cpp:186
int(* updateFunc)(long mask, int compute_gradients, double *coef_values, void *update_data)
Definition: SnoptInterface.hpp:37
int mOutput
Definition: SnoptInterface.hpp:83
VVD mdConstrdCoef
Definition: SnoptInterface.hpp:75
std::vector< double > * mdObjdCoef
Definition: SnoptInterface.hpp:72
static void checkTermination(int *iAbort, double *xs)
Definition: SnoptInterface.cpp:601
AbnormalType
Definition: SnoptInterface.hpp:29
@ NONE
Definition: SnoptInterface.hpp:29
@ HESSIAN_UPDATE
Definition: SnoptInterface.hpp:29
@ INFEASIBLE
Definition: SnoptInterface.hpp:29
@ HESSIAN_RESET
Definition: SnoptInterface.hpp:29
int * mConstrEqns
Definition: SnoptInterface.hpp:65
UpdateType
Definition: SnoptInterface.hpp:27
@ Obj
Definition: SnoptInterface.hpp:27
@ Constr
Definition: SnoptInterface.hpp:27
double * mBoundsHi
Definition: SnoptInterface.hpp:64
std::vector< double > * mConstr
Definition: SnoptInterface.hpp:74
int mHasObjective
Definition: SnoptInterface.hpp:67
~SnoptInterface()
Definition: SnoptInterface.cpp:98
int mNumNonlinJacCoef
Definition: SnoptInterface.hpp:59
int mBreak
Definition: SnoptInterface.hpp:88
double * mObj
Definition: SnoptInterface.hpp:71
SnoptInterface(int constr_total, int coef_total, int nonlin_constr_total, int nonlin_obj_coef, int nonlin_jac_coef, int *constr_eqns, int has_objective, VVD J, VVB JMap, std::vector< double > *constraints, double *objective, std::vector< double > *gradient, updateFunc update_f, void *update_d)
Definition: SnoptInterface.cpp:21
int mNumNonlinConstr
Definition: SnoptInterface.hpp:57
int mNumConstr
Definition: SnoptInterface.hpp:55
int mNumCoef
Definition: SnoptInterface.hpp:56
double mReturnedObj
Definition: SnoptInterface.hpp:81
static SnoptInterface * mRef
Definition: SnoptInterface.hpp:69
SnoptInterface::updateFunc mUpdateFunc
Definition: SnoptInterface.hpp:96
int sparseCount(int col)
Definition: SnoptInterface.cpp:591
int mSum
Definition: SnoptInterface.hpp:84
bool mCheckTerm
Definition: SnoptInterface.hpp:85
Eigen::VectorXd mCoefScale
Definition: SnoptInterface.hpp:78
Return solve(double *x, double *lo_bounds, double *hi_bounds, int unit=4)
Definition: SnoptInterface.cpp:298
void scaleValues(long update_type, int compute_derivs)
Definition: SnoptInterface.cpp:199
Definition: BulletCollisionDetector.cpp:65
Definition: SnoptInterface.hpp:31
double val
Definition: SnoptInterface.hpp:34
SlackType type
Definition: SnoptInterface.hpp:33
int constr_idx
Definition: SnoptInterface.hpp:32