本文整理汇总了C++中options::ER方法的典型用法代码示例。如果您正苦于以下问题:C++ options::ER方法的具体用法?C++ options::ER怎么用?C++ options::ER使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类options
的用法示例。
在下文中一共展示了options::ER方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HDDP
void HDDP(options & probdata, options & nominal, int & go_to_step, int & current_iter, bool & converged){
double rho;
cout << "Iteration " << current_iter << ": ";
switch (go_to_step){
// Step 1: Computation of First and Second Order STMs
case 1:
cout << "Step 1: Computation of First and Second Order STMS \n";
ComputeSTMs(nominal);
go_to_step = 2;
break;
// Step 2: Backward Sweep
case 2:
cout << "Step 2: Backward Sweep \n";
BackwardSweep(nominal);
go_to_step = 3;
break;
// Step 3: Convergence Check
case 3:
cout << "Step 3: Convergence Check \n";
if ((abs(nominal.ER(0, 0)) < nominal.tol && (nominal.f < nominal.tol) && (nominal.delta <= nominal.delta_min + 1e-6)) || (nominal.delta <= nominal.delta_min + 1e-6)){
cout << "I think we're done here \n";
//cout << "Feasible Solution Within Tolerance \n";
converged = 1;
break;
}
cout << nominal.ER(0, 0) << " " << nominal.J << " " << nominal.h << " " << nominal.f << " " << nominal.delta << "\n";
cout << probdata.ER(0, 0) << " " << probdata.J << " " << probdata.h << " " << probdata.f << " " << probdata.delta << "\n";
go_to_step = 4;
break;
// Step 4: Forward Pass
case 4:
current_iter++;
probdata = nominal;
cout << "Step 4: Forward Pass \n";
ForwardPass(probdata, nominal);
go_to_step = 5;
break;
// Step 5: Trust Region Update
case 5:
cout << "Step 5: Trust Region Update \n";
eval_J(probdata);
rho = (probdata.J - nominal.J) / probdata.ER(0, 0);
if (current_iter < 0){
cout << "Accepted rho = " << rho << "\n";
go_to_step = 6;
break;
} //(.8 < rho && rho < 1.2){
else if (probdata.J < nominal.J){
cout << "Accepted rho = " << rho << "\n";
go_to_step = 6;
break;
} // second chance
else {
nominal.delta = max(nominal.delta*(1. - nominal.kappa), nominal.delta_min);
cout << "Rejected rho = " << rho << "\n";
go_to_step = 2;
break;
}
// Step 6: Nominal Solution Update
case 6:
cout << "Step 6: Nominal Solution Update \n";
rho = (probdata.J - nominal.J) / probdata.ER(0, 0);
probdata.Multipliers += nominal.delta_l;
/**/
// Update rule from Niu
if (probdata.psi.norm() >= nominal.psi.norm()/1.2){
probdata.s = max(1.2*probdata.s, 1.2*probdata.Multipliers.norm());
}
else {
probdata.s = max(probdata.s, 1.2*probdata.Multipliers.norm());
}
eval_J(probdata);
nominal = probdata;
if (.8 < rho && rho < 1.2){
nominal.delta = min(probdata.delta*pow((1. + probdata.kappa),2.0), probdata.delta_max);
go_to_step = 1; // 2 to re-use STM
}
else if (rho > 0){
nominal.delta = min(probdata.delta*pow((1. + probdata.kappa), 1.0), probdata.delta_max);
go_to_step = 1;
}
else {
nominal.delta = max(nominal.delta*(1. - nominal.kappa), nominal.delta_min);
go_to_step = 1;
//.........这里部分代码省略.........