Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The topology is ignored when it is a Networkx topology #108

Open
israel-cj opened this issue Oct 5, 2022 · 2 comments
Open

The topology is ignored when it is a Networkx topology #108

israel-cj opened this issue Oct 5, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@israel-cj
Copy link

israel-cj commented Oct 5, 2022

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
-----------------------------------

@israel-cj israel-cj added the bug Something isn't working label Oct 5, 2022
@bluescarni
Copy link
Member

@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.

@israel-cj
Copy link
Author

@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()

download

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()

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants