Optimization FlowShop Problem- Error Received
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have the following code for a flow shop problem.
In the following part
[optimalSequence, minMaxTardiness] = fmincon(objectiveFunction, initialSequence, A, b, Aeq, beq, lb, ub, [], options);
I get the following error. But the lb is basically a matrix on 1x20 with "1" and ub is the same with "20".
These are also reflected in the matlab data. Thanks for the help.
ERROR
Initial point X0 is not between bounds LB and UB;
FMINCON shifted X0 to strictly satisfy the bounds.
Unrecognized function or variable 'numJobs'.
completionTimes = zeros(numMachines, numJobs);
Error in codev2>@(sequence)calculateMaxTardinessWithSequence(sequence,processingTimes,dueTimes,sequenceDependentSetupTimes,numMachines) (line 17)
objectiveFunction = @(sequence) calculateMaxTardinessWithSequence(sequence, processingTimes, dueTimes, sequenceDependentSetupTimes, numMachines);
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
CODE
++
clc; clear all; close all;
% Number of machines and jobs
numMachines = 5;
numJobs = 20;
% Generate random processing times for jobs on machines
processingTimes = randi([1, 10], numMachines, numJobs);
% Generate random due times for each job
dueTimes = randi([20, 30], 1, numJobs);
% Generate random sequence-dependent setup times between products
sequenceDependentSetupTimes = randi([1, 5], numJobs-1, 1);
% Objective function for fmincon
objectiveFunction = @(sequence) calculateMaxTardinessWithSequence(sequence, processingTimes, dueTimes, sequenceDependentSetupTimes, numMachines);
% Initial guess (random permutation of jobs)
initialSequence = randperm(numJobs);
% Bounds for the decision variables (permutations of jobs)
lb(1: numJobs) = 1;
ub(1: numJobs) = numJobs;
% Constraints (none in this case)
A = [];
b = [];
Aeq = [];
beq = [];
% Use fmincon to minimize the objective function
options = optimoptions('fmincon', 'Display', 'iter', 'MaxIterations', 1000);
[optimalSequence, minMaxTardiness] = fmincon(objectiveFunction, initialSequence, A, b, Aeq, beq, lb, ub, [], options);
% Display the results
disp(['Optimal Sequence: ', num2str(optimalSequence)]);
disp(['Minimum Max Tardiness: ', num2str(minMaxTardiness)]);
% Function to calculate max tardiness with given sequence
function maxTardiness = calculateMaxTardinessWithSequence(sequence, processingTimes, dueTimes, setupTimes, numMachines)
completionTimes = zeros(numMachines, numJobs);
lostTimeDueToSetups = 0;
% Calculate completion times for each job on each machine based on the given sequence
for j = 1:numJobs
for i = 1:numMachines
currentJob = sequence(j);
if j == 1
if i == 1
completionTimes(i, currentJob) = processingTimes(i, currentJob);
else
completionTimes(i, currentJob) = completionTimes(i - 1, currentJob) + processingTimes(i, currentJob) + setupTimes(currentJob - 1);
lostTimeDueToSetups = lostTimeDueToSetups + setupTimes(currentJob - 1);
end
else
if i == 1
completionTimes(i, currentJob) = completionTimes(i, sequence(j - 1)) + processingTimes(i, currentJob);
else
completionTimes(i, currentJob) = max(completionTimes(i, sequence(j - 1)), completionTimes(i - 1, currentJob)) + processingTimes(i, currentJob);
end
end
end
end
% Calculate tardiness for each job
tardiness = zeros(1, numJobs);
for j = 1:numJobs
tardiness(j) = max(0, completionTimes(numMachines, j) - dueTimes(j));
end
% Calculate maximum tardiness
maxTardiness = max(tardiness);
++
0 commentaires
Réponse acceptée
Alan Weiss
le 15 Fév 2024
You don't pass numJobs into your calculateMaxTardinessWithSequence function:
function maxTardiness = calculateMaxTardinessWithSequence(sequence, processingTimes, dueTimes, setupTimes, numMachines)
Alan Weiss
MATLAB mathematical toolbox documentation
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!