Skip to content

Commit

Permalink
Merge pull request #983.
Browse files Browse the repository at this point in the history
Exception and minor C-to-C++ transition.
  • Loading branch information
lballabio committed Jan 21, 2021
2 parents 532596a + e0cb127 commit 97a3c7e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ql/math/optimization/simplex.cpp
Expand Up @@ -102,20 +102,24 @@ namespace QuantLib {
= endCriteria.maxStationaryStateIterations();
EndCriteria::Type ecType = EndCriteria::None;
P.reset();

Array x_ = P.currentValue();
if (!P.constraint().test(x_))
QL_FAIL("Initial guess " << x_ << " is not in the feasible region.");

Integer iterationNumber_=0;

// Initialize vertices of the simplex
Size n = x_.size(), i;
Size n = x_.size();
vertices_ = std::vector<Array>(n+1, x_);
for (i=0; i<n; i++) {
for (Size i=0; i<n; ++i) {
Array direction(n, 0.0);
direction[i] = 1.0;
P.constraint().update(vertices_[i+1], direction, lambda_);
}
// Initialize function values at the vertices of the simplex
values_ = Array(n+1, 0.0);
for (i=0; i<=n; i++)
for (Size i=0; i<=n; ++i)
values_[i] = P.value(vertices_[i]);
// Loop looking for minimum
do {
Expand Down

0 comments on commit 97a3c7e

Please sign in to comment.