What does this code mean?

4 ビュー (過去 30 日間)
Navya Anand
Navya Anand 2018 年 5 月 30 日
回答済み: Krishna Akella 2018 年 12 月 10 日
I'm trying to build a SimEvents model, where entities are assigned attributes that will determine whether they pass through a second loop in the model, or are terminated immediately.
I have the following code (See below) from my supervisor, but can't understand what it means. Any help is appreciated!
___
Found in Entity Generator (Entity Generation tab):
% Pattern: Repeating Sequence
persistent SEQ;
persistent idx;
if isempty(SEQ)
SEQ = [1 1 1 1 inf];
idx = 1;
end
%if idx > numel(SEQ)
% idx = 6;
%end
x = SEQ(idx);
idx = idx + 1;
dt=x;
___
Found in Entity Generator (Event Actions tab):
% Pattern: Repeating Sequence
persistent SEQ;
persistent idx;
if isempty(SEQ)
SEQ = [2 2 2 2 2];
idx = 1;
end
if idx > numel(SEQ)
idx = 1;
end
entity.Route = SEQ(idx);
idx = idx + 1;
Thank you!
  2 件のコメント
Rishabh Rathore
Rishabh Rathore 2018 年 5 月 31 日
I could explain what every single line is doing but won't be able to explain the utility of the code as other code (i.e. context) is not given.
Navya Anand
Navya Anand 2018 年 6 月 1 日
Ah ok, thank you. Would you be able to explain how I can enter a code such that the nth entity generated has a specific attribute? e.g. 60% attributes proceed down Path1, whilst 40% proceed down Path2 (to be split later on in the model)?
Thank you, Navya

サインインしてコメントする。

回答 (2 件)

Jan
Jan 2018 年 5 月 31 日
編集済み: Jan 2018 年 5 月 31 日
The first code replies a dt=1 for the first 4 calls and dt=inf for the fifth call.
The second code sets the variable entity.Route to 2 in all 5 calls.
  3 件のコメント
Jan
Jan 2018 年 6 月 1 日
dt is the output of the first code. The posted code does not contain any information which explains, how the value is used in the calling function. In the first call the code performs:
dt = 1
Do you see, that it is impossible to use this information to clarify the meaning of dt?
Navya Anand
Navya Anand 2018 年 6 月 7 日
Yes I can see that - thank you for your help! :)

サインインしてコメントする。


Krishna Akella
Krishna Akella 2018 年 12 月 10 日
Hi Navya,
In the Entity Generator, Entity Generation tab, dt is the amount of time the generator has to wait before it generates the next entity. So it is the delta time to next entity. Or the inter-generation time.
If I understand correctly, you want 60% entities to go down path 1 and 40% to go down path 2. Assuming entity.Route is what is deciding the route later on in your model, you can draw a uniform random number between 0 and 1. If the value is less than or equal to 0.6, then set entity.Route = 1. Else, set entity.Route = 2.
- Krishna

カテゴリ

Help Center および File ExchangeDiscrete-Event Simulation についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by