Please help me to code the entity geneator

1 次查看(过去 30 天)
I need to gerenrate 100 products from the entity generator out of which 25 good and 75 bad prodcuts, then route good prodcuts and bad products through the entiry output switch.
Please help me to code the entity geneator to generate exactly 25 bad and 75 good ones.

回答(1 个)

Poorna
Poorna 2024-2-9
Hi Yedhuraj,
I see you are trying to simulate a pipeline where you are required to generate 75 good products and 25 products randomly and route to their individual bins.
From the model shared, I can see that you have implemented the bagging part correctly, but you couldn’t generate the entities as per the specification.
To generate 75 good products and 25 bad products randomly you could follow the below steps:
  • Entity Generation:
Create two “Entity Generator” blocks, one to generate good products and one to generate bad products. Set the ‘Generation method’ to ‘Time-based’. Also set the appropriate attributes.
  • Random Number Generation:
Create a MATLAB function block to randomly generate numbers from 1 to 100. You could use “persistent” variables to keep track of what numbers have been generated already and what needs to be generated yet. A sample code is provided below:
function y = fcn()
persistent idx;
persistent rand_values;
if isempty(idx) || isempty(rand_values)
idx = 1;
rand_values = randperm(100);
end
y = rand_values(idx);
idx = idx + 1;
  • Entity Routing:
Utilize an "Entity Input Switch" block to direct the flow of good and bad entities. Set the switching criteria to “From control port.
  • Control Logic:
Implement a "Compare to Constant" block to evaluate the output from the MATLAB Function block against the value of 25. Following this comparison, employ a "Message Send" block to convey the result to the control port of the "Entity Input Switch" block. It is important to note that the output from the "Compare to Constant" block cannot be directly connected to the "Entity Input Switch" block and must be routed through a "Message Send" block.
By following the above steps, you should be able to achieve your goal.
To know more about the above-mentioned blocks, refer to the following documentation:

类别

Help CenterFile Exchange 中查找有关 Discrete-Event Simulation 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by