Skip to content

Commit

Permalink
update to operon rev. 4c3e1ee
Browse files Browse the repository at this point in the history
  • Loading branch information
foolnotion committed Apr 4, 2024
1 parent 5a41ebc commit dd38d8f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion script/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ rm -rf mdspan
## operon
git clone https://github.com/heal-research/operon.git
pushd operon
git checkout 59ea4c147baad463406ed9f315a9031b4eb130b1
git checkout 4c3e1eea119d118406dd80389884253815721bc8
mkdir build
cmake -S . -B build --preset build-${PLATFORM} \
-DCMAKE_BUILD_TYPE=Release \
Expand Down
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from skbuild import setup # This line replaces 'from setuptools import setup'
import platform

build_preset = ''
if platform.system() == 'Linux':
build_preset = 'build-linux'
elif platform.system() == 'Darwin':
build_preset = 'build-osx'

setup(
name="pyoperon",
Expand All @@ -7,4 +14,5 @@
author='Bogdan Burlacu',
packages=['pyoperon'],
python_requires=">=3.8",
cmake_args=[f'--preset {build_preset}' if build_preset != '' else '']
)
15 changes: 9 additions & 6 deletions source/algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@

void InitAlgorithm(py::module_ &m)
{
py::class_<Operon::GeneticProgrammingAlgorithm>(m, "GeneticProgrammingAlgorithm")
py::class_<Operon::GeneticAlgorithmBase>(m, "GeneticAlgorithmBase")
.def_property_readonly("Generation", static_cast<size_t (Operon::GeneticAlgorithmBase::*)() const>(&Operon::GeneticAlgorithmBase::Generation))
.def_property_readonly("Individuals", static_cast<std::vector<Operon::Individual> const& (Operon::GeneticAlgorithmBase::*)() const>(&Operon::GeneticAlgorithmBase::Individuals))
.def_property_readonly("Parents", static_cast<std::span<Operon::Individual const> (Operon::GeneticAlgorithmBase::*)() const>(&Operon::GeneticAlgorithmBase::Parents))
.def_property_readonly("Parents", static_cast<std::span<Operon::Individual const> (Operon::GeneticAlgorithmBase::*)() const>(&Operon::GeneticAlgorithmBase::Offspring))
;

py::class_<Operon::GeneticProgrammingAlgorithm, Operon::GeneticAlgorithmBase>(m, "GeneticProgrammingAlgorithm")
.def(py::init<Operon::Problem const&, Operon::GeneticAlgorithmConfig const&, Operon::TreeInitializerBase const&,
Operon::CoefficientInitializerBase const&, Operon::OffspringGeneratorBase const&, Operon::ReinserterBase const&>())
.def("Run", py::overload_cast<Operon::RandomGenerator&, std::function<void()>, size_t>(&Operon::GeneticProgrammingAlgorithm::Run),
Expand All @@ -22,11 +29,9 @@ void InitAlgorithm(py::module_ &m)
auto minElem = std::min_element(self.Parents().begin(), self.Parents().end(), [&](auto const& a, auto const& b) { return a[0] < b[0]; });
return *minElem;
})
.def_property_readonly("Generation", &Operon::GeneticProgrammingAlgorithm::Generation)
.def_property_readonly("Individuals", &Operon::GeneticProgrammingAlgorithm::Individuals)
.def_property_readonly("Config", &Operon::GeneticProgrammingAlgorithm::GetConfig);

py::class_<Operon::NSGA2>(m, "NSGA2Algorithm")
py::class_<Operon::NSGA2, Operon::GeneticAlgorithmBase>(m, "NSGA2Algorithm")
.def(py::init<Operon::Problem const&, Operon::GeneticAlgorithmConfig const&, Operon::TreeInitializerBase const&, Operon::CoefficientInitializerBase const&,
Operon::OffspringGeneratorBase const&, Operon::ReinserterBase const&, Operon::NondominatedSorterBase const&>())
.def("Run", py::overload_cast<Operon::RandomGenerator&, std::function<void()>, size_t>(&Operon::NSGA2::Run),
Expand All @@ -36,8 +41,6 @@ void InitAlgorithm(py::module_ &m)
auto minElem = std::min_element(self.Best().begin(), self.Best().end(), [&](auto const& a, auto const& b) { return a[0] < b[0];});
return *minElem;
})
.def_property_readonly("Generation", &Operon::NSGA2::Generation)
.def_property_readonly("Individuals", &Operon::NSGA2::Individuals)
.def_property_readonly("BestFront", [](Operon::NSGA2 const& self) {
auto best = self.Best();
return std::vector<Operon::Individual>(best.begin(), best.end());
Expand Down
5 changes: 4 additions & 1 deletion source/evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,8 @@ void InitEval(py::module_ &m)

py::class_<TPoissonEvaluator, TEvaluator>(m, "PoissonLikelihoodEvaluator")
.def(py::init<Operon::Problem&, TDispatch const&>())
.def_property("Sigma", &TPoissonEvaluator::Sigma , &TPoissonEvaluator::SetSigma /*set*/);
.def_property("Sigma", [](TPoissonEvaluator const& self) {
auto sigma = self.Sigma();
return std::vector<Operon::Scalar>(sigma.begin(), sigma.end());
}, &TPoissonEvaluator::SetSigma /*set*/);
}

0 comments on commit dd38d8f

Please sign in to comment.