void testQLDSolver() { BaseVariable xy("xy",2); BaseVariable z("z",1); CompositeVariable T("T", xy, z); MatrixXd A1(1,1); A1 << 1; VectorXd b1(1); b1 << -3; LinearFunction lf1(z, A1, b1); LinearConstraint c1(&lf1, true); MatrixXd A2(1,2); A2 << 3,1 ; VectorXd b2(1); b2 << 0; LinearFunction lf2(xy, A2, b2); LinearConstraint c2(&lf2, true); MatrixXd A3(2,2); A3 << 2,1,-0.5,1 ; VectorXd b3(2); b3 << 0, 1; LinearFunction lf3(xy, A3, b3); LinearConstraint c3(&lf3, false); QuadraticFunction objFunc(T, Matrix3d::Identity(), Vector3d::Zero(), 0); QuadraticObjective obj(&objFunc); QLDSolver solver; solver.addConstraint(c1); solver.addConstraint(c2); solver.addConstraint(c3); solver.addObjective(obj); std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl; ocra_assert(solver.getLastResult().info == 0); solver.removeConstraint(c1); IdentityFunction id(z); VectorXd lz(1); lz << 1; VectorXd uz(1); uz << 2; IdentityConstraint bnd1(&id, lz, uz); solver.addBounds(bnd1); std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl; ocra_assert(solver.getLastResult().info == 0); BaseVariable t("t", 2); VectorXd ut(2); ut << -4,-1; BoundFunction bf(t, ut, BOUND_TYPE_SUPERIOR); BoundConstraint bnd2(&bf, false); solver.addBounds(bnd2); QuadraticFunction objFunc2(t, Matrix2d::Identity(), Vector2d::Constant(2.71828),0); QuadraticObjective obj2(&objFunc2); solver.addObjective(obj2); std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl; ocra_assert(solver.getLastResult().info == 0); Vector2d c3l(-1,-1); c3.setL(c3l); std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl; ocra_assert(solver.getLastResult().info == 0); }
/* NOT UPDATED */ void initUpdateDistMatrix( double * D, double * E, double * SS, size_t d, size_t N, size_t * size, void (*objFunc) ( size_t , size_t , size_t , double * , double * , double * ,size_t, size_t , size_t * ) /* this is an update function */ ) { size_t i, j; /* run some sanity checks */ //assert(N > 1); for( i = 0; i < N-1; i++) { /* iterate over columns */ for( j = i+1; j < N; j++) { /* iterate over rows */ if((size[i] > 1) | (size[j] > 1)) objFunc( j,i,i,D,E,SS,d,N,size) ; } } /* that was it, we are done */ }
// Function definitions. // ----------------------------------------------------------------- void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) try { // Check to see if we have the correct number of input and output // arguments. if (nrhs < minNumInputArgs) throw MatlabException("Incorrect number of input arguments"); // Get the starting point for the variables. This is specified in // the first input argument. The variables must be either a single // matrix or a cell array of matrices. int k = 0; // The index of the current input argument. ArrayOfMatrices x0(prhs[k++]); // Create the output, which stores the solution obtained from // running IPOPT. There should be as many output arguments as cell // entries in X. if (nlhs != x0.length()) throw MatlabException("Incorrect number of output arguments"); ArrayOfMatrices x(plhs,x0); // Load the lower and upper bounds on the variables as // ArrayOfMatrices objects. They should have the same structure as // the ArrayOfMatrices object "x". ArrayOfMatrices lb(prhs[k++]); ArrayOfMatrices ub(prhs[k++]); // Check to make sure the bounds make sense. if (lb != x || ub != x) throw MatlabException("Input arguments LB and UB must have the same \ structure as X"); // Get the Matlab callback functions. MatlabString objFunc(prhs[k++]); MatlabString gradFunc(prhs[k++]); // Get the auxiliary data. const mxArray* auxData; const mxArray* ptr = prhs[k++]; if (nrhs > 5) { if (mxIsEmpty(ptr)) auxData = 0; else auxData = ptr; } else auxData = 0; // Get the intermediate callback function. MatlabString* iterFunc; ptr = prhs[k++]; if (nrhs > 6) { if (mxIsEmpty(ptr)) iterFunc = 0; else iterFunc = new MatlabString(ptr); } else iterFunc = 0; // Set the options for the L-BFGS algorithm to their defaults. int maxiter = defaultmaxiter; int m = defaultm; double factr = defaultfactr; double pgtol = defaultpgtol; // Process the remaining input arguments, which set options for // the IPOPT algorithm. while (k < nrhs) { // Get the option label from the Matlab input argument. MatlabString optionLabel(prhs[k++]); if (k < nrhs) { // Get the option value from the Matlab input argument. MatlabScalar optionValue(prhs[k++]); double value = optionValue; if (!strcmp(optionLabel,"maxiter")) maxiter = (int) value; else if (!strcmp(optionLabel,"m")) m = (int) value; else if (!strcmp(optionLabel,"factr")) factr = value / mxGetEps(); else if (!strcmp(optionLabel,"pgtol")) pgtol = value; else { if (iterFunc) delete iterFunc; throw MatlabException("Nonexistent option"); } } } // Create a new instance of the optimization problem. x = x0; MatlabProgram program(x,lb,ub,&objFunc,&gradFunc,iterFunc, (mxArray*) auxData,m,maxiter,factr,pgtol); // Run the L-BFGS-B solver. SolverExitStatus exitStatus = program.runSolver(); if (exitStatus == abnormalTermination) { if (iterFunc) delete iterFunc; throw MatlabException("Solver unable to satisfy convergence \ criteria due to abnormal termination"); } else if (exitStatus == errorOnInput) {