question

sara avatar image
0 Likes"
sara asked sara commented

Read a percentage of the data in the source

Hello everyone,

Is there any way to read just a percentage of the data we are having in the source, for example at each time I run the model, I wanted the source to generate a random 7% of the data I inserted in the excel sheet (as an arrival schedule).

Thank you!

flexsim 21.2.0source data
· 2
5 |100000 characters needed characters left characters exceeded

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

@Felix Möhlmann Could you please help ?

0 Likes 0 ·

Hi @sarah.s4, was one of Felix Möhlmann's or Joerg Vogel's answers helpful? If so, please click the red "Accept" button at the bottom of the one that best answers your question. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered sara commented

This is somewhat of a "hacky" solution to the problem:

First, create a copy of the "schedule" node in the tree of the source.

- Edit: Change the schedule in the source to what you want to use as the "base" schedule, where the entries are taken from.
- Right click on source -> Explore Tree
- The "schedule" node is located under "variables".
- Click on the node and hit space bar to insert an empty node after it.
- Then copy the schedule node (ctrl-c), click on the new node and paste it (ctrl-v) in there.
- Finally rename the new node to "schedulecopy".

1629913690893.png

Create an "On Reset" trigger for the source and paste the following code in there

/**Custom Code*/
Object current = ownerobject(c);

// Replace last schedule with copy of complete schedule
treenode schedule = current.find(">variables/schedule");
schedule.destroy();
treenode schedulecopy = current.find(">variables/schedulecopy");
schedule = createcopy(schedulecopy, schedulecopy.up);
schedule.name = "schedule";

// How many rows should be deleted?
int NumRows = schedule.subnodes.length;
int NumDelRows = NumRows*0.93;

// Delete random entries until down to 7% (remaining number is rounded up)
int rand;
for(int index = 1; index <= NumDelRows; index++)
{
    rand = duniform(1, schedule.subnodes.length, 0);
    schedule.subnodes[rand].destroy();
}

// Re-insert the column names
if(schedule.subnodes.length > 0)
{
    for(int index = 1; index <= schedule.subnodes[1].subnodes.length; index++)
    {
        schedule.subnodes[1].subnodes[index].name = schedulecopy.subnodes[1].subnodes[index].name;
    }
}

Each time you reset the model, this code will delete the "schedule" node and replace it with a copy of the original table (schedulecopy). Then it deletes subnodes (entries) until only the desired number of entries remain. (I delete 93% of nodes instead of adding a random 7% so the order stays the same and no duplicates can occur).

Be sure to uncheck the "Repeat Random Streams" option under "Statistics". Otherwise the chosen entries will always be the same.

ChooseRandomFromSchedule.fsm


· 35
5 |100000 characters needed characters left characters exceeded

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

@Felix Möhlmann Than you for the quick answer. but as per your model, I added the number of items in the arrival schedule from 7 to 30. what is needed is to generate only 7% of the data (30*0.07 =2.1) which should be around only 2 items.

-Also I wanted to ask if this could be done in another way, for example with labelling the vials, to have a conveyor after the source (not a queue), and to have a decision point, after generating all the vials, this decision point (or a sensor) will give a random number between 1-100 for each vial, if the number is less than 93, the label on this vial will be 2 ( and go to conveyor 2), if the number is more than 93 it is labelled as =1 (go to conveyor 1). Thank you

The model: chooserandomfromschedule1.fsm

0 Likes 0 ·
When you edit the "base" schedule, you have to copy the node into the "schedulecopy" as described in my post, because that is where the reset trigger pulls the entries from. In my model, this node contains 100 entries, resulting in seven entries being chosen to remain in the source schedule. If you only change the schedule in the source, the changes will simply be overwridden on the next reset.

Of course you could use the "Set Label By Percentage" option in a decision point trigger (under "Data") and then send the items to different directions based on the label. By using a statistical distribution you will end up with variance in how many items end up being chosen due to its randomness. With only 30 entries as a base you will probably frequently end up sending with fewer or more than two items.


You could count how many items were already selected and stop selecting further ones if the quota was met or start forcing the selection when you're nearing the end of the table (Write down the total number of entries in a label to compare the number of selected items to). This in turn would introduce a bias towards earlier entries and those at the very end of the schedule though, which is why I ended up with the solution above.


0 Likes 0 ·
sara avatar image sara Felix Möhlmann ·

@Felix Möhlmann

for the attached "model1" I have used the same source you presented but adding 2 conveyor destinations. I have a question on the source:

How did you add 100 items in the schedulecopy node, and how can I find its table? also, is the code you did in the source trigger, does this create the arrival schedule shown in the source itself (that contains 7 items)? For this model, how can I let the other 93 items to go to conveyor2? This could work without the decision point.

BUT for the model2 attached, I added 100 items to the source and a decision point shown on the first conveyor, with deleting the source trigger. I didn't know how to add the details on the decision point where I need it simply to send 7% of these items to conveyor 1 (the processor) and the other 93% to conveyor 2. I tried to add the label for the percentage but it did not work, so I added a new decision point. Can you assist in this, please, or send me the updated one? Thank you

model1: model1.fsm

model2: model2.fsm

0 Likes 0 ·
model1.fsm (41.5 KiB)
model2.fsm (42.3 KiB)
Show more comments
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered

https://answers.flexsim.com/questions/88795/como-crear-elementos-desde-la-fuente.html

This question seems to request a similar answer. There are two approaches dealing with a fixed ratio randomly occurring. A scheduled source is fine, but any deviation is occurring relative static of a repeating cycle.
The table bound approach updates the actual drawn items and their currently distribution. It has got a mechanism to update chances to realize the fixed ratio.
The list approach creates a lot which matches with the fixed ratio and chooses randomly entries from the List. Once the list gets empty (lot is processed) the list is filled up again.

5 |100000 characters needed characters left characters exceeded

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.