Please help me on this coding about nested loops
3 次查看(过去 30 天)
显示 更早的评论
I have to give time delay all jobs in the dataset to make a separation. You can find the structure of the 'list' dataset at attachment.
cond1: represents particles (1-30), I have all particles in the Figure, but I show a part of it, it is too long to share.
cond2: represents hourzone (between 1-8), each hourzone have different number of jobs, but each particle has same number of jobs into the hourzone.
cond3: represents entry point of each job into the production line.
param1: entry time
param2: 1st time for check
param3: 2nd time for check
param4: 3rd time for check
param times are depended previous param. If any param2,3 or 4 is zero, it means that there is no passing line at that point for corresponding job.
list = % contains all data I need to check conflicts at oven line crossing point.
for p=1:30 % this is for ensuring check all particles in particle swarm opt. separately.
for h=1:8 % this is for ensuring check all jobs that are in the same hourzone.
checkgroup = []; % preparation for control loop
for i=1:100 % this is for reaching each job in the 'list'.
if list(i,'cond3') == 5 || list(i,'cond3') == 8
checkgroup(row) = list(i,:); %checkgroup holds jobs have common crossing point, so has to be checked for conflict and given delay.
end
end
checkgroup = sortrows(checkgroup, 6);
while k <= size(checkgroup,1)-1
l = k + 1;
while l <= size(checkgroup,1)
if abs(checkgroup(l,'param2') - checkgroup(k,'param2') >= 60)
%no delay
else
%giving delay
checkgroup(l,'param2') = checkgroup(l,'param2') + delay;
checkgroup = sortrows(checkgroup, 6);
k=0;
break
end
l=l+1;
end
k=k+1;
end
checkgroup = []; % preparation for new control loop
for i=1:100
if (%different conditions)
checkgroup(row) = list(i,:); %checkgroup holds have common crossing point, so has to be checked for conflict and given delay.
end
while k <= size(checkgroup,1)-1
l = k + 1;
while l <= size(checkgroup,1)
if abs(checkgroup(l,'param3') - checkgroup(k,'param3') >= 60)
%no delay
else
%giving delay
checkgroup(l,'param3') = checkgroup(l,'param3') + delay;
checkgroup = sortrows(checkgroup, 6);
k=0;
break
end
l=l+1;
end
k=k+1;
end
%% I have to use this control loop (for i=1:100) 5 more times to check all conflicts at each crossing point.
%% If I use just first for i=1:100 loop I had to define 5 more checkgroup1,2...5 list to check each conflict group separately.
end
end
How to filter the grouped data to check conflicts among the corresponding jobs? Do I need to use nested loops (for look for particle, hourzone and jobs_id), that is what I am planing to do, or is there an efficient way to do it except my algorithm that I share with you in the question part?
**As you noticed, 3 "for loop" works mainly and 2 nested "for-loop" OR 2 "while loop" (I have not decided yet, "while" probably) will be employed to compare jobs time and controlling for giving delay. This reduces algorithm performance.
5 个评论
Stephen23
2021-1-26
Your explanation is not clear.
You are trying to explain your attempt, rather than what you are actually trying to achieve:
As far as I understand it, you have several independent variables, and you want to process each unique combination of those variables. Is that correct? Perhaps you are trying to do something like this:
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Math 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!