Input user data into Surrogate Optimization Function

조회 수: 1 (최근 30일)
Jadon Latta
Jadon Latta 2021년 5월 31일
답변: Alan Weiss 2021년 6월 2일
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)
clear;
clc;
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,...
upperBounds,intcon,[],[],[],[],options);
% Clear variables
clearvars options
% disp(solution);
% disp(objectiveValue);
fill = solution(1);
cap = solution(2);
cost = objectiveValue;
print(fill,cap,cost);
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.

채택된 답변

Alan Weiss
Alan Weiss 2021년 6월 2일
To pass extra parameters see Passing Extra Parameters.
Alan Weiss
MATLAB mathematical toolbox documentation

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by