Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Continuous relaxation meta problem #146

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions PyGMO/problem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,18 @@ def _shifted_ctor(self, problem=None, shift=None):
shifted.__init__ = _shifted_ctor


def _relaxed_ctor(self, problem=None):
# We construct the arg list for the original constructor exposed by
# boost_python
arg_list = []
if problem is None:
problem = ackley(1)
arg_list.append(problem)
self._orig_init(*arg_list)
relaxed._orig_init = relaxed.__init__
relaxed.__init__ = _relaxed_ctor


def _rotated_ctor(self, problem=None, rotation=None):
"""
Rotates a problem. (also reflections are possible)
Expand Down
12 changes: 8 additions & 4 deletions PyGMO/problem/problem_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,24 @@ BOOST_PYTHON_MODULE(_problem_meta) {
.def(init<const problem::base &, double>())
.add_property("shift_vector",make_function(&problem::shifted::get_shift_vector,return_value_policy<copy_const_reference>()))
.def("deshift",&problem::shifted::deshift);


// Relaxed meta-problem
meta_problem_wrapper<problem::relaxed>("relaxed","Relaxed problem")
.def(init<const problem::base &>());

// Scaled meta-problem
meta_problem_wrapper<problem::scaled>("scaled","Scaled problem")
.def(init<const problem::base &, fitness_vector >())
.add_property("units",make_function(&problem::scaled::get_units,return_value_policy<copy_const_reference>()))
.def("descale",&problem::scaled::descale);

// Rotated meta-problem
meta_problem_wrapper<problem::rotated>("rotated","Rotated problem")
.def(init<const problem::base &>())
.def(init<const problem::base &, Eigen::MatrixXd >())
.add_property("rotation_matrix",&get_rotation_matrix_from_eigen)
.def("derotate",&problem::rotated::derotate);

// Normalized meta-problem
meta_problem_wrapper<problem::normalized>("normalized","Normalized problem")
.def(init<const problem::base &>())
Expand All @@ -172,7 +176,7 @@ BOOST_PYTHON_MODULE(_problem_meta) {
// Decomposition meta-problem
meta_problem_wrapper<problem::decompose>("decompose","Decomposed problem")
.def(init<const problem::base &, optional<problem::decompose::method_type, const std::vector<double> &, const std::vector<double> &, const bool> >())
.def("compute_decomposed_fitness", &compute_decomposed_fitness_wrapper,
.def("compute_decomposed_fitness", &compute_decomposed_fitness_wrapper,
"Computes the fitness of the decomposed problem\n\n"
" USAGE:: w = prob.compute_decomposed_fitness(fit,weight)\n"
" - fit: multi-dimensional fitness\n"
Expand Down
5 changes: 3 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ SET(PAGMO_LIB_SRC_LIST
${CMAKE_CURRENT_SOURCE_DIR}/problem/death_penalty.cpp
${CMAKE_CURRENT_SOURCE_DIR}/problem/cstrs_self_adaptive.cpp
${CMAKE_CURRENT_SOURCE_DIR}/problem/antibodies_problem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/problem/shifted.cpp
${CMAKE_CURRENT_SOURCE_DIR}/problem/scaled.cpp
${CMAKE_CURRENT_SOURCE_DIR}/problem/relaxed.cpp
${CMAKE_CURRENT_SOURCE_DIR}/problem/shifted.cpp
${CMAKE_CURRENT_SOURCE_DIR}/problem/scaled.cpp
${CMAKE_CURRENT_SOURCE_DIR}/problem/rotated.cpp
${CMAKE_CURRENT_SOURCE_DIR}/problem/normalized.cpp
${CMAKE_CURRENT_SOURCE_DIR}/problem/decompose.cpp
Expand Down
88 changes: 88 additions & 0 deletions src/problem/relaxed.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*****************************************************************************
* Copyright (C) 2015 The PaGMO development team, *
* Advanced Concepts Team (ACT), European Space Agency (ESA) *
* http://apps.sourceforge.net/mediawiki/pagmo *
* http://apps.sourceforge.net/mediawiki/pagmo/index.php?title=Developers *
* http://apps.sourceforge.net/mediawiki/pagmo/index.php?title=Credits *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
*****************************************************************************/

#include "../exceptions.h"
#include "../types.h"
#include "../population.h"
#include "base.h"
#include "relaxed.h"

namespace pagmo { namespace problem {

/**
* Construct the continuous relaxation of a (mixed-)integer problem
*
* @param[in] p base::problem to be relaxed
*
* @see problem::base constructors.
*/

relaxed::relaxed(const base & p):
base_meta(
p,
p.get_dimension(),
0,
p.get_f_dimension(),
p.get_c_dimension(),
p.get_ic_dimension(),
p.get_c_tol())
{
}

/// Clone method.
base_ptr relaxed::clone() const
{
return base_ptr(new relaxed(*this));
}

/// Implementation of the objective function.
/// (Wraps over the original implementation)
void relaxed::objfun_impl(fitness_vector &f, const decision_vector &x) const
{
m_original_problem->objfun(f, x);
}

/// Implementation of the constraints computation.
/// (Wraps over the original implementation)
void relaxed::compute_constraints_impl(constraint_vector &c, const decision_vector &x) const
{
m_original_problem->compute_constraints(c, x);
}

std::string relaxed::get_name() const
{
return m_original_problem->get_name() + " [Relaxed]";
}

/// Extra human readable info for the problem.
/**
* Will return a formatted string containing the translation vector
*/
std::string relaxed::human_readable_extra() const
{
return m_original_problem->human_readable_extra();
}
}}

BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::relaxed)
74 changes: 74 additions & 0 deletions src/problem/relaxed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*****************************************************************************
* Copyright (C) 2015 The PaGMO development team, *
* Advanced Concepts Team (ACT), European Space Agency (ESA) *
* http://apps.sourceforge.net/mediawiki/pagmo *
* http://apps.sourceforge.net/mediawiki/pagmo/index.php?title=Developers *
* http://apps.sourceforge.net/mediawiki/pagmo/index.php?title=Credits *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
*****************************************************************************/

#ifndef PAGMO_PROBLEM_RELAXED_H
#define PAGMO_PROBLEM_RELAXED_H

#include <string>

#include "../serialization.h"
#include "ackley.h"
#include "../types.h"
#include "base_meta.h"

namespace pagmo{ namespace problem {

/// Relaxed meta-problem
/**
* Implements a meta-problem class that wraps some other problem and acts as
* its continous relaxation. This basically means that the integer part of the
* underlying problem will be treated the same way as if it was continous. See
* http://docs.mosek.com/7.0/capi/The_optimizers_for_mixed-integer_problem.html
* for more details.
*/

class __PAGMO_VISIBLE relaxed : public base_meta
{
public:
//constructor
relaxed(const base & = ackley(1));

base_ptr clone() const;
std::string get_name() const;

protected:
std::string human_readable_extra() const;
void objfun_impl(fitness_vector &, const decision_vector &) const;
void compute_constraints_impl(constraint_vector &, const decision_vector &) const;
private:
void configure_shifted_bounds(const decision_vector &);

friend class boost::serialization::access;
template <class Archive>
void serialize(Archive &ar, const unsigned int)
{
ar & boost::serialization::base_object<base_meta>(*this);
}
};

}} //namespaces

BOOST_CLASS_EXPORT_KEY(pagmo::problem::relaxed)

#endif // PAGMO_PROBLEM_RELAXED_H
1 change: 1 addition & 0 deletions src/problems.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "problem/cstrs_co_evolution.h"
#include "problem/cstrs_self_adaptive.h"
#include "problem/antibodies_problem.h"
#include "problem/relaxed.h"
#include "problem/shifted.h"
#include "problem/scaled.h"
#include "problem/rotated.h"
Expand Down