@@ -81,16 +81,18 @@ def fitness_iteration_parallel(self, out_queue, ichunk, chunk_length,
8181 index of the individual, the individual itself, and its fitness.
8282
8383 :param multiprocessing.queues.Queue out_queue: multiprocessing queue
84- :param int ichunk: index of the chunk under consideration
84+ :param int ichunk: index of the chunk under consideration.
8585 :param int chunk_length: lengths of the chunks (the last chunk may
8686 be shorter due to non-even division of the number of generations by
87- the number of processors)
87+ the number of processors).
8888 :param list individuals: list of individuals on which to perform
8989 fitness evaluation.
9090 :param list perturbed_nodes: nodes(s) involved in the perturbing event.
9191 :param dict initial_condition: initial status (boolean) for the graph
9292 switches.
93-
93+ :param origin: origin of the perturbation. Nodes can be resitant to
94+ different kinds of perturbations, default to None.
95+ :type origin: string, optional
9496 """
9597
9698 for iter_ind in range (len (individuals )):
@@ -106,13 +108,16 @@ def fitness_evaluation_parallel(self, pop, perturbed_nodes,
106108 Wrapper for fitness evaluation. This methods spawns the processes for
107109 fitness evaluation and collects the results.
108110
109- :param list pop: list of individuals
111+ :param list pop: list of individuals.
110112 :param list perturbed_nodes: nodes(s) involved in the perturbing event.
111113 :param dict initial_condition: initial status (boolean) for the graph
112114 switches.
115+ :param origin: origin of the perturbation. Nodes can be resitant to
116+ different kinds of perturbations, default to None.
117+ :type origin: string, optional
113118
114119 :return: list of tuples constituted by the index of the individual,
115- the individual itself, and its fitness
120+ the individual itself, and its fitness.
116121 :rtype: list
117122 """
118123
@@ -157,6 +162,9 @@ def fitness_evaluation(self, individual, perturbed_nodes,
157162 perturbing event.
158163 :param dict initial_condition: initial status (boolean) for the graph
159164 switches.
165+ :param origin: origin of the perturbation. Nodes can be resitant to
166+ different kinds of perturbations, default to None.
167+ :type origin: string, optional
160168 """
161169
162170 acts = np .sum (np .not_equal (list (initial_condition .values ()),
@@ -226,7 +234,10 @@ def optimizer(self, perturbed_nodes, initial_condition, params, weights,
226234 (default to -1.0)
227235 - 'w5': weight for service balance over users (default to 2.0)
228236 :param bool parallel: flag for parallel fitness evaluation of
229- initial population
237+ initial populations.
238+ :param origin: origin of the perturbation. Nodes can be resitant to
239+ different kinds of perturbations, default to None.
240+ :type origin: string, optional
230241 """
231242
232243 logging .getLogger ().setLevel (logging .INFO )
@@ -263,28 +274,24 @@ def optimizer(self, perturbed_nodes, initial_condition, params, weights,
263274 for ind , f in zip (pop , fitnesses ):
264275 ind .fitness .values = (np .dot (w , np .asarray (f )),)
265276
266- # Variable keeping track of the number of generations
277+ # Generations
267278 g = 0
268-
269279 result = []
270- # Begin the evolution
271280
272- # Population is made by individuals and fitnesses
273281 pop = [list (couple ) for couple in zip (pop , fitnesses )]
274282 pop .sort (key = lambda x : np .dot (w , np .asarray (x [1 ])))
275283
276284 while g < params ['ngen' ]:
277285
278- # A new generation
279286 g = g + 1
280287
281- # Select the next generation individuals
288+ # Select next generation
282289 offspring = [x [0 ] for x in pop [:params ['nsel' ]]]
283290 pop = pop [:params ['nsel' ]]
284291
285292 invalid_ind = []
286293
287- # Apply crossover and mutation on the offspring
294+ # Crossover and mutation on the offspring
288295 for parent1 , parent2 in zip (offspring [::2 ], offspring [1 ::2 ]):
289296 if random .random () < params ['tresh' ]:
290297 child1 = toolbox .clone (parent1 )
@@ -401,11 +408,14 @@ def rm_nodes(self, node, graph, origin, visited=None, broken_nodes=None):
401408
402409 :param str node: the id of the node to remove.
403410 :param nx.DiGraph graph: graph on which to apply the node deletion
411+ :param origin: origin of the perturbation. Nodes can be resitant to
412+ different kinds of perturbations, default to None.
413+ :type origin: string, optional
404414 :param visited: nodes already visited, default to None.
405415 :type visited: set, optional
406416 :param broken_nodes: nodes that got broken along the perturbation,
407417 default to None.
408- :type visited : list, optional
418+ :type broken_nodes : list, optional
409419 """
410420
411421 if visited is None :
@@ -508,6 +518,9 @@ def delete_a_node(self, node, origin):
508518 Delete a node in the graph.
509519
510520 :param str node: the id of the node to remove.
521+ :param origin: origin of the perturbation. Nodes can be resitant to
522+ different kinds of perturbations, default to None.
523+ :type origin: string, optional
511524
512525 .. warning:: the node id must be contained in the graph.
513526 No check is done within this function.
@@ -555,10 +568,13 @@ def apply_perturbation(self, perturbed_nodes, params, weights, parallel,
555568 (default to -1.0)
556569 - 'w5': weight for service balance over users (default to 2.0)
557570 :param bool parallel: flag for parallel fitness evaluation of
558- initial population
559- :param bool verbose: flag for verbose printing
571+ initial population.
572+ :param bool verbose: flag for verbose printing.
573+ :param origin: origin of the perturbation. Nodes can be resitant to
574+ different kinds of perturbations, default to None.
575+ :type origin: string, optional
560576 :param str kind: type of simulation, used to label output files,
561- default to 'element'
577+ default to 'element'.
562578
563579 .. note:: A perturbation, depending on the considered system,
564580 may spread in all directions starting from the damaged
@@ -671,10 +687,13 @@ def simulate_element_perturbation(self, perturbed_nodes,
671687 - 'w5': weight for service balance over users (default to 2.0)
672688 :type weights: dict, optional
673689 :param parallel: flag for parallel fitness evaluation of
674- initial population, default to False
690+ initial population, default to False.
675691 :type parallel: bool, optional
676- :param verbose: flag for verbose output, default to True
692+ :param verbose: flag for verbose output, default to True.
677693 :type verbose: bool, optional
694+ :param origin: origin of the perturbation. Nodes can be resitant to
695+ different kinds of perturbations, default to None.
696+ :type origin: string, optional
678697
679698 .. note:: A perturbation, depending on the considered system,
680699 may spread in all directions starting from the damaged
@@ -723,8 +742,11 @@ def simulate_area_perturbation(self, perturbed_areas, params={'npop': 300,
723742 - 'w5': weight for service balance over users (default to 2.0)
724743 :type weights: dict, optional
725744 :param parallel: flag for parallel fitness evaluation of
726- initial population, default to False
745+ initial population, default to False.
727746 :type parallel: bool, optional
747+ :param origin: origin of the perturbation. Nodes can be resitant to
748+ different kinds of perturbations, default to None.
749+ :type origin: string, optional
728750
729751 .. note:: A perturbation, depending on the considered system,
730752 may spread in all directions starting from the damaged
0 commit comments