44 #ifndef ROL_PROGRESSIVEHEDGING_H 45 #define ROL_PROGRESSIVEHEDGING_H 90 const Ptr<OptimizationProblem<Real>>
input_;
113 std::vector<Ptr<Vector<Real>>>
wvec_;
117 for (
int j = 0; j <
sampler_->numMySamples(); ++j) {
119 if (
input_->getConstraint() != nullPtr) {
134 ParameterList &parlist)
137 usePresolve_ = parlist.sublist(
"SOL").sublist(
"Progressive Hedging").get(
"Use Presolve",
true);
138 useInexact_ = parlist.sublist(
"SOL").sublist(
"Progressive Hedging").get(
"Use Inexact Solve",
true);
139 penaltyParam_ = parlist.sublist(
"SOL").sublist(
"Progressive Hedging").get(
"Initial Penalty Parameter",10.0);
140 maxPen_ = parlist.sublist(
"SOL").sublist(
"Progressive Hedging").get(
"Maximum Penalty Parameter",-1.0);
141 update_ = parlist.sublist(
"SOL").sublist(
"Progressive Hedging").get(
"Penalty Update Scale",10.0);
142 freq_ = parlist.sublist(
"SOL").sublist(
"Progressive Hedging").get(
"Penalty Update Frequency",0);
143 ztol_ = parlist.sublist(
"SOL").sublist(
"Progressive Hedging").get(
"Nonanticipativity Constraint Tolerance",1e-4);
144 maxit_ = parlist.sublist(
"SOL").sublist(
"Progressive Hedging").get(
"Iteration Limit",100);
145 print_ = parlist.sublist(
"SOL").sublist(
"Progressive Hedging").get(
"Print Subproblem Solve History",
false);
146 maxPen_ = (maxPen_ <= static_cast<Real>(0) ? ROL_INF<Real>() :
maxPen_);
149 ParameterList olist; olist.sublist(
"SOL") = parlist.sublist(
"SOL").sublist(
"Objective");
150 std::string type = olist.sublist(
"SOL").get(
"Type",
"Risk Neutral");
151 std::string prob = olist.sublist(
"SOL").sublist(
"Probability").get(
"Name",
"bPOE");
152 hasStat_ = ((type==
"Risk Averse") ||
153 (type==
"Deviation") ||
154 (type==
"Probability" && prob==
"bPOE"));
155 Ptr<ParameterList> parlistptr = makePtrFromRef<ParameterList>(olist);
157 ph_vector_ = makePtr<RiskVector<Real>>(parlistptr,
158 input_->getSolutionVector());
170 ph_bound_ = makePtr<RiskBoundConstraint<Real>>(parlistptr,
171 input_->getBoundConstraint());
178 if (
input_->getConstraint() != nullPtr) {
191 input_->getMultiplierVector());
194 if (
ph_problem_->getBoundConstraint() != nullPtr) {
195 if (
ph_problem_->getBoundConstraint()->isActivated()) {
207 ph_status_ = makePtr<PH_StatusTest<Real>>(parlist,
219 for (
int i = 0; i <
sampler_->numMySamples(); ++i) {
227 void check(std::ostream &outStream = std::cout,
const int numSamples = 1) {
228 int nsamp = std::min(
sampler_->numMySamples(),numSamples);
229 for (
int i = 0; i < nsamp; ++i) {
239 void run(std::ostream &outStream = std::cout) {
241 std::vector<Real> vec_p(2), vec_g(2);
242 Real znorm(ROL_INF<Real>()), zdotz(0);
243 int iter(0), tspiter(0), flag = 1;
244 bool converged =
true;
246 outStream << std::scientific << std::setprecision(6);
247 outStream << std::endl <<
"Progressive Hedging" 249 << std::setw(8) << std::left <<
"iter" 250 << std::setw(15) << std::left <<
"||z-Ez||" 251 << std::setw(15) << std::left <<
"penalty" 252 << std::setw(10) << std::left <<
"subiter" 253 << std::setw(8) << std::left <<
"success" 255 for (iter = 0; iter <
maxit_; ++iter) {
259 for (
int j = 0; j <
sampler_->numMySamples(); ++j) {
275 vec_p[0] +=
sampler_->getMyWeight(j)
278 vec_p[1] +=
static_cast<Real
>(
ph_solver_->getAlgorithmState()->iter);
282 ? converged :
false);
288 sampler_->sumAll(&vec_p[0],&vec_g[0],2);
290 for (
int j = 0; j <
sampler_->numMySamples(); ++j) {
294 znorm = std::sqrt(std::abs(vec_g[0] - zdotz));
295 tspiter +=
static_cast<int>(vec_g[1]);
298 << std::setw(8) << std::left << iter
299 << std::setw(15) << std::left << znorm
301 << std::setw(10) << std::left << static_cast<int>(vec_g[1])
302 << std::setw(8) << std::left << converged
305 if (znorm <=
ztol_ && converged) {
307 outStream <<
"Converged: Nonanticipativity constraint tolerance satisfied!" << std::endl;
324 if (iter >=
maxit_ && flag != 0) {
325 outStream <<
"Maximum number of iterations exceeded" << std::endl;
327 outStream <<
"Total number of subproblem iterations per sample: " 328 << tspiter <<
" / " <<
sampler_->numGlobalSamples()
329 <<
" ~ " <<
static_cast<int>(std::ceil(static_cast<Real>(tspiter)/static_cast<Real>(
sampler_->numGlobalSamples())))
ProgressiveHedging(const Ptr< OptimizationProblem< Real >> &input, const Ptr< SampleGenerator< Real >> &sampler, ParameterList &parlist)
Ptr< BoundConstraint< Real > > ph_bound_
Ptr< Vector< Real > > ph_vector_
Ptr< Solver< Real > > ph_solver_
Ptr< Vector< Real > > z_psum_
Provides the interface to solve a stochastic program using progressive hedging.
void check(std::ostream &outStream=std::cout, const int numSamples=1)
Ptr< OptimizationProblem< Real > > ph_problem_
Ptr< Constraint< Real > > ph_constraint_
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Ptr< PH_StatusTest< Real > > ph_status_
const Ptr< SampleGenerator< Real > > sampler_
void reset(const bool resetAlgo=true)
Reset both Algorithm and Step.
Ptr< Problem< Real > > ph_problem_new_
std::vector< Ptr< Vector< Real > > > wvec_
Provides a simplified interface for solving a wide range of optimization problems.
Ptr< Vector< Real > > z_gsum_
int solve(const ROL::Ptr< StatusTest< Real > > &status=ROL::nullPtr, const bool combineStatus=true)
Solve optimization problem with no iteration output.
const Ptr< OptimizationProblem< Real > > input_
void run(std::ostream &outStream=std::cout)
Ptr< PH_Objective< Real > > ph_objective_