How to pass inequality constraints to surrogateopt?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Suhas Raghavendra Kulkarni
el 9 de Mzo. de 2022
Respondida: T.Nikhil kumar
el 1 de Dic. de 2023
Hello,
I have a function that returns the objective and constraint functions to be passed to surrogateopt. However, I receve the following error about the constraint
Error using parallel.FevalFuture/fetchNext
The function evaluation completed with an error.
[~, self.pendingTrials(fetchID).output] = fetchNext(self.pendingTrials(fetchID).task);
trialResponse = self.modelMgr.getNext();
controller = controller.optimize();
xfinal = surrogateopt(objconstr,lb,ub,intcon, options);
Caused by:
Input arguments to function include colon operator. To input the colon character, use ':' instead.
The function that returns the constraint is as follows
[obj, con]=func1(a,b,c);
objconstr=@(x) struct('Fval',obj,'Ineq',con);
% lb ub, intcon and options have also been appropriately specified and supplied to the optimiser.
xfinal = surrogateopt(objconstr,lb,ub,intcon, options);
function [obj, con]=func1(a,b,c)
P=[];
obj=@func2;
con=@func3;
function obj=func2(x)
%many matrix operations that calculate P using a,b,c and a number
%of optimsiation variables "x"
P=somedummyoperation; %P is a nXM matrix
obj=sum(sum(P));
end
function con=func3
load('ref_vector_file','ref_vec');
buff_var=cross(P(1:2:3,:),ref_vec);
con=norm(buff_vec);
end
end
This code however runs when i remove the constraint and optimise (the solution is unacceptable since the problem is poorly defined in this case)
How would I choose to move ahead to to address the error?
0 comentarios
Respuestas (1)
T.Nikhil kumar
el 1 de Dic. de 2023
Hello Suhas,
I understand that you are trying to solve an optimization problem using surrogate optimization method and are facing an error while passing a function to another function.
The error suggests that there might be an issue with the input arguments or operations within the constraint function ‘con’.
After looking at the code, it seems that there's a typing mistake in the constraint function ‘func3’. The variable ‘buff_var’ is being assigned a value using ‘cross’ function, but then ‘con’ value is calculated using ‘norm(buff_vec)’. There is no ‘buff_vec’ variable being calculated/declared in the code snippet. It seems like ‘buff_var ‘and ‘buff_vec’ might be the same variable, causing inconsistency. So, I would suggest you change the ‘buff_vec’ to ‘buff_var’ and retry running.
Hope this helps you resolve the error.
0 comentarios
Ver también
Categorías
Más información sobre Surrogate Optimization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!