Open israel-cj opened 1 year ago
@israel-cj I think you are missing the n
argument to specify the number of islands in the archipelago. See the docs:
https://esa.github.io/pygmo2/archipelago.html
In case you are wondering, the topology interface does not allow to infer how many nodes (i.e., islands) are in the graph, and thus the number of islands must be provided separately.
@bluescarni, thanks for your answer. The problem is the free topology is ignored when I add a new island. For example, when I use a topology object directly from pygmo (e.g. pg.ring()), and I add an island (new node), the topology immediately associates this island with an edge to the current topology:
import pygmo as pg a_cstrs_sa = pg.algorithm(pg.cstrs_self_adaptive(iters=1000)) p_toy = pg.problem(toy_problem(50)) p_toy.c_tol = [1e-4, 1e-4] archi = pg.archipelago(n=9,algo=a_cstrs_sa, prob=p_toy, pop_size=50, t=pg.topology(pg.ring())) print(archi) G = archi.get_topology().to_networkx() nx.draw(G) plt.draw() # pyplot draw()
But when it is a free form, the islands are added in an unconnected way, without considering the free from topology:
archi = pg.archipelago(n=9,algo=a_cstrs_sa, prob=p_toy, pop_size=50, t=pg.free_form(G)) print(archi) G = archi.get_topology().to_networkx() nx.draw(G) plt.draw() # pyplot draw()
Hello :) I want to integrate a new topology in an archipelago so that it can be updated every time an island is added, but Pygmo does not respect the configuration. In the following code example, given the topology (G) with 4 nodes, I would like to see these 4 islands in the archipelago when I use "pg.free_form(G)".
Creation network's topology
G = nx.DiGraph() list_nodes = list(range(0,4)) edges = list(itertools.product(list_nodes, list_nodes)) final_edge_list = [] for edge in edges: if edge[0] != edge[1]: final_edge_list.append((edge[0], edge[1], {"weight": 1.0})) G.add_nodes_from(list_nodes) G.add_edges_from(final_edge_list) pos = nx.spring_layout(G) nx.draw_networkx(G, pos, with_labels=True, font_weight='bold') labels = nx.get_edge_attributes(G, 'weight') nx.draw_networkx_edge_labels(G, pos, edge_labels=labels)
Using the topology in the archipelago
archi = pg.archipelago(algo = pg.de(), prob = pg.rosenbrock(10), pop_size = 20, seed = 32, t=pg.free_form(G))
But the archipelago didn't get any island
Number of islands: 0 Topology: Free form Migration type: point-to-point Migrant handling policy: preserve Status: idle Islands summaries: Type Algo Prob Size Status