question

Francesco V2 avatar image
0 Likes"
Francesco V2 asked tannerp commented

How to manage table by writing code in Flexsim?

file-corretto-professore-autosave-3.fsmHello everybody, I'm Francesco from Italy. I' m going to explain you my problem. I have to manipulate tables in Flexsim and I have to write an alghorithm with the goal to take same data in Flexsim from the table, find element in common in some part of the table. ecc. Is quite difficult to explain here, I would like to know if there is someone that could write me, please write me:[email protected]

Thank you

FlexSim 19.2.0
write an alghorithm in flexsim
· 9
5 |100000

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

Braydn T avatar image Braydn T commented ·
@Francesco V2

I will send you an email, but it is best if you post here so that others can benefit from your question.

0 Likes 0 ·
Francesco V2 avatar image Francesco V2 commented ·

I have this problem if someone could help me. I'm going to try to explain you with more details and I will try to write a good post, in a case someone in future will need. I have two tables:

First table: ListadoOF_Lectura

Second table:componentes.png

In the first table there is a column called codProducto, in the second table there are two column:the first called "codProducto" and the second called "codComponente".In the second table for each product there is a list of component. What i want to do is:

1 I want to compare each product of the list with the others product of the list for finding how many component in common each product has with others.

example: Prod1=(1,2,3); Prod2=(2,3,4);Prod3=(1,2,3). The Prod1 has 4 component in common.I want to obtain the total number. I want that the total number is showed in the table ListadoOF_Lectura in the last column. I will show you the code that i have, I'm a newbie in coding, so, any advice is good for me. This is the code:

0 Likes 0 ·
code.png (47.4 KiB)
componentes.png (35.3 KiB)
Francesco V2 avatar image Francesco V2 commented ·

any advice is welcomed, thank you

0 Likes 0 ·
tannerp avatar image tannerp Francesco V2 commented ·

Hi @Francesco V2,

One piece of advice I have would be to create a simple example that does exactly what you need. It sounds like this is what you're looking to do:

1) Starting with the first product in one table, compare the number of the product (i.e. "1") to the other table, one row at a time.

2) Count the instances that match the number of the product (i.e. "1") in the other table.

3) Record the count of instances that match.

You can correct me if I'm wrong. If this is what you're hoping to do, then I recommend Excel or Google Sheets. This is relatively easy in spreadsheet software; is there a reason why you need to do it using FlexSim rather than using Excel and then importing the table into FlexSim?

0 Likes 0 ·
Francesco V2 avatar image Francesco V2 commented ·

Thank you tanner.p. I'm not sure if is the same, I will explain better to you to avoid misuenrstanding:

In the second table we have:

codProd codComponente
1 2
1 3
1 4
2 3
2 4
2 5
2 6

The product 1 is composed by (2,3,4) components. The product 2 is composed by (3,4,5,6).

The two products have in common 2 components. And for example I would like to take the product 1 and compare with the other products and calculate the sum of components in common.

I hope is more clear now.

0 Likes 0 ·
tannerp avatar image tannerp Francesco V2 commented ·

@Francesco V2,

Thanks for the clarification. There are many permutations of products possible - do you intend to check each product against all other products?

For example, if I'm looking at product 1, which has components (2,3,4), am I going to check product 2, 3, 4, ... N to see if they all have 2, 3, or 4?

Or am I checking products 1 and 2, products 3 and 4, products 5 and 6, etc.?

0 Likes 0 ·
Francesco V2 avatar image Francesco V2 commented ·

In the code I have used the function Table.query for exctracting data from the table, but I m not sure if is correct.

0 Likes 0 ·
Show more comments

1 Answer

·
tannerp avatar image
0 Likes"
tannerp answered tannerp commented

Here's an idea, @Francesco V2:

You can use a table query for this. I've attached an example model that aggregates the products according to the component. The query selects components, aggregates products, groups by component and orders by component. Hopefully this allows you to then use the array for whatever you need. You could also copy it into another column if you wanted, but I don't know how it would best fit with the other data as there are fewer entries in the aggregated table.

table-query.fsm


table-query.fsm (23.9 KiB)
· 6
5 |100000

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

Francesco V2 avatar image Francesco V2 commented ·

Hello @tanner.p, thank you for your advice bit is not what exactly I wanted to say. I wil try to explain you better with an example:

Product Component
1 1
1 2
1 3
2 1
2 2
2 4
3 1
3 2
3 5

I would like to find the number of products in common that each product has with all the other products. For this example we have:

Product 1:

has in common 2 components with product 2

has in common 2 components with product 3

The total sum is 5 products in common, I'm interested on the number of components in common.

0 Likes 0 ·
Braydn T avatar image Braydn T Francesco V2 commented ·

@Francesco V2

I think there are better pieces of software to use than flexsim for this, but the two ways that you could do this are what tanner said, which is using table queries, or writing complete custom code. I think you should stick with table queries.

0 Likes 0 ·
Francesco V2 avatar image Francesco V2 Braydn T commented ·

Thank you, I would like to try to do it on Flexsim, I have attached an example but I'm not sure if the code is correct, I have used the table queries.

0 Likes 0 ·
Francesco V2 avatar image Francesco V2 commented ·

example-commoncomponents.fsm

Hello @tanner.p, I have tryed to write a code using a table query but I don't know which kind of mistake i did it. I have used the example that you sent me some weeks ago.

Francesco

0 Likes 0 ·
tannerp avatar image tannerp Francesco V2 commented ·

@Francesco V2,

Thanks for clarifying that you wanted the sum of the components in common and not the actually component numbers. I wrote a script that will do this in the attached model, but make sure you clear the output table (Global Table 3) before you run the script. I wasn't sure how to add the logic to separate each count by product number, but I'm sure you could get that worked out. You can use this as an example to hopefully achieve what you need.

francesco-help.fsm

0 Likes 0 ·
francesco-help.fsm (24.2 KiB)
tannerp avatar image tannerp Francesco V2 commented ·

@Francesco V2

Here's an updated model that doesn't require resetting the table to be all zeros in between running scripts:

francesco-help-1.fsm

0 Likes 0 ·

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.