######################################################################## # # This is an example call of MIDACO 6.0 # ------------------------------------- # # MIDACO solves Multi-Objective Mixed-Integer Non-Linear Problems: # # # Minimize F_1(X),... F_O(X) where X(1,...N-NI) is CONTINUOUS # and X(N-NI+1,...N) is DISCRETE # # subject to G_j(X) = 0 (j=1,...ME) equality constraints # G_j(X) >= 0 (j=ME+1,...M) inequality constraints # # and bounds XL <= X <= XU # # # The problem statement of this example is given below. You can use # this example as template to run your own problem. To do so: Replace # the objective functions 'F' (and in case the constraints 'G') given # here with your own problem and follow the below instruction steps. # ######################################################################## O = 0 # global variable to store number of objectives N = 0 # global variable to store number of variables M = 0 # global variable to store number of constraints ######################################################################## ###################### OPTIMIZATION PROBLEM ######################## ######################################################################## def problem_function(x): global O,N,M f = [0.0]*O # Initialize array for objectives F(X) g = [0.0] # Dummy argument for unconstrainted problems #################################################################### ############# Create temporary evaluation folder ############ ############# Copy blackbox executor file into folder ############ ############# Change working directory to eval folder ############ #################################################################### import os,sys,random key_num = random.SystemRandom() random_number = key_num.random() # produces a random number between 0 and 1 random_number = int(random_number*100000000.0) # convert to large integer commands = "mkdir EVALUATION_FOLDER_" + str(random_number) + ";" os.system( commands ) commands = "cp blackbox EVALUATION_FOLDER_" + str(random_number) + "/blackbox;" os.system( commands ) path_old = os.getcwd() # save original path path_new = path_old + '/EVALUATION_FOLDER_' + str(random_number) os.chdir(path_new) # change path to EVALUATION_FOLDER os.system("chmod a+x blackbox") # set permission to allow execution #################################################################### ################ WRITE x variables to text-file ################### #################################################################### xfile=open('variables.txt','w') for i in range(0, N): xfile.write( str(x[i]) + '\n') xfile.close() #################################################################### ################### CALL the blackbox executable ################### #################################################################### from subprocess import call call("./blackbox") # Call blackbox executable from current path #################################################################### ################# READ F and G from text-file #################### #################################################################### objfile=open('objectives.txt','r') i = -1 for line in iter(objfile): i = i + 1 if i < O : f[i] = float(line) else : g[i-O] = float(line) objfile.close() #################################################################### ############# Change working directory back to old path ########### ############# Destroy temporary evaluation folder ########### #################################################################### os.chdir(path_old) commands = "rm -fr EVALUATION_FOLDER_" + str(random_number) + ";" os.system( commands ) return f,g ######################################################################## ######################### MAIN PROGRAM ############################# ######################################################################## key = b'MIDACO_LIMITED_VERSION___[CREATIVE_COMMONS_BY-NC-ND_LICENSE]' problem = {} # Initialize dictionary containing problem specifications option = {} # Initialize dictionary containing MIDACO options problem['@'] = problem_function # Handle for problem function name ######################################################################## ### Step 1: Problem definition ##################################### ######################################################################## # STEP 1.A: Problem dimensions ############################## problem['o'] = 2 # Number of objectives problem['n'] = 2 # Number of variables (in total) problem['ni'] = 0 # Number of integer variables (0 <= ni <= n) problem['m'] = 0 # Number of constraints (in total) problem['me'] = 0 # Number of equality constraints (0 <= me <= m) # save global O = problem['o'] N = problem['n'] M = problem['m'] # STEP 1.B: Lower and upper bounds 'xl' & 'xu' ############################################## problem['xl'] = [ 0, 0 ] problem['xu'] = [ 1, 1 ] # STEP 1.C: Starting point 'x' ############################## problem['x'] = problem['xl'] # Here for example: starting point = lower bounds ######################################################################## ### Step 2: Choose stopping criteria and printing options ########### ######################################################################## # STEP 2.A: Stopping criteria ############################# option['maxeval'] = 1000 # Maximum number of function evaluation (e.g. 1000000) option['maxtime'] = 60*60*24 # Maximum time limit in Seconds (e.g. 1 Day = 60*60*24) # STEP 2.B: Printing options ############################ option['printeval'] = 100 # Print-Frequency for current best solution (e.g. 1000) option['save2file'] = 1 # Save SCREEN and SOLUTION to TXT-files [0=NO/1=YES] ######################################################################## ### Step 3: Choose MIDACO parameters (FOR ADVANCED USERS) ########### ######################################################################## option['param1'] = 0.0 # ACCURACY option['param2'] = 0.0 # SEED option['param3'] = 0.0 # FSTOP option['param4'] = 0.0 # ALGOSTOP option['param5'] = 0.0 # EVALSTOP option['param6'] = 0.0 # FOCUS option['param7'] = 0.0 # ANTS option['param8'] = 0.0 # KERNEL option['param9'] = 0.0 # ORACLE option['param10'] = 0.0 # PARETOMAX option['param11'] = 0.0 # EPSILON option['param12'] = 0.0 # BALANCE option['param13'] = 0.0 # CHARACTER ######################################################################## ### Step 4: Choose Parallelization Factor ############################ ######################################################################## option['parallel'] = 4 # Serial: 0 or 1, Parallel: 2,3,4,5,6,7,8... ######################################################################## ############################ Run MIDACO ################################ ######################################################################## import midaco if __name__ == '__main__': solution = midaco.run( problem, option, key ) # print(solution['f']) # print(solution['g']) # print(solution['x']) ######################################################################## ############################ END OF FILE ############################### ########################################################################