Please help me on this coding about nested loops

4 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 26 Jan 2021
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:
snr matlb
snr matlb on 26 Jan 2021
Edited: snr matlb on 26 Jan 2021
I explain my attempt because I will try to solve it by myself, so I just need to simplfy the loops.
Acually, I have 3 variables these are list.param2, list.param3 and list.param4.
I have to control each variable with some condition for example, jobs that have cond3 = 5 or cond3=8 has to be separated in terms of param2. These jobs must be separated by 60 sec.
But, I have to do this for each particle that I have 30 different particles and 8 different hour zones.
That is to say; each particle has 8 hourzones, and each hourzone have different number of jobs and I have to control jobs that are in the same particle and same hourzone if they have conflict.
  • For example, I have to check jobs that have cond3=5 or cond3=8 for make separation about times shared at param2 column in the list. for instance, lets check while cond1 = 1 and cond2 = 3. The new filtered table must be like that;
as you see that I filtered jobs that have cond3=5 or cond3=8 but, I just filtered just for cond1=1 and cond2=3. I will check this new table, then I will change only cond2, I will check again. Then when cond2 reaches to 8, I will change cond3 and then cond2 starts over.
But, I have to do this for all cond1 that the last one is 30, and cond2 in the each cond1.
I mean that while I am holding cond1=1, I have to filter all cond3=5 or cond=8 for different cond2=1 to 8. Then, I will check each jobs till cond2 reaches 8. When I finished all check for cond3=5 or cond3=8, I will change cond3 for example cond3=1 or cond3=2. When I finished all, I will increase the cond1=2 then whole process will be repetaed, then I will do this till I finish them when cond1=30.

Sign in to comment.

Answers (0)

Categories

Find more on Discrete Math in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!