0

I'm trying to solve the minimum vertex cover problem using the Brute-Force Approach, basically trying every combination of edges of a graph to find the minimum.

I have a nested for loop that I want to run parallel

Say I have the following code so far:

def brute_force_MVC(vertices, edges):
    bin_input=["000","001","010","011","100","101","110","111"]
    for case in bin_input:
        for i, vertex in enumerate(vertices):
            if case[i]:
                #do stuff
                for edge in edges:
                   #do more stuff

is there a way to parallelize this? instead of running each case one after the other, could i run them parallel? Would that speed things up?

canecse
  • 1,772
  • 3
  • 16
  • 20
  • https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing – xrisk Oct 06 '18 at 03:16
  • As Rishav mentioned, you should use mutiprocessing to run parallel – goodahn Oct 06 '18 at 03:22
  • Possible duplicate of [How to process a list in parallel in Python?](https://stackoverflow.com/questions/51814897/how-to-process-a-list-in-parallel-in-python) – U13-Forward Oct 06 '18 at 03:24
  • the problem is, I have multiple inputs on my function, all the documentation is for 1 input functions, including the thread posted above. – canecse Oct 06 '18 at 03:34
  • @canecse Group your inputs into tuples. – xrisk Oct 06 '18 at 04:09
  • Even with a tuple, i'm still passing two arguments to the function: the bin_input and the tuples. The documentation for the library you posted shows parallel processing for 1 argument. @rishav could you perhaps provide a pseudocode for your suggestion? – canecse Oct 06 '18 at 13:09

0 Answers0