GeminiLight / virne

Virne is a simulator for resource allocation problems in network virtualization, mainly for virtual network embedding (VNE). It also is adaptable to VNE's variants, such as service function chain deployment (SFC Deployment), network slicing, etc.
https://virne.readthedocs.io
Apache License 2.0
100 stars 19 forks source link

Particle_swarm_optimization_solver may have a multiprocessing bug #35

Closed grey-wood-wolf closed 2 weeks ago

grey-wood-wolf commented 2 weeks ago

In the project code, Particle_swarm_optimization_solver may have a code bug.

Specifically, this issue occurs when using multiprocessing for parallel processing in the solution method. In Python, when using multiprocessing, passing an object directly as a parameter can cause some issues:

  1. When a new process is created, the parameters are serialized (pickled) and then passed to the child process. The child process receives a completely independent copy of the parameter object.
  2. Any modifications made to this copy by the child process will not affect the original object in the main process because they are in different memory spaces.

As a result, during each evolve iteration, the particle's properties, such as node_slots, will not be modified. This implementation may have some issues.

The potentially problematic code is as follows:

for id in range(self.max_iteration):
    # result = mp_pool.map(self.evolve, self.particles)
    particle_runners = []
    node_slots_1 = str([particle.solution["node_slots"] for particle in self.particles])

    for particle in self.particles:
        particle_runners.append(mp.Process(target=self.evolve, args=(particle, )))
        # particle_runners.append(ParticleRunner(v_net, p_net, self, self.particles[i]))

    for particle_runner in particle_runners:
        particle_runner.start()

    for particle_runner in particle_runners:
        particle_runner.join()