Skip to content

[BUG] set_topology causing crash. #606

@kilasuelika

Description

@kilasuelika

Describe the bug
If set the

archipelago archi{ 16u, algo, prob, 20u };
archi.set_topology(pagmo::topology(pagmo::ring()));

then program crash. remove the line ok.

To Reproduce
Code:

#include <iostream>

#include <pagmo/algorithm.hpp>
#include <pagmo/algorithms/sade.hpp>
#include <pagmo/algorithms/pso.hpp>
#include <pagmo/archipelago.hpp>
#include <pagmo/problem.hpp>
#include <pagmo/problems/schwefel.hpp>
#include <pagmo/topologies/ring.hpp>
using namespace pagmo;

struct CustomSphere {
	CustomSphere(unsigned int dim = 30) : m_dim(dim) {}

	std::vector<double> fitness(const std::vector<double>& x) const {
		double sum = 0.0;
		for (const auto& xi : x) {
			sum += xi * xi;
		}
		return { sum };
	}

	std::pair<std::vector<double>, std::vector<double>> get_bounds() const {
		std::vector<double> lb(m_dim, -5.0);
		std::vector<double> ub(m_dim, 5.0);
		return { lb, ub };
	}

	unsigned int get_nobj() const {
		return 1;
	}

	std::string get_name() const {
		return "Custom Sphere Function";
	}

private:
	unsigned int m_dim;
};


int main()
{
	// 1 - Instantiate a pagmo problem constructing it from a UDP
	// (i.e., a user-defined problem, in this case the 30-dimensional
	// generalised Schwefel test function).
	problem prob{ CustomSphere(30) };

	// 2 - Instantiate a pagmo algorithm (self-adaptive differential
	// evolution, 100 generations).
	algorithm algo{ pagmo::pso(100) };

	algo.set_verbosity(5);
	// 3 - Instantiate an archipelago with 16 islands having each 20 individuals.
	archipelago archi{ 16u, algo, prob, 20u };
	archi.set_topology(pagmo::topology(pagmo::ring()));

	// 4 - Run the evolution in parallel on the 16 separate islands 10 times.
	archi.evolve(10);

	// 5 - Wait for the evolutions to finish.
	archi.wait_check();

	// 6 - Print the fitness of the best solution in each island.
	for (const auto& isl : archi) {
		std::cout << isl.get_population().champion_f()[0] << '\n';
	}
}

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: [e.g. Linux] windows
  • Installation method: [e.g. conda, source] vcpkg
  • Version: [e.g. 2.15] 2.19.1

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions