The main idea here is to know how black-box functions are used in objective function definition and how optimization algorithms call these functions.
Let' assume that we have a function defined as follows:
f is an objective function to be minimized for a given problem.Lets say:
f(Xi,Yi)=(Ai.Xi)+(Bi.Xi.Yi) for i=1,2...n
where Yi= N(X1,X2,...Xn) is a blackbox function(a simulation) whose analytical form is unknown which takes all Xi's as inputs
N refers to a network being simulated.
Ai and Bi are constants
The problem has the following constraints:
X1+X2+...+Xn = C
The below function definition is just to show how I've called my simulation results and used it in my optimization objective. I'm also open to suggestions if it could be made even better. (But my main question follows my function definition)
def fun(X):
sim_inpfile(X) # function that has been already defined which is called now by taking x as arguments to write the input file to a simulation
Popen('python Test02.py') # running a python code to execute the simulation
jn.output.Results # Extracting results of simulation by importing a custom made python module called jn
Y=[] # Simulation Result
for i in range(len(jn.output.Results.res)):
if jn.output.Results.res[i].name in nodes:
y += [(jn.output.Results.res[i].pr)] # extracting y as a list from the simulation results
sum = 0 # optimization objective
for i in range(len(a)): # len[a]=len[b]=len[X]=len[Y]
sum += a[i]*X[i]+ b[i]*X[i]*Y[i] #a and b are constants which are lists with the same size as x and y
return sum #the ultimate objective function that takes y(simulation results) as arguments to return the optimization objective value
I call a python optimization solver now.
res = scipy.optimize.minimize(fun, x0, method='SLSQP', bounds=bnds, constraints=cons) # x0=initial x values, bounds= Variable bounds on X, Constraint =equality constraint
Qns:
For each iteration of the algorithm, will the objective function be called for evaluation?
If yes, is the way I've coded, an appropriate way to return my objective
function with the black-box function evaluation at each iteration of the solver?Also if there or similar problems in any of python optimization packages or similar questions and examples, please share their links or threads.
I appreciate you for your time and your experience may help me solve this problem.