Skip to content

Commit

Permalink
Implemented the virtual IsFinished method
Browse files Browse the repository at this point in the history
  • Loading branch information
einar90 committed Nov 18, 2016
1 parent e56193e commit 408fef3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
17 changes: 12 additions & 5 deletions FieldOpt/Optimization/optimizers/GSS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ namespace Optimization {
Model::Properties::VariablePropertyContainer *variables, Reservoir::Grid::Grid *grid)
: Optimizer(settings, base_case, variables, grid) {
step_tol_ = settings->parameters().minimum_step_length;
// \TODO Contr fac -> Set in subclass
// \TODO Expan fac -> Set in subclass
// \TODO Directions -> Set in subclass
// \TODO Step length -> Resize to directions size, set all to initial step length

assert(step_lengths_.size() == directions_.size());
}

Optimizer::TerminationCondition GSS::IsFinished()
{
if (case_handler_->EvaluatedCases().size() >= max_evaluations_)
return MAX_EVALS_REACHED;
else if (is_converged())
return MINIMUM_STEP_LENGTH_REACHED;
else return NOT_FINISHED; // The value of not finished is 0, which evaluates to false.
}

void GSS::expand(vector<int> dirs) {
Expand Down Expand Up @@ -76,7 +83,7 @@ namespace Optimization {

template<typename T>
Matrix<T, Dynamic, 1> GSS::perturb(Matrix<T, Dynamic, 1> base, int dir) {
Matrix<T, Dynamic, 1> perturbation = base + directions_[dir].cast<T>() * step_lengths_[dir];
Matrix<T, Dynamic, 1> perturbation = base + directions_[dir].cast<T>() * step_lengths_(dir);
return perturbation;
}

Expand Down
9 changes: 9 additions & 0 deletions FieldOpt/Optimization/optimizers/GSS.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ namespace Optimization {
GSS(Settings::Optimizer *settings, Case *base_case, Model::Properties::VariablePropertyContainer *variables,
Reservoir::Grid::Grid *grid);

/*!
* \brief IsFinished Check if the optimization is finished.
*
* This algorithm has two termination conditions: max number of objective function evaluations and
* minimum step length.
* \return True if the algorithm has finished, otherwise false.
*/
TerminationCondition IsFinished();

protected:
double step_tol_; //!< Step length convergence tolerance.
double contr_fac_; //!< Step length contraction factor.
Expand Down

0 comments on commit 408fef3

Please sign in to comment.