Skip to content

Commit

Permalink
Merge pull request #575 from jschueller/ubf
Browse files Browse the repository at this point in the history
unconstrain: Fix batch fitness
  • Loading branch information
bluescarni committed Jul 29, 2024
2 parents 3ef36a1 + 92feec6 commit a78aac1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/problems/unconstrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,14 @@ vector_double unconstrain::batch_fitness(const vector_double &xs) const
vector_double original_fitness(m_problem.batch_fitness(xs));
const vector_double::size_type nx = m_problem.get_nx();
const vector_double::size_type n_dvs = xs.size() / nx;
vector_double::size_type nobj = m_problem.get_nobj();
const vector_double::size_type nobj = m_problem.get_nobj();
const vector_double::size_type nf = m_problem.get_nf();
vector_double retval;
retval.resize(safe<vector_double::size_type>(n_dvs) * nobj);
vector_double y(nobj);
vector_double y(nf);
vector_double z; // will be resized in penalize if necessary.
for (vector_double::size_type i = 0; i < n_dvs; ++i) {
std::copy(original_fitness.data() + i * nobj, original_fitness.data() + (i + 1) * nobj, y.data());
std::copy(original_fitness.data() + i * nf, original_fitness.data() + (i + 1) * nf, y.data());
penalize(y, z);
std::copy(z.data(), z.data() + nobj, retval.data() + i * nobj);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/unconstrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,11 @@ BOOST_AUTO_TEST_CASE(unconstrain_batch_test)
bfe default_bfe{};
population pop{p0, default_bfe, 20u};
BOOST_CHECK(bf0::s_counter == 1u);

// through batch_fitness
vector_double::size_type bs = 10;
vector_double xs(p0.get_nx() * bs, 1.);
vector_double ys = t.batch_fitness(xs);
BOOST_CHECK(ys.size() == t.get_nobj() * bs);
BOOST_CHECK(bf0::s_counter == 2u);
}

0 comments on commit a78aac1

Please sign in to comment.