Go to the documentation of this file.00001
00019 #ifndef __INC_OPTIMIZER
00020 #define __INC_OPTIMIZER
00021
00022 #include <log.h>
00023 #include <frame.h>
00024 #include <configuration.h>
00025 #include <datapairs.h>
00026 #include <value_setter.h>
00027 #include <optimizer_goal.h>
00028 #include <optimizer_goal_global_position.h>
00029 #include <optimizer_goal_global_orientation.h>
00030 #include <optimizer_goal_orientation.h>
00031 #include <optimizer_goal_position.h>
00032 #include <optimizer_container.h>
00033
00034 namespace robotLibPbD {
00035
00036 class COptimizerResult
00037 {
00038 public:
00039 std::vector<std::vector<std::pair<std::string, CMatrix> > > timelineOfPoses;
00040
00041 std::vector<std::pair<std::string, CMatrix> > allPoses;
00042 std::vector<std::pair<std::string, CMatrix> > optimizedPoses;
00043 std::vector<double> values;
00044 double result;
00045
00046 void clear();
00047 };
00048
00049 class COptimizer
00050 {
00051 protected:
00052 std::vector<ValueSetter> valueSetters;
00053 std::vector<double> result;
00054
00055 std::vector<OptimizerContainer> data;
00056 std::vector<OptimizerGoalGlobal*> globalFunctions;
00057 std::vector<OptimizerGoal*> functions;
00058 CFrameContainer frames;
00059 DataPairs information;
00060
00061 std::vector<std::vector<double> > examples;
00062 std::vector<double> distances;
00063 unsigned int counter;
00064 double trim;
00065 unsigned int examplesMax, iterations;
00066 unsigned int dofs;
00067 unsigned int counterMod, trimming;
00068 bool useRandom, useShowResult, doQuit;
00069 double resultValue, epsilon;
00070
00071 void setValue(double *x);
00072 bool writeToFile(std::string filename, std::string buffer);
00073 std::string readFromFile(std::string filename);
00074 void setData(std::vector<double> &values);
00075 void callback(int nparam, double *x, double *fj);
00076
00077 bool isEqual(std::vector<double> &first, std::vector<double> &second, double eps = 0.1);
00078
00079 void loadData(std::string filename, unsigned int startId = 0);
00080 void loadDofs(std::string filename);
00081 void loadGoals(std::string filename);
00082 void loadValueSetters(std::string filename);
00083
00084 int getValue(TiXmlElement *node, std::string item);
00085 void reset();
00086
00087 public:
00088 COptimizer() : counter(0), trim(0.0), examplesMax(100000),dofs(0),counterMod(10000),useRandom(false),useShowResult(false),doQuit(false),epsilon(1.0e-8) {}
00089
00090 static void rosenbrockCallback(int nparam, double *x, double *fj, void *extraparams);
00091
00092 void load(std::string cfg, std::string data, unsigned int start = 0);
00093
00094 virtual std::string generateOutput();
00095
00096 void run(const std::vector<double> &initialValues);
00097
00098 void setEpsilon(double eps) { this->epsilon = eps; }
00099 void setTrimming(double trim) { this->trim = trim; }
00100 void setIterations(unsigned int iterations) { this->iterations = iterations; }
00101 void setRandomStart(bool useRandom) { this->useRandom = useRandom; }
00102 void setQuit(bool doQuit) { this->doQuit = doQuit; }
00103 void setDataMax(unsigned int examplesMax) { this->examplesMax = examplesMax; }
00104 void setShowResult(bool useShowResult) { this->useShowResult = useShowResult; }
00105 void setShowModulo(unsigned int counterMod) { this->counterMod = counterMod; }
00106
00107 bool getResult(COptimizerResult &out);
00108 };
00109
00110 };
00111
00112 #endif