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?

6
  • docs.python.org/3/library/… Commented Oct 6, 2018 at 3:16
  • As Rishav mentioned, you should use mutiprocessing to run parallel Commented Oct 6, 2018 at 3:22
  • Possible duplicate of How to process a list in parallel in Python? Commented Oct 6, 2018 at 3:24
  • the problem is, I have multiple inputs on my function, all the documentation is for 1 input functions, including the thread posted above. Commented Oct 6, 2018 at 3:34
  • @canecse Group your inputs into tuples. Commented Oct 6, 2018 at 4:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.