mirror of
				https://github.com/ejeanboris/MDAF.git
				synced 2025-11-04 15:18:14 +00:00 
			
		
		
		
	Finally caught the pipe error for bad processes... they can all run and catch the response
This commit is contained in:
		@@ -6,15 +6,19 @@ import importlib.util
 | 
				
			|||||||
import multiprocessing
 | 
					import multiprocessing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# initialise the logic helpers
 | 
					# initialise the logic helpers
 | 
				
			||||||
r.seed(int(time.time()))
 | 
					r.seed(int(time.time()))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
heuristicpath = "/home/remi/Documents/MDAF-GitLAB/SourceCode/SampleAlgorithms/SimmulatedAnnealing.py"
 | 
					heuristicpath = "/home/remi/Documents/MDAF-GitLAB/SourceCode/SampleAlgorithms/SimmulatedAnnealing.py"
 | 
				
			||||||
heuristic_name = "SimmulatedAnnealing"
 | 
					heuristic_name = "SimmulatedAnnealing"
 | 
				
			||||||
testfunctionpaths = ["/home/remi/Documents/MDAF-GitLAB/SourceCode/TestFunctions/Bukin2.py", "/home/remi/Documents/MDAF-GitLAB/SourceCode/TestFunctions/Bukin4.py", "/home/remi/Documents/MDAF-GitLAB/SourceCode/TestFunctions/Bukin6.py"]
 | 
					testfunctionpaths = ["/home/remi/Documents/MDAF-GitLAB/SourceCode/TestFunctions/Bukin2.py", "/home/remi/Documents/MDAF-GitLAB/SourceCode/TestFunctions/Bukin4.py", "/home/remi/Documents/MDAF-GitLAB/SourceCode/TestFunctions/Brown.py"]
 | 
				
			||||||
funcnames = ["Bukin2", "Bukin4", "Bukin6"]
 | 
					funcnames = ["Bukin2", "Bukin4", "Brown"]
 | 
				
			||||||
 | 
					# testfunctionpaths = ["/home/remi/Documents/MDAF-GitLAB/SourceCode/TestFunctions/Brown.py"]
 | 
				
			||||||
 | 
					# funcnames = ["Brown"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
objs = 0
 | 
					objs = 0
 | 
				
			||||||
args = {"high": 200, "low": -200, "t": 100, "p": 0.95}
 | 
					args = {"high": 200, "low": -200, "t": 1000, "p": 0.95}
 | 
				
			||||||
scale = 2.5
 | 
					scale = 2.5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -31,14 +35,33 @@ def doe(heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args,
 | 
				
			|||||||
        testspec.loader.exec_module(func)
 | 
					        testspec.loader.exec_module(func)
 | 
				
			||||||
        #func.MyClass()
 | 
					        #func.MyClass()
 | 
				
			||||||
        initpoint = [r.random() * scale, r.random() * scale]
 | 
					        initpoint = [r.random() * scale, r.random() * scale]
 | 
				
			||||||
        connections.append(multiprocessing.Pipe())
 | 
					        connections.append(multiprocessing.Pipe(duplex=False))
 | 
				
			||||||
        proc.append(multiprocessing.Process(target=heuristic.main, name=funcnames[idx], args=(func, objs, initpoint, args, connections[idx][0])))
 | 
					        proc.append(multiprocessing.Process(target=heuristic.main, name=funcnames[idx], args=(func, objs, initpoint, args, connections[idx][1])))
 | 
				
			||||||
    responses = []
 | 
					 | 
				
			||||||
    for idx,process in enumerate(proc):
 | 
					 | 
				
			||||||
        process.start()
 | 
					 | 
				
			||||||
        responses.append(connections[idx][1].recv())
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    print("started :" + str(initpoint) + "\nEnded  :" + str(responses[0]))
 | 
					
 | 
				
			||||||
 | 
					    responses = []
 | 
				
			||||||
 | 
					    failedfunctions = []
 | 
				
			||||||
 | 
					    processtiming = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for idx,process in enumerate(proc):
 | 
				
			||||||
 | 
					        # processtiming.append(time.tic())
 | 
				
			||||||
 | 
					        process.start()
 | 
				
			||||||
 | 
					        # connections[idx][1].close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Waiting for all the runs to be done
 | 
				
			||||||
 | 
					    for process in proc: process.join()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for idx,conn in enumerate(connections):
 | 
				
			||||||
 | 
					        if proc[idx].exitcode == 0: responses.append(conn[0].recv())
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            responses.append("this run was mot successful")
 | 
				
			||||||
 | 
					            failedfunctions.append((funcnames[idx], proc[idx].exitcode))
 | 
				
			||||||
 | 
					        conn[0].close()
 | 
				
			||||||
 | 
					        conn[1].close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # display output
 | 
				
			||||||
 | 
					    print("\n\n||||| Responses |||||")
 | 
				
			||||||
 | 
					    for idx,response in enumerate(responses): print(funcnames[idx] + "____\n" + "started :" + str(initpoint) + "\nEnded  :" + str(responses[idx]) + "\n_________________")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
doe (heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args, scale)
 | 
					doe (heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args, scale)
 | 
				
			||||||
							
								
								
									
										6
									
								
								SourceCode/TestFunctions/Brown.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								SourceCode/TestFunctions/Brown.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					def main(args):
 | 
				
			||||||
 | 
					    result = 0
 | 
				
			||||||
 | 
					    for i,x in enumerate(args[1:-1]):
 | 
				
			||||||
 | 
					        result += (x**2)**(args[i+1]**2+1) + (args[i+1]**2)**(x**2 + 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return result
 | 
				
			||||||
		Reference in New Issue
	
	Block a user