mirror of
				https://github.com/ejeanboris/MDAF.git
				synced 2025-11-04 07:08:15 +00:00 
			
		
		
		
	the multiprocessing workflows as well as comms pipelines are operational
This commit is contained in:
		@@ -14,8 +14,8 @@ heuristic_name = "SimmulatedAnnealing"
 | 
			
		||||
testfunctionpaths = ["/home/remi/Documents/MDAF-GitLAB/SourceCode/TestFunctions/Bukin2.py"]
 | 
			
		||||
funcnames = ["Bukin2"]
 | 
			
		||||
objs = 0
 | 
			
		||||
args = {"high": 200, "low": -200, "t": 0.01, "p": 0.8}
 | 
			
		||||
scale = 62
 | 
			
		||||
args = {"high": 200, "low": -200, "t": 100, "p": 0.8}
 | 
			
		||||
scale = 3
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def doe(heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args, scale):
 | 
			
		||||
@@ -23,6 +23,7 @@ def doe(heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args,
 | 
			
		||||
    heuristic = importlib.util.module_from_spec(spec)
 | 
			
		||||
    spec.loader.exec_module(heuristic)
 | 
			
		||||
    proc = list()
 | 
			
		||||
    connections = []
 | 
			
		||||
    #heuristic.MyClass()
 | 
			
		||||
    for idx, funcpath in enumerate(testfunctionpaths):
 | 
			
		||||
        testspec = importlib.util.spec_from_file_location(funcnames[idx], funcpath)
 | 
			
		||||
@@ -30,11 +31,14 @@ def doe(heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args,
 | 
			
		||||
        testspec.loader.exec_module(func)
 | 
			
		||||
        #func.MyClass()
 | 
			
		||||
        initpoint = [r.random() * scale, r.random() * scale]
 | 
			
		||||
        proc.append(multiprocessing.Process(target=heuristic.main, name=funcnames[idx], args=(func, objs, initpoint, args)))
 | 
			
		||||
        best = proc[idx].run()
 | 
			
		||||
        print("started :" + str(initpoint) + "\nEnded  :" + str(best))
 | 
			
		||||
        connections.append(multiprocessing.Pipe())
 | 
			
		||||
        proc.append(multiprocessing.Process(target=heuristic.main, name=funcnames[idx], args=(func, objs, initpoint, args, connections[idx][0])))
 | 
			
		||||
    responses = []
 | 
			
		||||
    for idx,process in enumerate(proc):
 | 
			
		||||
        process.start()
 | 
			
		||||
        responses.append(connections[idx][1].recv())
 | 
			
		||||
 | 
			
		||||
    print("started :" + str(initpoint) + "\nEnded  :" + str(responses[0]))
 | 
			
		||||
 | 
			
		||||
# simulatedAnnealing(S = [9.00,4.00],y = 0,high = 10,low = -8,t =0.01,p = 0.8)
 | 
			
		||||
# proc = subprocess.call(["python", heuristic, "arg-15", "arg2", "argN"])
 | 
			
		||||
 | 
			
		||||
doe (heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args, scale)
 | 
			
		||||
@@ -28,9 +28,10 @@ def Quality(Sc,objective,func):
 | 
			
		||||
        error = [func_output[i]-objective[i] for i in range(len(func_output))]
 | 
			
		||||
    else:
 | 
			
		||||
        error = func_output - objective
 | 
			
		||||
        print("Error is: "+str(error))
 | 
			
		||||
    return 1/abs(error)
 | 
			
		||||
 | 
			
		||||
def main(func,obj,S,args):
 | 
			
		||||
def main(func, obj, S, args, connection):
 | 
			
		||||
    r.seed(int(time.time()))
 | 
			
		||||
    route = list()
 | 
			
		||||
    #Parsing arguments
 | 
			
		||||
@@ -71,10 +72,12 @@ def main(func,obj,S,args):
 | 
			
		||||
            route.append(Best[:])
 | 
			
		||||
            print(route)
 | 
			
		||||
            
 | 
			
		||||
        if t < 0 or Quality(Best,y,func) > 200:
 | 
			
		||||
        if t < 0 or Quality(Best,y,func) > 1000:
 | 
			
		||||
            break
 | 
			
		||||
    #print('the Best Quality obtained was:{}'.format(Quality(Best,y)))
 | 
			
		||||
    return Best
 | 
			
		||||
    print("Final Quality is: {}".format(Quality(Best,y,func)))
 | 
			
		||||
    print("final Temperature is: {}".format(t))
 | 
			
		||||
    connection.send(Best)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user