mirror of
				https://github.com/ejeanboris/MDAF.git
				synced 2025-11-04 07:08:15 +00:00 
			
		
		
		
	the suboprocesses are running and the algorithm is functionning to optimize the function it is given
This commit is contained in:
		
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								References/TestFunctions.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								References/TestFunctions.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -10428,7 +10428,7 @@
 | 
				
			|||||||
   "name": "python",
 | 
					   "name": "python",
 | 
				
			||||||
   "nbconvert_exporter": "python",
 | 
					   "nbconvert_exporter": "python",
 | 
				
			||||||
   "pygments_lexer": "ipython3",
 | 
					   "pygments_lexer": "ipython3",
 | 
				
			||||||
   "version": "3.8.2"
 | 
					   "version": "3.9.2"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 },
 | 
					 },
 | 
				
			||||||
 "nbformat": 4,
 | 
					 "nbformat": 4,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										40
									
								
								SourceCode/AlgorithmAnalyser.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								SourceCode/AlgorithmAnalyser.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
				
			|||||||
 | 
					# directly running the DOE because existing surrogates can be explored with another workflow
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from numpy import random as r
 | 
				
			||||||
 | 
					import time
 | 
				
			||||||
 | 
					import importlib.util
 | 
				
			||||||
 | 
					import multiprocessing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# initialise the logic helpers
 | 
				
			||||||
 | 
					r.seed(int(time.time()))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					heuristicpath = "/home/remi/Documents/MDAF-GitLAB/SourceCode/SampleAlgorithms/SimmulatedAnnealing.py"
 | 
				
			||||||
 | 
					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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def doe(heuristicpath, heuristic_name, testfunctionpaths, funcnames, objs, args, scale):
 | 
				
			||||||
 | 
					    spec = importlib.util.spec_from_file_location(heuristic_name, heuristicpath)
 | 
				
			||||||
 | 
					    heuristic = importlib.util.module_from_spec(spec)
 | 
				
			||||||
 | 
					    spec.loader.exec_module(heuristic)
 | 
				
			||||||
 | 
					    proc = list()
 | 
				
			||||||
 | 
					    #heuristic.MyClass()
 | 
				
			||||||
 | 
					    for idx, funcpath in enumerate(testfunctionpaths):
 | 
				
			||||||
 | 
					        testspec = importlib.util.spec_from_file_location(funcnames[idx], funcpath)
 | 
				
			||||||
 | 
					        func = importlib.util.module_from_spec(testspec)
 | 
				
			||||||
 | 
					        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))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 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)
 | 
				
			||||||
							
								
								
									
										70
									
								
								SourceCode/Analyse_folders_and_description.ipynb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								SourceCode/Analyse_folders_and_description.ipynb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,70 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					 "cells": [
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					   "cell_type": "markdown",
 | 
				
			||||||
 | 
					   "id": "abstract-broad",
 | 
				
			||||||
 | 
					   "metadata": {},
 | 
				
			||||||
 | 
					   "source": [
 | 
				
			||||||
 | 
					    "# Program to read through folders in a file-path and spit out description"
 | 
				
			||||||
 | 
					   ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					   "cell_type": "code",
 | 
				
			||||||
 | 
					   "execution_count": null,
 | 
				
			||||||
 | 
					   "id": "similar-algeria",
 | 
				
			||||||
 | 
					   "metadata": {},
 | 
				
			||||||
 | 
					   "outputs": [],
 | 
				
			||||||
 | 
					   "source": [
 | 
				
			||||||
 | 
					    "def find_algorithm():\n",
 | 
				
			||||||
 | 
					    "    import os # To enable you walk through the OS directory\n",
 | 
				
			||||||
 | 
					    "    import re # To enable pattern recognition\n",
 | 
				
			||||||
 | 
					    "    \n",
 | 
				
			||||||
 | 
					    "    \n",
 | 
				
			||||||
 | 
					    "    # Take file-path and extract names of files in file-path as list data type\n",
 | 
				
			||||||
 | 
					    "    check_folder = input(\"Please enter the file-path of the folder: \\n\")\n",
 | 
				
			||||||
 | 
					    "    found_items = os.listdir(check_folder)\n",
 | 
				
			||||||
 | 
					    "    \n",
 | 
				
			||||||
 | 
					    "    \n",
 | 
				
			||||||
 | 
					    "    # Initialize what the pattern to be searched for should look like\n",
 | 
				
			||||||
 | 
					    "    pattern = \"\\W\\W\\W\"\n",
 | 
				
			||||||
 | 
					    "    \n",
 | 
				
			||||||
 | 
					    "    # Look into the individual txt files and extraxt the description \n",
 | 
				
			||||||
 | 
					    "    for items in range(0, len(found_items)):\n",
 | 
				
			||||||
 | 
					    "        print(f\"\\n({items + 1}): I found the file named: {found_items[items]}\")\n",
 | 
				
			||||||
 | 
					    "        inside_file = check_folder + '\\\\' + found_items[items]\n",
 | 
				
			||||||
 | 
					    "        \n",
 | 
				
			||||||
 | 
					    "        with open(inside_file, mode ='r', encoding = 'utf-8') as myfile:\n",
 | 
				
			||||||
 | 
					    "            print(\"Inside the file, I found this description: \\n \")\n",
 | 
				
			||||||
 | 
					    "            contents = myfile.readlines()\n",
 | 
				
			||||||
 | 
					    "            \n",
 | 
				
			||||||
 | 
					    "            for indexing in range(0, len(contents)):\n",
 | 
				
			||||||
 | 
					    "                if re.search(pattern, contents[indexing]):\n",
 | 
				
			||||||
 | 
					    "                    print(contents[indexing+1])\n",
 | 
				
			||||||
 | 
					    "                    break\n",
 | 
				
			||||||
 | 
					    "                    \n",
 | 
				
			||||||
 | 
					    "            print(\"\\n\\n\")"
 | 
				
			||||||
 | 
					   ]
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					 ],
 | 
				
			||||||
 | 
					 "metadata": {
 | 
				
			||||||
 | 
					  "kernelspec": {
 | 
				
			||||||
 | 
					   "display_name": "Python 3",
 | 
				
			||||||
 | 
					   "language": "python",
 | 
				
			||||||
 | 
					   "name": "python3"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "language_info": {
 | 
				
			||||||
 | 
					   "codemirror_mode": {
 | 
				
			||||||
 | 
					    "name": "ipython",
 | 
				
			||||||
 | 
					    "version": 3
 | 
				
			||||||
 | 
					   },
 | 
				
			||||||
 | 
					   "file_extension": ".py",
 | 
				
			||||||
 | 
					   "mimetype": "text/x-python",
 | 
				
			||||||
 | 
					   "name": "python",
 | 
				
			||||||
 | 
					   "nbconvert_exporter": "python",
 | 
				
			||||||
 | 
					   "pygments_lexer": "ipython3",
 | 
				
			||||||
 | 
					   "version": "3.9.2"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					 },
 | 
				
			||||||
 | 
					 "nbformat": 4,
 | 
				
			||||||
 | 
					 "nbformat_minor": 5
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										81
									
								
								SourceCode/SampleAlgorithms/SimmulatedAnnealing.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								SourceCode/SampleAlgorithms/SimmulatedAnnealing.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,81 @@
 | 
				
			|||||||
 | 
					import math as m
 | 
				
			||||||
 | 
					import numpy as np
 | 
				
			||||||
 | 
					from numpy import random as r
 | 
				
			||||||
 | 
					import time
 | 
				
			||||||
 | 
					import matplotlib.pyplot as plt
 | 
				
			||||||
 | 
					from mpl_toolkits import mplot3d
 | 
				
			||||||
 | 
					import copy as cp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#def func(Sc):
 | 
				
			||||||
 | 
					#    x1 = Sc[0]
 | 
				
			||||||
 | 
					#    x2 = Sc[1]
 | 
				
			||||||
 | 
					#    return m.sqrt(x1**2+x2**2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def tweak(St,p,sigma,high,low):
 | 
				
			||||||
 | 
					    for i in range(len(St)):
 | 
				
			||||||
 | 
					        if p > r.random():
 | 
				
			||||||
 | 
					            while True:
 | 
				
			||||||
 | 
					                n = r.normal(loc=0, scale=sigma)
 | 
				
			||||||
 | 
					                if (high > St[i]+n) and (low < St[i]+n):
 | 
				
			||||||
 | 
					                    St[i]+=n
 | 
				
			||||||
 | 
					                    break
 | 
				
			||||||
 | 
					    return St
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def Quality(Sc,objective,func):
 | 
				
			||||||
 | 
					    func_output = func.main(Sc)
 | 
				
			||||||
 | 
					    if type(func_output) == list:
 | 
				
			||||||
 | 
					        error = [func_output[i]-objective[i] for i in range(len(func_output))]
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        error = func_output - objective
 | 
				
			||||||
 | 
					    return 1/abs(error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def main(func,obj,S,args):
 | 
				
			||||||
 | 
					    r.seed(int(time.time()))
 | 
				
			||||||
 | 
					    route = list()
 | 
				
			||||||
 | 
					    #Parsing arguments
 | 
				
			||||||
 | 
					    y = obj
 | 
				
			||||||
 | 
					    high = args["high"]
 | 
				
			||||||
 | 
					    low = args["low"]
 | 
				
			||||||
 | 
					    t = args["t"]
 | 
				
			||||||
 | 
					    p = args["p"]
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    Best = list()
 | 
				
			||||||
 | 
					    Best[:] = cp.deepcopy(S)
 | 
				
			||||||
 | 
					    sigma = 0.1
 | 
				
			||||||
 | 
					    route.append(Best[:])
 | 
				
			||||||
 | 
					    while True:
 | 
				
			||||||
 | 
					        print('\n\n\n')
 | 
				
			||||||
 | 
					        R = tweak(cp.deepcopy(S),p,sigma,high,low)
 | 
				
			||||||
 | 
					        print(R)
 | 
				
			||||||
 | 
					        print(S)
 | 
				
			||||||
 | 
					        Qr = Quality(R,y,func)
 | 
				
			||||||
 | 
					        Qs = Quality(S,y,func)
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            P = m.e**((Qr-Qs)/t)
 | 
				
			||||||
 | 
					        except:
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					        print('QUALITY_R///{}'.format(Qr))
 | 
				
			||||||
 | 
					        print('QUALITY_S///{}'.format(Qs))
 | 
				
			||||||
 | 
					        print('fraction is:{}'.format(P))
 | 
				
			||||||
 | 
					        if (Qr > Qs) or (r.random() < P):
 | 
				
			||||||
 | 
					            print('NEW_S')
 | 
				
			||||||
 | 
					            S[:] = R[:]
 | 
				
			||||||
 | 
					        if t > 0.01:
 | 
				
			||||||
 | 
					            t-= t/10
 | 
				
			||||||
 | 
					        print('t = {}'.format(t))
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if (Quality(S,y,func) > Quality(Best,y,func)):
 | 
				
			||||||
 | 
					            print('new Best****:{}'.format(Best))
 | 
				
			||||||
 | 
					            Best[:] = S[:]
 | 
				
			||||||
 | 
					            route.append(Best[:])
 | 
				
			||||||
 | 
					            print(route)
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					        if t < 0 or Quality(Best,y,func) > 200:
 | 
				
			||||||
 | 
					            break
 | 
				
			||||||
 | 
					    #print('the Best Quality obtained was:{}'.format(Quality(Best,y)))
 | 
				
			||||||
 | 
					    return Best
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					 "cells": [],
 | 
				
			||||||
 | 
					 "metadata": {},
 | 
				
			||||||
 | 
					 "nbformat": 4,
 | 
				
			||||||
 | 
					 "nbformat_minor": 4
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										2
									
								
								SourceCode/TestFunctions/Bukin2.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								SourceCode/TestFunctions/Bukin2.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					def main(args):
 | 
				
			||||||
 | 
					    return 100*(args[1]-0.01*args[0]**2+1)+0.01*(args[0]+10)**2
 | 
				
			||||||
							
								
								
									
										6
									
								
								SourceCode/TestFunctions/Untitled.ipynb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								SourceCode/TestFunctions/Untitled.ipynb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					 "cells": [],
 | 
				
			||||||
 | 
					 "metadata": {},
 | 
				
			||||||
 | 
					 "nbformat": 4,
 | 
				
			||||||
 | 
					 "nbformat_minor": 4
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user