How to solve an optimization problem with an objective function which is not directly a function of decision variables?

My objective function and constraints include some expressions each of which are defined separately. Therefore the OF and constraints does not directly include variables. I know that the optimization functions in Matlab require the variables to present in the constraints or OFs to be able to solve the problem. I cannot bring variables to my functions because I do max operation and some different for loops for their calculations separately.

4 Comments

Note, max() operations likely render your objective function/constraints non-differentiable. There are no constrained solvers in the Optimization Toolbox that can handle non-differentiable problems. Only the Global Optimization Toolbox solvers would be appropriate for them, or maybe FMINSEARCHCON
Obviously pulling all nighters makes me a bad writer. Anyhow, how about GA? can I use GA for that? I used GA on Excel and it solved my problem . Can I use the GA toolbox to solve my problem?
Hello
I have the same question in using GA but I found the answer a bit complicated. Could you say the soloution for a simple question as follows:
a=10;
b=5;
x=2a+b
y=b/3
z=x+y
I want to minimize "z" while "a" & "b" are the variables.
Thank you very much.

Sign in to comment.

 Accepted Answer

I am not sure that I understand you. If you have some parameters that are not decision variables, but instead are extra parameters or data, see how to pass extra parameters.
If you have some parameters that depend on intermediate calculations in your objective or nonlinear constraint functions, then just wratp them into your function files.
If I misunderstand you completely, please try again, and perhaps include a bit of pseudocode so that we can have a better chance of understanding your situation.
Alan Weiss
MATLAB mathematical toolbox documentation

3 Comments

Alan, thnx a lot for your quick response. I do some intermediate calculations on my parameters and variables. My OF looks like this:
OF=HC+EC+SC+IVTT+IVTQ+IVTE+IVTH+IVTWE+IVTLE+IVTAE+IVTHW-ICTE-ICTLE-ICTWE-ICTAE-ICTHW-TS+TCCLE+TCCWE+TCCAE+TCCHW;
%Non of those are my variables.
%My variables are as follow:
xH=zeros(size(I));
xCT=zeros(size(I));
xA=zeros(size(I));
xE=zeros(size(I));
xWE=zeros(size(I));
xLE=zeros(size(I));
xAE=zeros(size(I));
xHW=zeros(size(I));
fileName = 'Parameters.xlsx'; %Excel file related to modelling parameters
sheetName = 'p' ; %excel sheet related to parameters
ParameterRange='A1:AU14' ; %cell range for the parameter data in the excel file
parameterData=xlsread(fileName, sheetName ,ParameterRange) ;
I=parameterData(:,2);
J=parameterData(:,3);
K=parameterData(:,4);
TTmax= max(TT,[],3);
TPT=sum(sum(sum(PHTf)))+sum(sum(sum(TTmax)));
TB= TTmax+sum(PHTf,3) ;
for n=2:size(I)
if((isequal(I(n),I(n-1)) + isequal(J(n),J(n-1)))<2)
TB(I(n),J(n))=TB(I(n),J(n))+TB(I(n-1),J(n-1));
else
TB(I(n),J(n))=TB(I(n-1),J(n-1));
end
end
NOP=zeros(max(I),max(J));
for n=1:size(I)
if((T-TPT*floor(T/TPT)-TB(I(n),J(n)))<0)
NOP(I(n),J(n))=floor(T/TPT);
else
NOP(I(n),J(n))=floor(T/TPT)+1;
end
end
HCij=zeros(max(I),max(J)); * % this is the first expression from the OF
for n=1:size(I)
HCij(I(n),J(n))=NOP(I(n),J(n))*PHR(I(n),J(n))*PHTf(I(n),J(n));
end*
the Other expressions have their own different definitions. Im not sure how to wrap up everything in my OF .
Thanks for the explanation. Here is how I would approach this problem.
  1. Get the Excel data into your workspace first with the xlsread statement.
  2. Create the parameters I, J, K, and whatever else you need that doesn't depend on anything but the data.
  3. Write a function file OF = myfunction(x,I,J,K,...), where x represents ALL your decision variables, and I,J,K,... are ALL your parameters that you need. myfunction should return the value of the objective function when x,I,J,K,.. are specified.
  4. Call the solver like this:
[solution,value] = patternsearch(@(x)myfunction(x,I,J,K,...),x0)
or
[solution,value] = ga(@(x)myfunction(x,I,J,K,...),numVariablesInx)
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!