MATLAB Answers

Nonlinear Optimization with 2 Variables, 1 variable is always equal limit

6 views (last 30 days)
Jadon Latta
Jadon Latta on 20 May 2021
Answered: Alan Weiss on 21 May 2021
We are currently working on a project that requires minimizing the cost of a welding projects by optimizing the amount of welders used for the project along with the amount of days the project takes. We are currently running into an issue where the amount of welders used is going to infinity, and will always equal whatever upper limit we set. Here is the equation we are optimizing, along with the constraints and the call to fmincon
clear;
clc;
x0 = [0 0];
% Possible Inputs %
deadline = 30;
upperBounds = [15 deadline];
% Set nondefault solver options
options = optimoptions('fmincon','PlotFcn','optimplotfvalconstr');
% Solve
[solution,objectiveValue] = fmincon(@objectiveFcn,x0,[],[],[],[],...
zeros(size(x0)),upperBounds,@constraintFcn,options);
% Clear variables
clearvars options
clc;
disp(solution);
disp(objectiveValue);
function f = objectiveFcn(optimInput)
% inputs but for now temp values
workHours = 10;
paidHours = 11;
weight = 15000;
overhang = 6;
qaqc = 2;
welderCost = 523.41;
helperCost = 467.32;
laborerSkilledCost = 467.32;
stabberCost = 450.87;
spacerO16Cost = 450.87;
operatorCost = 576.98;
foremanCost = 756.76;
strawBossCost = 643.35;
clampmanCost = 450.87;
qaqcCost = 678.24;
pipelayerCost = workHours * 124.54;
LOA = 175;
welders = optimInput(1);
days = optimInput(2);
constcrew = 8; % straw,foreman,2spacers,stabber,clampman,2operators
f = days*(welders * welderCost + welders * helperCost + (welders/3) * laborerSkilledCost...
+ foremanCost + strawBossCost + stabberCost + 2*spacerO16Cost + qaqc*qaqcCost...
+ clampmanCost + 2*pipelayerCost + 2*operatorCost + (welders*2 + constcrew + (welders/3) + qaqc)*LOA);
end
function [c,ceq] = constraintFcn(optimInput)
% Note, if no inequality constraints, specify c = []
% Note, if no equality constraints, specify ceq = []
eff = 5;
welds = 1000;
welders = optimInput(1);
days = optimInput(2);
c = [];
ceq = (welders*days*eff) - welds;
end
We would optimally like the equation to find the best balance between days and welders, not just maximize the amount of welders possible. Are we going about this optimization the wrong way, is there a better method?
EDITED TO ADD FULL CODE
  3 Comments
Jadon Latta
Jadon Latta on 20 May 2021
@Matt JHere is the entire program, our normal program using seperate functions to determine costs based on our database, we have filled in variables with random values instead, so that we dont have to include a excel sheet of data and multiple seperate functions. These functions all work perfectly, the problem isn't within them.
clear;
clc;
x0 = [0 0];
% Possible Inputs %
deadline = 30;
upperBounds = [15 deadline];
% Set nondefault solver options
options = optimoptions('fmincon','PlotFcn','optimplotfvalconstr');
% Solve
[solution,objectiveValue] = fmincon(@objectiveFcn,x0,[],[],[],[],...
zeros(size(x0)),upperBounds,@constraintFcn,options);
% Clear variables
clearvars options
clc;
disp(solution);
disp(objectiveValue);
function f = objectiveFcn(optimInput)
% inputs but for now temp values
workHours = 10;
paidHours = 11;
weight = 15000;
overhang = 6;
qaqc = 2;
welderCost = 523.41;
helperCost = 467.32;
laborerSkilledCost = 467.32;
stabberCost = 450.87;
spacerO16Cost = 450.87;
operatorCost = 576.98;
foremanCost = 756.76;
strawBossCost = 643.35;
clampmanCost = 450.87;
qaqcCost = 678.24;
pipelayerCost = workHours * 124.54;
LOA = 175;
welders = optimInput(1);
days = optimInput(2);
constcrew = 8; % straw,foreman,2spacers,stabber,clampman,2operators
f = days*(welders * welderCost + welders * helperCost + (welders/3) * laborerSkilledCost...
+ foremanCost + strawBossCost + stabberCost + 2*spacerO16Cost + qaqc*qaqcCost...
+ clampmanCost + 2*pipelayerCost + 2*operatorCost + (welders*2 + constcrew + (welders/3) + qaqc)*LOA);
end
function [c,ceq] = constraintFcn(optimInput)
% Note, if no inequality constraints, specify c = []
% Note, if no equality constraints, specify ceq = []
eff = 5;
welds = 1000;
welders = optimInput(1);
days = optimInput(2);
c = [];
ceq = (welders*days*eff) - welds;
end
Running this program will always give you the maximum bound of 15 welders, while making days as low as possible (13.3333 in this scenario). If we unbound the welders, it will put it into the 10000's of welders (will continue to run forever, we could set a lower bound of 1 for days, but it will just minimize days to 1, which is obviously not anything clsoe to realistic), just to make days as small as possible

Sign in to comment.

Answers (1)

Alan Weiss
Alan Weiss on 21 May 2021
Your problem has costs in terms of the problem variables of the form
cost = days*welders*positive + days*positive2;
Here positive and positive2 are positive constants. The constraint you have can be written
days*welders = positive3;
Therefore, your problem setup clearly has the minimal cost at the minimal value of days:
cost = positive3*positive + days*positive2;
The problem you experience is not a fault of the solution method, but of the problem definition.
To get a different result, you must give different costs.
Alan Weiss
MATLAB mathematical toolbox documentation

Community Treasure Hunt

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

Start Hunting!