MATLAB Answers

Input user data into Surrogate Optimization Function

1 view (last 30 days)
Jadon Latta
Jadon Latta on 31 May 2021
Answered: Alan Weiss on 2 Jun 2021
I need to be able to pass some data of my own, that is inputted by a user, into the surrograteopt function in order to have it work properly. Here is the code I have: (most of it, I removed a lot of the code within the function because it is not useful in this scenario. The function works perfectly, until I added these inputs)
addpath ../
nvar = 2;
upperBounds = [10,10];
lowerBounds = [1,1];
intcon = 1:nvar;
inputs = inputCaller();
[unitCostLaborFile, unitCostLaborPath] = uigetfile('*.xlsx','Select file with Welding Unit Costs for labor');
[unitCostFile, unitCostPath] = uigetfile('*.xlsx','Select file with Welding Unit Costs for equipment');
[weldSpeedsFile, weldSpeedsPath] = uigetfile('*.xlsx','Select file with Welding Speeds from WPS');
% Set nondefault solver options
options = optimoptions('surrogateopt','MaxFunctionEvaluations',10,'PlotFcn',...
% Solve
[solution,objectiveValue] = surrogateopt(@objConstrFcn,lowerBounds,...
% Clear variables
clearvars options
% disp(solution);
% disp(objectiveValue);
fill = solution(1);
cap = solution(2);
cost = objectiveValue;
function f = objConstrFcn(optimInput, inputs, unitCostLaborFile, unitCostFile, weldSpeedsFile)
startDateInput = inputs(1);
endDateInput = inputs(2);
pipeSize = inputs(3);
pipeThickness = inputs(4);
welds = inputs(5);
workHours = inputs(6);
travelTime = inputs(7);
weight = inputs(8);
overhang = inputs(9);
qaqc = inputs(10);
useTackRig = inputs(11);
Does anyone know how I would make this possible? This is pretty integral to my program, as without these user inputs I won't get the proper utilization of this program.

Accepted Answer

Alan Weiss
Alan Weiss on 2 Jun 2021
To pass extra parameters see Passing Extra Parameters.
Alan Weiss
MATLAB mathematical toolbox documentation

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by