Lazarus

Programming => General => Topic started by: Jonvy on October 03, 2022, 04:31:07 pm

Title: How to show product routing from database to program?
Post by: Jonvy on October 03, 2022, 04:31:07 pm
Hello all,

In database, I have a table t_simo saved the prodcut routing information, each row in the table means one step.
Column et_modeop means the current product step, column et_modeop_pere means the step before current step.
If  et_modeop_pere is null, this row means the beginning of the product step.

Product should go according to this table.
The target is to show the product routing in program, like the attachment drawing, it is what I what to show.

In some point, the product can go to different way, such as point 8685 to 8499, 8685 to 8555, it means product can go to station 8555 or 8599(these 2 are same function machine).Same situation as point 8865 to 8525 or 8865 to 8579.
Final station are 8531 and 8585.
All these process step also can be find in table t_simo.

I just don't know how to analysis this table t_simo and make it show in program, can anyone give me some ideas?


Thanks,
Jonvy
Title: Re: How to show product routing from database to program?
Post by: BrunoK on October 03, 2022, 04:51:40 pm
If you provided a testable .csv / .txt file for [et_modeop, et_modeop_pere] array, maybe one might help you.
In general, throwing  screen captures to the forum is probably not going to stimulate anybody to try to make suggestions.
Title: Re: How to show product routing from database to program?
Post by: Zvoni on October 04, 2022, 10:08:30 am
With SQL you could do a "Count" on the second column. That way you would see if for any current steps they may have the same parent

That's just out of my sleeve. Would have to analyze further
Title: Re: How to show product routing from database to program?
Post by: Jonvy on October 04, 2022, 03:51:16 pm
If you provided a testable .csv / .txt file for [et_modeop, et_modeop_pere] array, maybe one might help you.
In general, throwing  screen captures to the forum is probably not going to stimulate anybody to try to make suggestions.

OK, here I attach the CSV file, also in the file, I add 2 part no.,Part number 100458 and 171995(with different value in et_nomen), id_simo is not null id segment in table.
Title: Re: How to show product routing from database to program?
Post by: Zvoni on October 04, 2022, 04:19:37 pm
Code: SQL  [Select][+][-]
  1. SELECT DISTINCT et_nomen,et_modeop, COUNT(et_modeop_pere) AS Cnt FROM t_simo_Part100458_Part171995 GROUP BY et_nomen,et_modeop
  2.  
The Problem i see: How to find out, if the two processes meet again into a single one (Say "packaging" at the end of assembly lines)

EDIT: After thinking about it: How about turning it around?
Currently you have a step with its "parent"
Have you thought about:
You have current step, and in the second column you have the "next" step
That way each "current" step would propagate the next step, meaning: If you have two consecutive steps which have the same et_modeop, then it's a split.
If two "threads" have the same "next"-step they meet again
Title: Re: How to show product routing from database to program?
Post by: dseligo on October 04, 2022, 04:26:09 pm
I just don't know how to analysis this table t_simo and make it show in program, can anyone give me some ideas?

Are you asking how to do visual representation of your data only or you need some additional operations on analyzed data as well?
Do you already have solution for displaying data?
Title: Re: How to show product routing from database to program?
Post by: Jonvy on October 04, 2022, 04:54:27 pm
I need more support for  visual display the data, currently I can draw shape and show station text, but I don't know how to link station with arrow line.
Especially at split point.
Title: Re: How to show product routing from database to program?
Post by: Zvoni on October 04, 2022, 05:42:43 pm
I need more support for  visual display the data, currently I can draw shape and show station text, but I don't know how to link station with arrow line.
Especially at split point.
And there’s your problem: you‘re looking back for each current step, instead of forward (see my alternative approach)
Title: Re: How to show product routing from database to program?
Post by: Jonvy on October 07, 2022, 06:19:49 am
I think firstly I can quere distinct value from column et_modeop, so I can get 36 steps, this means it needed to drawing 36 circles on the form.
And the database has 40 records means totally 40 arrow lines needed to connected between them.
But how to arrange the layout in the form for 36 circles?It  is difficult.Especially circles after split point(point 8685, step 24)?
Title: Re: How to show product routing from database to program?
Post by: Zvoni on October 07, 2022, 09:44:52 am
Wrong. You have to walk singlestep through et_modeop, checking first if it has more than one NEXT step (I'm coming from my approach. Your approach by looking back will not work).
If it has one next step, draw your shape and an arrow right of it pointing to the next step (which is not painted yet)
If it has more than one step it's a split.
That way you'll know that the next step(s) have to be painted with a vertical offset
Title: Re: How to show product routing from database to program?
Post by: dseligo on October 07, 2022, 12:29:21 pm
What in reality represents these 'steps' (8685, 8499, 8685, 8555, ...)?
You mention 'station' and 'same function machine'.

But, if they are same function machine, why after steps 8499 and 8555 doesn't go back to one machine?

Is there a chance of repeating machine (i.e. step 8451, 8453 and then again 8451 for some additional operation after 8453)?
Title: Re: How to show product routing from database to program?
Post by: Zvoni on October 07, 2022, 12:37:35 pm
What in reality represents these 'steps' (8685, 8499, 8685, 8555, ...)?
You mention 'station' and 'same function machine'.

But, if they are same function machine, why after steps 8499 and 8555 doesn't go back to one machine?

Is there a chance of repeating machine (i.e. step 8451, 8453 and then again 8451 for some additional operation after 8453)?
Think "assembly-line" in a manufacturing plant (e.g. automotive production-line)
Title: Re: How to show product routing from database to program?
Post by: BrunoK on October 07, 2022, 12:56:02 pm
What fails me is that there is no way, in the .csv file data supplied, to determine that the graphic steps in 29 to 30 can be permuted. Each  has only one et_modeop_pere so it is not possible to know if an et_modeop can go to an alternative et_modeop thru the et_modeop_pere relation.

Saying an et_modeop can go to an alternative et_modeop means you have to build a down line from et_modeop_pere to its et_modeop. That would be best done with specialised class being fed from the source data by et_nomen identity (product nr ?).
Title: Re: How to show product routing from database to program?
Post by: dseligo on October 07, 2022, 01:11:28 pm
What fails me is that there is no way, in the .csv file data supplied, to determine that the graphic steps in 29 to 30 can be permuted. Each  has only one et_modeop_pere so it is not possible to know if an et_modeop can go to an alternative et_modeop thru the et_modeop_pere relation.

There are two entries with et_modeop 8585, one has et_modeop_pere 8525 and the other one has et_modeop_pere 8579.
Title: Re: How to show product routing from database to program?
Post by: BrunoK on October 07, 2022, 01:16:02 pm
There are two entries with et_modeop 8585, one has et_modeop_pere 8525 and the other one has et_modeop_pere 8579.
Missed that, will take a further look.
Title: Re: How to show product routing from database to program?
Post by: Zvoni on October 07, 2022, 01:45:27 pm
What fails me is that there is no way, in the .csv file data supplied, to determine that the graphic steps in 29 to 30 can be permuted. Each  has only one et_modeop_pere so it is not possible to know if an et_modeop can go to an alternative et_modeop thru the et_modeop_pere relation.

Saying an et_modeop can go to an alternative et_modeop means you have to build a down line from et_modeop_pere to its et_modeop. That would be best done with specialised class being fed from the source data by et_nomen identity (product nr ?).
Bruno, that's why i said, his mistake is "looking back".
Look at my approach (looking forward)
Title: Re: How to show product routing from database to program?
Post by: alpine on October 07, 2022, 02:21:17 pm
Before engaging with such a problem the OP must give more information about it. The two columns define a graph, presumably directed, but no more info is available.
Can there be loops? Obviously the start node is the first one. Are there terminal nodes? Are there other restrictions?

The trivial solutions:
Put nodes around a circle, connect them with a straight connectors, or
Put nodes in a line, connect them with arc connectors with a height proportional to the relative distance between nodes.

Other layouts will require things like topological sort of the nodes. A bit of graph theory will help here.
Title: Re: How to show product routing from database to program?
Post by: Jonvy on October 08, 2022, 08:17:04 am
Before engaging with such a problem the OP must give more information about it. The two columns define a graph, presumably directed, but no more info is available.
Can there be loops? Obviously the start node is the first one. Are there terminal nodes? Are there other restrictions?

There is no loops, only one directly,from beginning to the end.
For the terminal nodes, should judge from data, if one value only appears in column et_modeop, not in et_modeop_pere, then this node is terminal nodes.
No other restrictions.
Title: Re: How to show product routing from database to program?
Post by: Jonvy on October 08, 2022, 08:55:33 am

Bruno, that's why i said, his mistake is "looking back".
Look at my approach (looking forward)

Hello Zvoni,
Actually for this process routing graph, I should look both backwards and forward.
For the 1st point, I must find in column et_modeop_pere the value is null, so node 8251 in et_modeop is the 1st point(1st product process).
Then I'll check 8251 in column et_modeop_pere, to find the corresponding node 8253 in et_modeop, then 8253 is the 2nd point(2nd product process).

Follow this idea, next step to check 8253 in et_modeop_pere, find 8255 in et_modeop,8255 is the 3rd point.

In this way,can find 1st and 30th point(means product manufactured after 30 steps, it turns from component become final product), still 6 values not used in the data.
These are next branch after node 8685. Check 2nd 8685 in et_modeop_pere, find  corresponding node in et_modeop, can finish the next branch.

But still the drawing after node 8685 is a little difficult.




Title: Re: How to show product routing from database to program?
Post by: alpine on October 08, 2022, 11:49:04 am
Before engaging with such a problem the OP must give more information about it. The two columns define a graph, presumably directed, but no more info is available.
Can there be loops? Obviously the start node is the first one. Are there terminal nodes? Are there other restrictions?

There is no loops, only one directly,from beginning to the end.
For the terminal nodes, should judge from data, if one value only appears in column et_modeop, not in et_modeop_pere, then this node is terminal nodes.
No other restrictions.

Right, it is acyclic graph then. You should perform topological sort on the nodes first and then it will be easy to make the layout
https://rosettacode.org/wiki/Topological_sort#Object_Pascal
Title: Re: How to show product routing from database to program?
Post by: avk on October 09, 2022, 07:24:03 pm
Sorry for off topic,
...
Right, it is acyclic graph then. You should perform topological sort on the nodes first and then it will be easy to make the layout
https://rosettacode.org/wiki/Topological_sort#Object_Pascal

I was surprised to find that the mentioned solution contains over 400(!) lines of code. Isn't that too much for this task?
Title: Re: How to show product routing from database to program?
Post by: BrunoK on October 09, 2022, 09:45:34 pm
I played a bit with your supplied data.
Attached is a project that takes your .csv file and builds a tree corresponding to the structure of your graph with pere->child and child->pere bindings.
Beginning of hierarchy for the nomen lines have -1 in et_modeop_pere node field.
Bottom line terminator have child_steps.count = 0.
Following the child_steps you have the chain from pere to child(ren) and following the pere_steps list items you walk from child node to pere node(s).
Title: Re: How to show product routing from database to program?
Post by: alpine on October 10, 2022, 11:08:54 am
Apologies for the over-complicated sort example in my previous post.
Here is a new one I wrote, the idea is to approximate the left-right layout seen in the previous posts attachments.

The output of the program should be something like:
Code: Text  [Select][+][-]
  1. 8251(1,1) 8253(2,1) 8255(3,1) 8257(4,1) 8277(5,1) 8435(6,1) 8437(7,1) 8439(8,1) 8447(9,1) 8445(10,1) 8451(11,1) 8453(12,1) 8455(13,1) 8457(14,1) 8463(15,1) 8465(16,1) 8467(17,1) 8469(18,1) 8475(19,1) 8473(20,1) 8487(21,1) 8683(22,1) 8491(23,1) 8685(24,1) 8499(25,1) 8505(26,1) 8507(27,1) 8865(28,1) 8555(25,2) 8561(26,2) 8563(27,2) 8869(28,2) 8525(29,1) 8579(29,2) 8531(30,1) 8585(30,2)

The steps are followed by their (X,Y) relative offset. Y offsets are bound from 1 up. To achieve the "Y-centered" layout it will require an additional pass when the maximal of Y is known.

EDIT: Of course, this is only a example how the layout can be approximated, the final program should combine the contents of Sorted, XOffsets, YOffsets (and probably more) arrays into one array/container with a single encapsulated object for each node.

Title: Re: How to show product routing from database to program?
Post by: avk on October 11, 2022, 10:44:29 am
Apologies for the over-complicated sort example in my previous post.
...

Added to the page Rosetta Code: Topological sorting (https://rosettacode.org/wiki/Topological_sort) another example(seems simpler and more understandable) in the Pascal section.
TinyPortal © 2005-2018