Dynamic Variable with Two Values Inside a While Loop

How to express a dynamic variable with two values or more inside a while loop:
An example of what I mean by a dynamic is a time of a job in a work shop at one of the machines so (Tij) T is for Time i is the job identification number, where i=(1,2,3) as an example j is the machine identification number, where j=(1,2,3,4,5,6) as an example
So when I say: T35 is the time of the 3rd job in the 5th machine. T11 is the time of the 1st job in the 1st machine. T35 & T11 can occur at the same time, let say both occurred when time = 1:00pm
My question how create a while loop that will finish all the three (3) jobs in all the six (6) machines. Also let say each machine takes 3 minutes to complete a job and it can only treat one job at a time.
I not sure if this dynamic variable can be an array or a structure or something else.

回答(1 个)

Don't see that you need any loop at all. Simply populate a nJobMax by nMachines array with the appropriate start time values and accumulate total duration by column given the job duration as being fixed.
If the assignment is N jobs to the machine at one time to be processed sequentially, then it's even more trivial of just being that number*duration/job plus the starting time.
The new datetime class with duration variables should make this pretty simple to code.

6 个评论

Thank You dpb for your reply.
I though of that too at first, it might work, but I am afraid it will Not fully describe my problem, because my actual problem is way much more complicated than what described in my inquiry.
If you are interested to know more details about my problem, please do not hesitate to reply.
Meanwhile I will learn how create such a 2-denominational array.
Thank you again. I look forward to hearing from you.
Well, we can only answer the questions as asked. I wouldn't expect it to matter much on the other complications of how one might generate the actual elements in the array; one presumes this is some sort of MC simulation?
Greeting dpb,
Thank you for your last reply, I check what is MC Simulation, but I am afraid that I am not familiar with it.
I was Woundering if you can help me to solve it using the matlab editor.
Below I explained the previous problem with a suggested solution and with the outcomes I am expecting.
Imagine we have three jobs i=(1,2,3), and Two machines j=(1,2). the duration for each job in each machine is expressed in this matrix D(i,r)=[4 7; 3 8; 4 7].
I want a program of for or while loops to show me the time in-which each job starts & finishes at each machine.
The Program may look like this:
time=0
for i=1:3
for j=1:2
TS(i,j)=time+1 %%Staring time for job i at machine j
TF(i,j)=T(i,j) + D(i,j) %%Finishing time for job i from machine j
time=TF(i,j)
end
end
The Expected Results:
TS(1,1)=1
TF(1,1)=6
TS(1,2)=7
TF(1,2)=14
TS(2,1)=15
TF(2,1)=18
TS(2,2)=19
TF(2,2)=27
TS(3,1)=28
TF(3,1)=32
TS(3,2)=33
TF(3,2)=40
Once again I am not sure if the variables TS(i,j) & TF(i,j) are structures or Arrays inside theses two loops.
Thank you in-advance.
"what is MC Simulation"
Monte Carlo simulation...I was presuming probably you would be simulating a large number of these individual elements to evaluate from some distribution of job lengths to evaluate overall system statistics.
If the data are static as you show and TS(i+1)=TS(i)+D(i) for each job i, then I don't see how your expected TF(1)=6? If TS=1 and D=4, the TF=1+4 = 5 it would seem. Where's the other hour come from to get 6?
But, as I noted before
>> D=[4 7; 3 8; 4 7];
>> cumsum([1 1;D])
ans =
1 1
5 8
8 16
12 23
>>
is the cumulative end times from your above D; the start of the next is the end of the previous. Again, this is based on what you've described so far; the "how" to get the desired 6 instead of 5 for the first end time is insolvable from the description so far (unless it is just a typo???).
Dear dpb
Thank you for your prompt reply and your notice, My apologies I missed typed the matrix of D It should be: D=[5 7;3 8;4 7]
In the loops the indexes return the selected value from the D matrix and substitute it in D(i,j) in the loop. for example if:
i=1,j=1
D(i,j)=D(1,1)=5
Also you are right about simulating large number of jobs! :)
I am working on optimization problem for a Job Shop Scheduling Problem, more specifically know as Hoist Scheduling Problem (HSP).
I know that matlab has a package for HSP https://www.youtube.com/watch?v=sRN6xxexn0Q But only for one hoist, my problem is with 5 hoists and it is big size problem.
I do not know if it will possible to do my HSP on MC Simulation?
So I am planning to use the variable T(i,j) as basic variable to obtain the time for each operation (Start & Finish) to build my simulation.
Of course there are other operation types (other than that start & finish), but I guess it will take time to explain all about my HSP here.
I read many Q&A on mathworks.com, but I am afraid that I have not found how to code it. I guess it has to do with (structure, or cells, or Array, and eval command).
I really want to know how code this variable as one unit that is capable to enter loops, in order to program my full algorithm.
Once again I thank you for your reply. If you any ideas, I will be happy to hear them from you. But Please I want to know how to code T(i,j). Thank you in-advance.
Best Regards Alaa
Well, there are any number of examples of for loops, but the power in Matlab is in the vector operations. You'll probably want an outer loop for each of the trials, but look again at the solution above without looping that solves the time issue for all machines and all times for a given sampled duration dataset without needing any loops at all.
And, forget you've even heard of eval, there "there be dragons!" :)

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by