[this message was posted on Stack overflow before I found out about the mailing list. I hope this is OK]
I'm trying to find what seems to be a complicated and time-consuming multi-objective optimization on a large-ish graph.
Here's the problem: I want to find a graph of n vertices (n is constant at, say 100) and m edges (m can change) where a set of metrics are optimized:
My best guess is to go with GA. I am not very familiar with genetic algorithms, but I can spend a little time to learn the basics. From what I'm reading so far, I need to go as such:
Now, I usually use Python with networkx for my little graph experiments. Could DEAP help me with this problem? If so, I have many more questions (especially on the crossover and mutate steps), but in short: are the steps (in Python, using DEAP) easy enough to be explain or summarized here?
I can try and elaborate if needed. Cheers.
Hey Félix,
This is already so useful, thank you so much! It's really good news DEAP can help me with this problem. I heard of it on stack overflow, actually, while looking for a GA library for Python.
As far as the graph goes, it will be a little bit more complicated than that later on (I actually need to assign categories to vertices), but a simple graph will be a great start.
Thanks again for your very clear explanations, I'll try it first thing tomorrow, will do my best through each step, and might (*will*, most likely) come back with more questions.
Cheers!
Rodolphe
import randomfrom deap import algorithmsfrom deap import basefrom deap import creatorfrom deap import toolsimport networkx as nximport randomimport math"""Creates a binary string from a random graph"""def graph2bin():G=nx.gnm_random_graph(100,random.randint(1,2000))ind = ""for i in G.nodes():for j in G.nodes():if j > i:if G.has_edge(i,j):ind += '1'else:ind += '0'return ind
"""Evaluate function"""def evaluate(individual):G = bin2graph(individual)return nx.density(G), nx.average_shortest_path_length(G), nx.average_clustering(G)"""Fitness class"""creator.create("Fitness", base.Fitness, weights=(-1.0, -1.0, 1.0))"""Individual class"""creator.create("Individual", str, fitness=creator.Fitness) # put graph2bin() instead of list?ind = creator.Individual(graph2bin())print(ind)
--
You received this message because you are subscribed to the Google Groups "deap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deap-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.