Skip to content

Instantly share code, notes, and snippets.

@Laetus
Last active February 22, 2016 08:32
Show Gist options
  • Save Laetus/14b4a0f2b9104093f46a to your computer and use it in GitHub Desktop.
Save Laetus/14b4a0f2b9104093f46a to your computer and use it in GitHub Desktop.
Example
Multiple Shooting is done
Multiple Shooting is done
proc wall num mean mean
time time evals proc time wall time
eval_f 0.005 [s] 0.005 [s] 27 0.17 [ms] 0.17 [ms]
eval_grad_f 0.006 [s] 0.006 [s] 28 0.20 [ms] 0.20 [ms]
eval_g 0.006 [s] 0.006 [s] 27 0.22 [ms] 0.22 [ms]
eval_jac_g 0.023 [s] 0.023 [s] 29 0.80 [ms] 0.80 [ms]
eval_h 0.081 [s] 0.081 [s] 27 3.00 [ms] 3.00 [ms]
all previous 0.120 [s] 0.120 [s]
ipopt 0.021 [s] 0.021 [s]
main loop 0.141 [s] 0.141 [s]
proc wall num mean mean
time time evals proc time wall time
eval_f 0.027 [s] 0.027 [s] 27 1.00 [ms] 0.99 [ms]
eval_grad_f 0.029 [s] 0.029 [s] 28 1.04 [ms] 1.04 [ms]
eval_g 0.028 [s] 0.028 [s] 27 1.04 [ms] 1.04 [ms]
eval_jac_g 0.028 [s] 0.028 [s] 29 0.96 [ms] 0.96 [ms]
eval_h 0.067 [s] 0.067 [s] 27 2.50 [ms] 2.50 [ms]
all previous 0.179 [s] 0.179 [s]
ipopt 0.021 [s] 0.021 [s]
main loop 0.200 [s] 0.200 [s]
IpOpt solver took: 0.141438
ACPSCP solver took: 0.200157
Result APCSCP: [109.102, 106.708, 106.707, 111.769, 111.704, 110.733, 110.727, 108.671, 108.668, 105.911, 105.908, 110.125, 93.9454, 74.2309, 74.5366, 83.1493, 83.5524, 82.5985, 82.9253, 80.1743, 80.4472, 76.5374, 76.8387, 89.2, 0, 0, 0, 54.9206, 320, 6.28563e-08, 20, 0, 0, 0, 0, 210, 78.2552, 80, 80, 0, 0, 0, 0, 0, 0, 80, 80, 0, 109.102, 106.708, 106.707, 111.769, 111.704, 110.733, 110.727, 108.671, 108.668, 105.911, 105.908, 110.125, 86.75, 86, 86, 86, 86.75, 87.5, 88.35, 89.2, 89.2, 89.2, 89.2, 89.2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 9.72904e-12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.46607, 2.4206, 2.32317, 2.22666, 2.30556, 3.18111, 3.0967, 3.0733, 2.98781, 2.90315, 2.81503, 2.72782, 3.29504, 1.45369, 1.06916, 0.762118, 0.453704, 0.466532, 0.480921, 0.502978, 0.527389, 0.568005, 0.607392, 0.304374, 0, 0, 0.487493, 0.983928, 1.49018, 1.99643, 1.74375, 0, 0.05625, 0, 0.05625, 0.1125, 0.61875, 1.125, 0]
Result IpOpt: [109.102, 106.708, 106.707, 111.769, 111.704, 110.733, 110.727, 108.671, 108.668, 105.911, 105.908, 110.125, 93.9454, 74.2309, 74.5366, 83.1493, 83.5524, 82.5985, 82.9253, 80.1743, 80.4472, 76.5374, 76.8387, 89.2, 0, 0, 0, 54.9206, 320, 6.28563e-08, 20, 0, 0, 0, 0, 210, 78.2552, 80, 80, 0, 0, 0, 0, 0, 0, 80, 80, 0, 109.102, 106.708, 106.707, 111.769, 111.704, 110.733, 110.727, 108.671, 108.668, 105.911, 105.908, 110.125, 86.75, 86, 86, 86, 86.75, 87.5, 88.35, 89.2, 89.2, 89.2, 89.2, 89.2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 9.72907e-12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.46607, 2.4206, 2.32317, 2.22666, 2.30556, 3.18111, 3.0967, 3.0733, 2.98781, 2.90315, 2.81503, 2.72782, 3.29504, 1.45369, 1.06916, 0.762118, 0.453704, 0.466532, 0.480921, 0.502978, 0.527389, 0.568005, 0.607392, 0.304374, 0, 0, 0.487493, 0.983928, 1.49018, 1.99643, 1.74375, 0, 0.05625, 0, 0.05625, 0.1125, 0.61875, 1.125, 0]
Difference between x and x1: 3.34144e-14
Duration Update dG: 2.0376e-05
Duration Update A: 9.7e-08
Duration Update H: 4.4e-08
Duration Update M: 1.82e-05
elapsed iteration time: 0.402758
elapsed time for MS: 0.00159316
elapsed time to solve: 0.399476
Time: 6
Multiple Shooting is done
Multiple Shooting is done
proc wall num mean mean
time time evals proc time wall time
eval_f 0.004 [s] 0.004 [s] 21 0.17 [ms] 0.17 [ms]
eval_grad_f 0.005 [s] 0.005 [s] 22 0.21 [ms] 0.21 [ms]
eval_g 0.005 [s] 0.005 [s] 21 0.22 [ms] 0.22 [ms]
eval_jac_g 0.018 [s] 0.018 [s] 23 0.77 [ms] 0.77 [ms]
eval_h 0.062 [s] 0.062 [s] 21 2.96 [ms] 2.96 [ms]
all previous 0.093 [s] 0.093 [s]
ipopt 0.015 [s] 0.015 [s]
main loop 0.107 [s] 0.107 [s]
proc wall num mean mean
time time evals proc time wall time
eval_f 0.020 [s] 0.020 [s] 21 0.94 [ms] 0.94 [ms]
eval_grad_f 0.021 [s] 0.021 [s] 22 0.97 [ms] 0.97 [ms]
eval_g 0.021 [s] 0.021 [s] 21 1.00 [ms] 1.00 [ms]
eval_jac_g 0.021 [s] 0.021 [s] 23 0.90 [ms] 0.90 [ms]
eval_h 0.052 [s] 0.052 [s] 21 2.49 [ms] 2.49 [ms]
all previous 0.135 [s] 0.135 [s]
ipopt 0.015 [s] 0.015 [s]
main loop 0.150 [s] 0.150 [s]
IpOpt solver took: 0.107594
ACPSCP solver took: 0.150205
Result APCSCP: [106.708, 106.688, 111.75, 111.685, 110.714, 110.707, 108.651, 108.648, 105.891, 105.888, 110.138, 110.102, 74.2309, 74.5366, 83.1492, 83.5524, 82.5985, 82.9252, 80.1743, 80.4472, 76.5375, 76.8388, 89.0252, 89.3748, 0, 0, 54.9206, 320, 6.28538e-08, 20, 0, 0, 0, 0, 6.98802e-08, 220, 80, 80, 0, 0, 0, 0, 0, 0, 80, 80, 0, 0, 106.708, 106.688, 111.75, 111.685, 110.714, 110.707, 108.651, 108.648, 105.891, 105.888, 110.138, 110.102, 86, 86, 86, 86.75, 87.5, 88.35, 89.2, 89.2, 89.2, 89.2, 89.2, 89.2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9.72904e-12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.4206, 2.32317, 2.22672, 2.30568, 3.18128, 3.09694, 3.07359, 2.98816, 2.90356, 2.8155, 2.72835, 2.66501, 3.26283, 1.06916, 0.762118, 0.453704, 0.466532, 0.480921, 0.502978, 0.52739, 0.568005, 0.607393, 0.304374, 0, 0.00078671, 0, 0.983928, 1.49018, 1.99643, 1.74375, 0, 0.05625, 0, 0.05625, 0.1125, 0.61875, 1.125, 1.18125, 0]
Result IpOpt: [106.708, 106.688, 111.75, 111.685, 110.714, 110.707, 108.651, 108.648, 105.891, 105.888, 110.138, 110.102, 74.2309, 74.5366, 83.1492, 83.5524, 82.5985, 82.9252, 80.1743, 80.4472, 76.5375, 76.8388, 89.0252, 89.3748, 0, 0, 54.9206, 320, 6.28538e-08, 20, 0, 0, 0, 0, 6.98802e-08, 220, 80, 80, 0, 0, 0, 0, 0, 0, 80, 80, 0, 0, 106.708, 106.688, 111.75, 111.685, 110.714, 110.707, 108.651, 108.648, 105.891, 105.888, 110.138, 110.102, 86, 86, 86, 86.75, 87.5, 88.35, 89.2, 89.2, 89.2, 89.2, 89.2, 89.2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9.72904e-12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.4206, 2.32317, 2.22672, 2.30568, 3.18128, 3.09694, 3.07359, 2.98816, 2.90356, 2.8155, 2.72835, 2.66501, 3.26283, 1.06916, 0.762118, 0.453704, 0.466532, 0.480921, 0.502978, 0.52739, 0.568005, 0.607393, 0.304374, 0, 0.00078671, 0, 0.983928, 1.49018, 1.99643, 1.74375, 0, 0.05625, 0, 0.05625, 0.1125, 0.61875, 1.125, 1.18125, 0]
Difference between x and x1: 9.70111e-14
Duration Update dG: 2.2963e-05
Duration Update A: 1.07e-07
Duration Update H: 4.4e-08
Duration Update M: 2.0177e-05
//The whole RealtimeAPCSCP Solver Class extending Solver
#include "RealtimeAPCSCP.hpp"
RealtimeAPCSCP::RealtimeAPCSCP(Model* model) :
RealtimeAPCSCP::Solver(model) {
this->nlp = MXFunction("nlp", nlpIn("x", model->getV()), nlpOut("f",
model->getf(0), "g", G));
this->dG_f = this->nlp.jacobian("x", "g");
this->choiceH = 0;
this->exactA = true;
this->n_updateA = 1;
this->assumedData = std::vector<Matrix<double> >(this->model->getN_F() + 1);
this->firstIteration = true;
this->name = "APCSCPandIpOpt";
this->hess_gi = std::vector<Function>(G.size());
for (int i = 0; i < G.size(); i++) {
hess_gi[i] = MXFunction("constraint_i", nlpIn("x", model->getV()),
nlpOut("g", (MX) G[i])).hessian("x", "g");
}
hess_fi = nlp.hessian("x", "f");
}
void RealtimeAPCSCP::solve() {
//Initialisation (calculate the exact solution for inital point)
int t_act = 0;
std::cout << "Time: " + to_string(t_act) << std::endl;
startIt = std::chrono::system_clock::now();
startSolver = std::chrono::system_clock::now();
//Solve the first problem exactly
std::map<std::string, Matrix<double> > arg = make_map("lbx",
model->getVMIN(), "ubx", model->getVMAX(), "lbg", this->G_bound,
"ubg", this->G_bound, "x0", model->getVINIT());
NlpSolver nlpSolver = NlpSolver("solver", "ipopt", nlp, opts);
nlpSolver.setOption("warn_initial_bounds", true);
nlpSolver.setOption("eval_errors_fatal", true);
model->writeModelToConsole(false);
std::map<string, Matrix<double>> result_tact = nlpSolver(arg);
endSolver = std::chrono::system_clock::now();
// Store data
assumedData[t_act] = result_tact["x"];
//Setup new iteration
model->storeAndShiftValues(result_tact, t_act);
// storeStatsIpopt(&nlpSolver);
//Define values
this->x_act = result_tact["x"];
this->y_act = result_tact["lam_g"];
updateDg_act();
updateA_act(t_act);
updateH_act(t_act);
updateM_act();
m_act = mul(transpose(Dg_act - A_act), y_act);
// firstIteration = false;
opts["warm_start_init_point"] = "yes";
endIt = std::chrono::system_clock::now();
printTimingData(t_act);
//Iteration
for (t_act = 1; t_act < model->getN_F(); t_act++) {
std::cout << "Time: " + to_string(t_act) << std::endl;
startIt = std::chrono::system_clock::now();
startMS = std::chrono::system_clock::now();
G_sub = mul(A_act, model->getV() - x_act) + model->doMultipleShooting<
MX> ((MX) x_act);
// this->G = this->model->doMultipleShooting(model->getV());
endMS = std::chrono::system_clock::now();
f_sub = model->getf(t_act) + mul(transpose(m_act), model->getV()
- x_act) + 0.5 * quad_form(model->getV() - x_act, H_act);
this->nlp_sub = MXFunction("nlp", nlpIn("x", model->getV()), nlpOut(
"f", model->getf(t_act), "g", G_sub));
this->nlp = MXFunction("nlp", nlpIn("x", model->getV()), nlpOut("f",
model->getf(t_act), "g", G));
// Step2 solve convex subproblem
startSolver = std::chrono::system_clock::now();
result_tact = solveConvexSubproblem();
endSolver = std::chrono::system_clock::now();
// Step3 update matrices and retrieve new measurement (step 1)
x_act = result_tact["x"];
y_act = result_tact["lam_g"];
model->storeAndShiftValues(result_tact, t_act);
// update
this->x_act = result_tact["x"];
this->y_act = result_tact["lam_g"];
updateDg_act();
updateA_act(t_act);
updateH_act(t_act);
updateM_act();
endIt = std::chrono::system_clock::now();
printTimingData(t_act);
}
}
std::map<string, Matrix<double> > RealtimeAPCSCP::solveConvexSubproblem() {
std::chrono::time_point<std::chrono::system_clock> sta, end;
std::chrono::duration<double> duration, duration2;
sta = std::chrono::system_clock::now();
std::map<std::string, Matrix<double> > arg = make_map("lbx",
model->getVMIN(), "ubx", model->getVMAX(), "lbg", this->G_bound,
"ubg", this->G_bound, "x0", model->getVINIT());
if (!firstIteration) {
arg.insert(std::pair<std::string, Matrix<double> >("lam_g0",
model->getLAM_G()));
arg.insert(std::pair<std::string, Matrix<double> >("lam_x0",
model->getLAM_X()));
}
NlpSolver nlpSolver0 = NlpSolver("solver", "ipopt", nlp_sub, opts);
NlpSolver nlpSolver = NlpSolver("solver", "ipopt", nlp_sub, opts);
NlpSolver nlpSolver2 = NlpSolver("solver", "ipopt", nlp, opts);
end = std::chrono::system_clock::now();
// std::map<string, Matrix<double> > result0 = nlpSolver0(arg);
sta = std::chrono::system_clock::now();
std::map<string, Matrix<double> > result2 = nlpSolver2(arg);
end = std::chrono::system_clock::now();
duration2 = end - sta;
sta = std::chrono::system_clock::now();
std::map<string, Matrix<double> > result = nlpSolver(arg);
end = std::chrono::system_clock::now();
duration = end - sta;
storeStatsIpopt(&nlpSolver);
storeStatsIpopt(&nlpSolver2);
Matrix<double> x = result["x"];
Matrix<double> x1 = result2["x"];
Matrix<double> res = norm_2(x - x1);
std::cout << "IpOpt solver took: " << duration2.count() << std::endl;
std::cout << "ACPSCP solver took: " << duration.count() << std::endl;
x.print(std::cout << "Result APCSCP: ");
x1.print(std::cout << "Result IpOpt: ");
res.print(std::cout << "Difference between x and x1: ");
return result;
}
void RealtimeAPCSCP::updateH_act(int t_act) {
std::chrono::time_point<std::chrono::system_clock> start, end;
std::chrono::duration<double> duration;
start = std::chrono::system_clock::now();
switch (choiceH) {
case 0:
if (t_act == 0) {
H_act = MX::zeros(x_act.size(), x_act.size());
}
break;
case 1:
H_act = calcCheapLagrangian();
break;
case 2:
H_act = calcApproxLagrangian();
break;
case 3:
H_act = calcExactLagrangian();
break;
default:
if (t_act == 0) {
H_act = MX::zeros(x_act.size(), x_act.size());
}
}
end = std::chrono::system_clock::now();
duration = end - start;
std::cout << "Duration Update H: " << duration.count() << std::endl;
}
void RealtimeAPCSCP::updateA_act(int t_act) {
std::chrono::time_point<std::chrono::system_clock> start, end;
std::chrono::duration<double> duration;
start = std::chrono::system_clock::now();
if (exactA) {
A_act = Dg_act;
} else {
if (t_act % n_updateA == 0) {
A_act = Dg_act;
}
}
end = std::chrono::system_clock::now();
duration = end - start;
std::cout << "Duration Update A: " << duration.count() << std::endl;
}
void RealtimeAPCSCP::updateDg_act() {
std::chrono::time_point<std::chrono::system_clock> start, end;
std::chrono::duration<double> duration;
start = std::chrono::system_clock::now();
std::map<std::string, MX> result = dG_f(make_map("x", (MX) x_act));
this->Dg_act = result["jac"];
end = std::chrono::system_clock::now();
duration = end - start;
std::cout << "Duration Update dG: " << duration.count() << std::endl;
}
void RealtimeAPCSCP::updateM_act() {
std::chrono::time_point<std::chrono::system_clock> start, end;
std::chrono::duration<double> duration;
start = std::chrono::system_clock::now();
m_act = mul(transpose(Dg_act - A_act), y_act);
end = std::chrono::system_clock::now();
duration = end - start;
std::cout << "Duration Update M: " << duration.count() << std::endl;
}
void RealtimeAPCSCP::setExactA(bool isExact) {
this->exactA = isExact;
}
void RealtimeAPCSCP::setChoiceH(int option) {
this->choiceH = option;
}
void RealtimeAPCSCP::setNupdateA(int n_updateA) {
this->n_updateA = n_updateA;
this->setExactA(false);
}
MX RealtimeAPCSCP::calcExactLagrangian() {
// std::chrono::time_point<std::chrono::system_clock> start, end, startf, endf;
// std::chrono::duration<double> duration;
std::map<std::string, MX> eval;
std::vector<std::map<std::string, MX> > evec(G.size());
std::map<std::string, MX> map = make_map("x", (MX) x_act);
MX result;
// start = std::chrono::system_clock::now();
eval = hess_fi(map);
result = eval["jac"];
// MX bla = result; //TODO: remove
// end = std::chrono::system_clock::now();
// duration = end - start;
// std::cout << "Duration of hessian evaluation: " << duration.count()
// << std::endl;
// start = std::chrono::system_clock::now();
// Function ddF_f = this->nlp.hessian("x", "f");
// eval = ddF_f(map);
// result = eval["jac"];
// end = std::chrono::system_clock::now();
// duration = end - start;
// std::cout << "Duration of new hessian calculation: " << duration.count()
// << std::endl;
// startf = std::chrono::system_clock::now();
for (int i = 0; i < G.size(); i++) {
eval = this->hess_gi[i](map);
result += y_act[i] * (eval)["jac"];
}
// endf = std::chrono::system_clock::now();
// duration = endf - startf;
// std::cout << "Duration of for Loop: " << duration.count()
// << std::endl;
return result;
}
MX RealtimeAPCSCP::calcApproxLagrangian() {
std::map<std::string, MX> eval;
std::map<std::string, MX> map = make_map("x", (MX) x_act);
MX result = MX::zeros(x_act.size(), x_act.size());
for (int i = 0; i < G.size(); i++) {
eval = this->hess_gi[i](map);
result += y_act[i] * eval["jac"];
}
return result;
}
MX RealtimeAPCSCP::calcCheapLagrangian() {
std::map<std::string, MX> eval;
std::map<std::string, MX> map = make_map("x", (MX) x_act);
MX result = MX::zeros(x_act.size(), x_act.size());
for (int i = 0; i < G.size(); i++) {
if (y_act.getValue(i) > 1e-3) {
eval = this->hess_gi[i](map);
result += y_act[i] * eval["jac"];
}
}
return result;
}
//The implementation of Solver
#include "Solver.hpp"
Solver::Solver(Model* model) {
this->model = model;
startMS = std::chrono::system_clock::now();
this->G = this->model->doMultipleShooting(model->getV());
endMS = std::chrono::system_clock::now();
this->G_bound = Matrix<double>::zeros((int) G.size());
this->model->calculateV();
this->stats = new list<Dict> ();
this->timing = Matrix<double>::zeros(3, model->getN_F());
opts["max_iter"] = 1000;
// opts["derivative_test"] = "second-order";
// opts["derivative_test_print_all"] = "yes";
opts["print_timing_statistics"] = "no";
opts["print_level"] = 0;
// opts["output_file"] = "secondStep.txt";
// opts["file_print_level"] = 5;
// std::vector<std::string> bla;
// bla= {"eval_f", "eval_g","eval_grad_f", "eval_h" ,"eval_jac_g", "inputs", "outputs"};
}
void Solver::storeStatsIpopt(NlpSolver* nlpSolver) {
this->stats->push_back(nlpSolver->getStats());
}
void Solver::writeResultToFile() {
std::string filename = this->name + "_" + model->getName();
std::ofstream filestream;
filestream.open("data/result_" + filename + ".m");
model->writeResultToFile(&filestream);
Dict dict1 = this->stats->front();
for (Dict::iterator it = dict1.begin(); it != dict1.end(); it++) {
filestream << this->name + "_" + it->first << " = [";
std::list<Dict>::iterator lit = this->stats->begin();
while (lit != this->stats->end()) {
filestream << lit->at(it->first);
if (++lit != this->stats->end()) {
filestream << ", ";
}
}
filestream << "];" << std::endl;
}
Matrix<double> sec_pIT = timing[Slice(0,timing.size(), 3)];
Matrix<double> sec_pSv = timing[Slice(1,timing.size(), 3)];
Matrix<double> sec_pMS = timing[Slice(2,timing.size(), 3)];
sec_pIT.print(filestream << this->name + "_timing_sec_p_Solve = ", false);
filestream << ";" << std::endl;
sec_pSv.print(filestream << this->name + "_timing_sec_p_It = ", false);
filestream << ";" << std::endl;
sec_pMS.print(filestream << this->name + "_timing_sec_p_MS = ", false);
filestream << ";" ;
filestream.close();
}
void Solver::setName(std::string name) {
this->name = name;
}
void Solver::printTimingData(int t_act) {
sec_p_It = endIt - startIt;
sec_p_Solve = endSolver - startSolver;
sec_p_MS = endMS - startMS;
std::cout << "elapsed iteration time: " << sec_p_It.count() << std::endl;
std::cout << "elapsed time for MS: " << sec_p_MS.count() << std::endl;
std::cout << "elapsed time to solve: " << sec_p_Solve.count() << std::endl;
startIt = std::chrono::system_clock::now();
startSolver = startIt;
timing[3 * t_act] = sec_p_It.count();
timing[3 * t_act + 1] = sec_p_Solve.count();
timing[3 * t_act + 2 ] = sec_p_MS.count();
}
//In every timestep we haveto solve the following problems
// G_sub is an approximation to G
G_sub = mul(A_act, model->getV() - x_act) + model->doMultipleShooting< MX> ((MX) x_act);
this->G = this->model->doMultipleShooting(model->getV());
// This is the general formula, but the parameters can be chosen s.t. m_act = 0 and H_act = 0 -> f_sub = model->getf(t_act)
f_sub = model->getf(t_act) + mul(transpose(m_act), model->getV()
- x_act) + 0.5 * quad_form(model->getV() - x_act, H_act);
this->nlp_sub = MXFunction("nlp", nlpIn("x", model->getV()), nlpOut(
"f", model->getf(t_act), "g", G_sub));
this->nlp = MXFunction("nlp", nlpIn("x", model->getV()), nlpOut("f",
model->getf(t_act), "g", G));
// Both problems are solved in this method
std::map<string, Matrix<double> > RealtimeAPCSCP::solveConvexSubproblem() {
std::map<std::string, Matrix<double> > arg = make_map("lbx",
model->getVMIN(), "ubx", model->getVMAX(), "lbg", this->G_bound,
"ubg", this->G_bound, "x0", model->getVINIT());
NlpSolver nlpSolver0 = NlpSolver("solver", "ipopt", nlp_sub, opts);
NlpSolver nlpSolver = NlpSolver("solver", "ipopt", nlp_sub, opts);
NlpSolver nlpSolver2 = NlpSolver("solver", "ipopt", nlp, opts);
std::map<string, Matrix<double> > result2 = nlpSolver2(arg);
std::map<string, Matrix<double> > result = nlpSolver(arg);
// Analysis, preparation of next step etc..
storeStatsIpopt(&nlpSolver);
storeStatsIpopt(&nlpSolver2);
Matrix<double> x = result["x"];
Matrix<double> x1 = result2["x"];
Matrix<double> res = norm_2(x - x1);
std::cout << "IpOpt solver took: " << duration2.count() << std::endl;
std::cout << "ACPSCP solver took: " << duration.count() << std::endl;
x.print(std::cout << "Result APCSCP: ");
x1.print(std::cout << "Result IpOpt: ");
res.print(std::cout << "Difference between x and x1: ");
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment