Skip to content

Commit

Permalink
Merge pull request #164 from bluescarni/pr/small_bits
Browse files Browse the repository at this point in the history
Small CI/build system bits.
  • Loading branch information
bluescarni authored Apr 11, 2018
2 parents ccea967 + 2ebd849 commit 1ff0631
Show file tree
Hide file tree
Showing 20 changed files with 200 additions and 173 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ matrix:
script:
- mkdir build
- cd build
- bash ../tools/install_deps.sh
- bash ../tools/install_travis.sh
# NOTE: currently, travis does not stop automatically if one of these
# 2 scripts returns an error code. Thus, we run them together as a single
# command, so that if install_deps.sh fails the whole build fails immediately
# rather than executing install_travis.sh as well. See
# https://github.com/travis-ci/travis-ci/issues/1066
- ../tools/install_deps.sh && ../tools/install_travis.sh

notifications:
email: false
Expand Down
5 changes: 0 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ install:
- if [%BUILD_TYPE%]==[MSVC_64_Debug] conda clean --all -y
- if [%BUILD_TYPE%]==[MSVC_64_Debug] conda update conda -y
- if [%BUILD_TYPE%]==[MSVC_64_Debug] conda update --all -y
# NOTE: here we are pinning the boost and boost-cpp packages versions to the current
# pinned conda-forge versions, which can be found out at:
# https://github.com/conda-forge/conda-forge.github.io/blob/master/scripts/pin_the_slow_way.py
# This ensures that we build with the same boost version we use to build the conda packages.
# NOTE: these version numbers need to be updated manually.
- if [%BUILD_TYPE%]==[MSVC_64_Debug] conda create -y --name pagmo python=3.6 cmake boost boost-cpp eigen nlopt
# NOTE: need to use "call" because otherwise it won't work within an if block.
- if [%BUILD_TYPE%]==[MSVC_64_Debug] call activate pagmo
Expand Down
2 changes: 1 addition & 1 deletion cmake_modules/yacma/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2017 Francesco Biscani
Copyright (c) 2016-2018 Francesco Biscani

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 12 additions & 10 deletions cmake_modules/yacma/YACMACompilerLinkerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function(_YACMA_REPORT_FLAGS)
message(STATUS "YACMA autodetected C++ debug flags: ${YACMA_CXX_FLAGS_DEBUG}")
endfunction()

# Enable conditionally a CXX flags, if supported by the compiler.
# Enable conditionally a CXX flag, if supported by the compiler.
# This is for flags intended to be enabled in all configurations.
# NOTE: we use macros and go through temporary private variables
# because it's apparently impossible to append to an internal
Expand All @@ -60,7 +60,7 @@ macro(_YACMA_CHECK_ENABLE_CXX_FLAG flag)
unset(YACMA_CHECK_CXX_FLAG CACHE)
endmacro()

# Enable conditionally a debug CXX flags, is supported by the compiler.
# Enable conditionally a debug CXX flag, is supported by the compiler.
# This is for flags intended to be enabled in debug mode.
macro(_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG flag)
set(CMAKE_REQUIRED_QUIET TRUE)
Expand All @@ -82,16 +82,13 @@ if(NOT _YACMACompilerLinkerSettingsRun)
set(_YACMA_CXX_FLAGS "")
set(_YACMA_CXX_FLAGS_DEBUG "")

# NOTE: all these flags are with a Unix-like syntax. We will need to change them
# for MSVC and clang on windows possibly.

# Configuration bits specific for GCC.
if(YACMA_COMPILER_IS_GNUCXX)
_YACMA_CHECK_ENABLE_CXX_FLAG(-fdiagnostics-color=auto)
endif()

# Configuration bits specific for clang.
if(YACMA_COMPILER_IS_CLANGXX AND NOT YACMA_COMPILER_IS_MSVC)
if(YACMA_COMPILER_IS_CLANGXX)
# For now it seems like -Wshadow from clang behaves better than GCC's, just enable it here
# for the time being.
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wshadow)
Expand All @@ -100,7 +97,7 @@ if(NOT _YACMACompilerLinkerSettingsRun)
endif()

# Common configuration for GCC, clang and Intel.
if((YACMA_COMPILER_IS_CLANGXX AND NOT YACMA_COMPILER_IS_MSVC) OR YACMA_COMPILER_IS_INTELXX OR YACMA_COMPILER_IS_GNUCXX)
if(YACMA_COMPILER_IS_CLANGXX OR YACMA_COMPILER_IS_INTELXX OR YACMA_COMPILER_IS_GNUCXX)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wall)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wextra)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wnon-virtual-dtor)
Expand All @@ -111,9 +108,7 @@ if(NOT _YACMACompilerLinkerSettingsRun)
# This limit is supposed to be at least 1024 in C++11, but for some reason
# clang sets this to 256, and gcc to 900.
_YACMA_CHECK_ENABLE_CXX_FLAG(-ftemplate-depth=1024)
# NOTE: this can be useful, but at the moment it triggers lots of warnings in type traits.
# Keep it in mind for the next time we touch type traits.
# _YACMA_CHECK_ENABLE_CXX_FLAG(-Wold-style-cast)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wold-style-cast)
# NOTE: disable this for now, as it results in a lot of clutter from Boost.
# _YACMA_CHECK_ENABLE_CXX_FLAG(-Wzero-as-null-pointer-constant)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-pedantic-errors)
Expand All @@ -131,6 +126,7 @@ if(NOT _YACMACompilerLinkerSettingsRun)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wshift-negative-value)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wshift-overflow=2)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wduplicated-cond)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wnull-dereference)
# From GCC 7.
#_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wduplicated-branches)
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wrestrict)
Expand All @@ -143,6 +139,12 @@ if(NOT _YACMACompilerLinkerSettingsRun)
message(STATUS "Activating the '-Wno-attributes' workaround for GCC >= 6.")
_YACMA_CHECK_ENABLE_CXX_FLAG(-Wno-attributes)
endif()
if(YACMA_COMPILER_IS_GNUCXX)
# The -Wmaybe-uninitialized flag is enabled by -Wall, but it is known
# to emit a lot of possibly spurious warnings. Let's just disable it.
message(STATUS "Activating the '-Wno-maybe-uninitialized' workaround for GCC.")
_YACMA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Wno-maybe-uninitialized)
endif()
endif()

# MSVC setup.
Expand Down
2 changes: 2 additions & 0 deletions doc/sphinx/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Changelog
New
~~~

- Implement the particle swarm optimization generational (GPSO) algorithm (`#161 <https://github.com/esa/pagmo2/pull/161>`__).

- Implement the exponential natural evolution strategies (xNES) algorithm (`#142 <https://github.com/esa/pagmo2/pull/142>`__).

- Implement the improved harmony search (IHS) algorithm (`#141 <https://github.com/esa/pagmo2/pull/141>`__).
Expand Down
4 changes: 2 additions & 2 deletions doc/sphinx/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ C++

pagmo is a header-only library which has the following third-party dependencies:

* `Boost <http://www.boost.org/>`__, **mandatory**, header-only
* `Boost <https://www.boost.org/>`__, **mandatory**, header-only
* `Eigen <http://eigen.tuxfamily.org/index.php?title=Main_Page>`__, optional, header-only
(enabled via the ``PAGMO_WITH_EIGEN3`` CMake option)
* `NLopt <https://nlopt.readthedocs.io/en/latest/>`__, optional, requires linking
Expand Down Expand Up @@ -136,7 +136,7 @@ For an installation from source, pygmo has the following dependencies:

* pagmo (i.e., the C++ headers of the pagmo library need to be installed before attempting
to compile pygmo),
* `Boost.Python <http://www.boost.org/doc/libs/1_63_0/libs/python/doc/html/index.html>`__
* `Boost.Python <https://www.boost.org/doc/libs/1_63_0/libs/python/doc/html/index.html>`__
* `NumPy <http://www.numpy.org/>`__ (note that NumPy's development headers must be installed as well).

Note that, at the present time, the versions of pygmo and pagmo must be exactly identical for the compilation of pygmo
Expand Down
8 changes: 4 additions & 4 deletions include/pagmo/algorithms/bee_colony.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ namespace pagmo
* The implementation provided for PaGMO is based on the pseudo-code provided in Mernik et al. (2015) - Algorithm 2.
* pagmo::bee_colony is suitable for box-constrained single-objective continuous optimization.
*
* See: http://mf.erciyes.edu.tr/abc/ for the official ABC web site
* See: https://abc.erciyes.edu.tr/ for the official ABC web site
*
* See: https://link.springer.com/article/10.1007/s10898-007-9149-x for the paper that introduces Artificial Bee Colony
*
* See: http://www.sciencedirect.com/science/article/pii/S0020025514008378 for the pseudo-code
* See: https://www.sciencedirect.com/science/article/pii/S0020025514008378 for the pseudo-code
*/
class bee_colony
{
Expand Down Expand Up @@ -256,8 +256,8 @@ class bee_colony
auto best_idx = pop.best_idx();
// Every 50 lines print the column names
if (count % 50u == 1u) {
print("\n", std::setw(7), "Gen:", std::setw(15), "Fevals:", std::setw(15), "Best:",
std::setw(15), "Current Best:\n");
print("\n", std::setw(7), "Gen:", std::setw(15), "Fevals:", std::setw(15),
"Best:", std::setw(15), "Current Best:\n");
}
print(std::setw(7), gen, std::setw(15), prob.get_fevals() - fevals0, std::setw(15),
pop.champion_f()[0], std::setw(15), pop.get_f()[best_idx][0], '\n');
Expand Down
2 changes: 1 addition & 1 deletion include/pagmo/algorithms/cmaes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class cmaes

// If the algorithm is called for the first time on this problem dimension / pop size or if m_memory is false we
// erease the memory of past calls
if ((newpop.size() != lam) || ((unsigned int)newpop[0].rows() != dim) || (m_memory == false)) {
if ((newpop.size() != lam) || (static_cast<unsigned int>(newpop[0].rows()) != dim) || (m_memory == false)) {
sigma = m_sigma0;
mean.resize(_(dim));
auto idx_b = pop.best_idx();
Expand Down
10 changes: 5 additions & 5 deletions include/pagmo/algorithms/cstrs_self_adaptive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ struct penalized_udp {
retval += std::max(0., fit[j + 1] - c_tol[j]) / m_c_max[j];
}
}
retval /= (double)nc;
retval /= static_cast<double>(nc);
return retval;
}
// According to the population, the first penalty may or may not be applied
Expand Down Expand Up @@ -407,7 +407,7 @@ struct penalized_udp {
mutable std::unordered_map<vector_double, vector_double, detail::hash_vf<double>, detail::equal_to_vf<double>>
m_fitness_map;
};
}
} // namespace detail

/// Self-adaptive constraints handling
/**
Expand Down Expand Up @@ -603,9 +603,9 @@ class cstrs_self_adaptive
// Prints a log line after each call to the inner algorithm
// 1 - Every 50 lines print the column names
if (count % 50u == 1u) {
print("\n", std::setw(7), "Iter:", std::setw(15), "Fevals:", std::setw(15), "Best:",
std::setw(15), "Infeasibility:", std::setw(15), "Violated:", std::setw(15), "Viol. Norm:",
std::setw(15), "N. Feasible:", '\n');
print("\n", std::setw(7), "Iter:", std::setw(15), "Fevals:", std::setw(15),
"Best:", std::setw(15), "Infeasibility:", std::setw(15), "Violated:", std::setw(15),
"Viol. Norm:", std::setw(15), "N. Feasible:", '\n');
}
// 2 - Print
auto cur_best_f = pop.get_f()[pop.best_idx()];
Expand Down
3 changes: 2 additions & 1 deletion include/pagmo/algorithms/ihs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ namespace pagmo
*
* .. seealso::
*
* http://dx.doi.org/10.1016/j.amc.2006.11.033 for the paper that introduces and explains improved harmony search.
* https://linkinghub.elsevier.com/retrieve/pii/S0096300306015098 for the paper that introduces and explains improved
* harmony search.
*
* \endverbatim
*/
Expand Down
39 changes: 16 additions & 23 deletions include/pagmo/algorithms/pso.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ see https://www.gnu.org/licenses/. */
#ifndef PAGMO_ALGORITHMS_PSO_HPP
#define PAGMO_ALGORITHMS_PSO_HPP

#include <cinttypes>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <random>
#include <string>
#include <tuple>
#include <cstdlib>
#include <cmath>
#include <cinttypes>

#include <pagmo/algorithm.hpp>
#include <pagmo/exceptions.hpp>
Expand All @@ -44,6 +44,11 @@ see https://www.gnu.org/licenses/. */
#include <pagmo/rng.hpp>
#include <pagmo/utils/generic.hpp>

namespace pagmo
{

namespace detail
{

// Usual trick with global read-only data.
template <typename = void>
Expand All @@ -53,19 +58,18 @@ struct pso_statics {
*
* The von Neumann neighbourhood of a point includes all the points at a Hamming distance of 1.
*
* - http://en.wikipedia.org/wiki/Von_Neumann_neighborhood
* - https://en.wikipedia.org/wiki/Von_Neumann_neighborhood
* - http://mathworld.wolfram.com/vonNeumannNeighborhood.html
* - http://en.wikibooks.org/wiki/Cellular_Automata/Neighborhood
*/
* - https://en.wikibooks.org/wiki/Cellular_Automata/Neighborhood
*/
static const int vonNeumann_neighb_diff[4][2];
};

// Init of the statics data
template <typename T>
const int pso_statics<T>::vonNeumann_neighb_diff[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

namespace pagmo
{
} // namespace detail

/// Particle Swarm Optimization
/**
Expand Down Expand Up @@ -128,11 +132,11 @@ namespace pagmo
*
* .. seealso::
*
* http://dx.doi.org/10.1007/s11721-007-0002-0 for a survey
* https://link.springer.com/article/10.1007%2Fs11721-007-0002-0 for a survey
*
* \endverbatim
*/
class pso : public pso_statics<>
class pso
{
public:
/// Single entry of the log (Gen, Fevals, gbest, Mean Vel., Mean lbest, Avg. Dist.)
Expand Down Expand Up @@ -775,17 +779,6 @@ class pso : public pso_statics<>
}
}

/*! @brief Von Neumann neighborhood
* (increments on particles' lattice coordinates that produce the coordinates of their neighbors)
*
* The von Neumann neighbourhood of a point includes all the points at a Hamming distance of 1.
*
* - http://en.wikipedia.org/wiki/Von_Neumann_neighborhood
* - http://mathworld.wolfram.com/vonNeumannNeighborhood.html
* - http://en.wikibooks.org/wiki/Cellular_Automata/Neighborhood
*/
//const int vonNeumann_neighb_diff[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

/**
* @brief Arranges particles in a lattice, where each interacts with its immediate 4 neighbors to the N, S, E and
* W.
Expand Down Expand Up @@ -821,9 +814,9 @@ class pso : public pso_statics<>
p_y = pidx / cols;

for (unsigned int nidx = 0u; nidx < 4u; nidx++) {
n_x = (p_x + vonNeumann_neighb_diff[nidx][0]) % cols;
n_x = (p_x + detail::pso_statics<>::vonNeumann_neighb_diff[nidx][0]) % cols;
if (n_x < 0) n_x = cols + n_x;
n_y = (p_y + vonNeumann_neighb_diff[nidx][1]) % rows;
n_y = (p_y + detail::pso_statics<>::vonNeumann_neighb_diff[nidx][1]) % rows;
if (n_y < 0) n_y = rows + n_y;

neighb[static_cast<unsigned int>(pidx)].push_back(static_cast<unsigned int>(n_y * cols + n_x));
Expand Down
Loading

0 comments on commit 1ff0631

Please sign in to comment.