Rules engine Base handling round trip

Good evening guys, how are you ?

Today I have a challenge to carry out a roundtrip control and I would like your help.

I’ll give you an example of what I need to do.

Example:

I have 2 routes, the outbound and the return route.
The departure being:
RT827 - FMH-FRC-01 SOC-SP5
Being the return:
RT831 - SOC-SP5 HUB-FRC-01

Therefore, this route is a roundtrip FMH-FRC-01|SOC-SP5|HUB-FRC-01.
I would like the flow to return only those that fit this round trip pattern, and also return the IDs in 2 columns, one column for the first route and the second for the second route.

Point of attention, routes do not necessarily follow the FMH-SOC-HUB format, SOC-SOC-SOC may exist.

Example
SOC-SP2 - SOC-SP6
SOC-SP6 - SOC-SP2

I will leave the file attached, I count on your collaboration

KNIME_project4.knwf (2.7 MB)

@takbb @ArjenEX Can you help me?

Hello @Gabriel2020 ,
I have tried to solve your problem, but I am not sure whether it is what you expect.
This is the output I am getting is attached below

I have tried not use any regex or string manipulation stuff and just used basic cell splitter and row filter nodes. I have attached the workflow as well.

Let me know if this helps.

KNIME_project4_updated.knwf (2.8 MB)

1 Like

How can this be a roundtrip when the start and endpoint are not the same?

I would say that RT852 is actually the roundtrip.

2 Likes

They are the same place, we just have to separate the “-” character

If you view the example it will be FRC-01|SP5|FRC-01.

I’ll leave a simpler flow below so we can get to the result.

And a print to demonstrate how you would like it to return.

KNIME_project48.knwf (2.7 MB)

I had exactly the same question, but I thought I’d let you blink first @ArjenEX :wink:

Hi @Gabriel2020

Reiterating what @ArjenEX said… I don’t think you fully answered that point and your example didn’t really help me either

So you’ve given us a new piece of information that the FMH, FRC and SOC prefix apparently isn’t part of the location. So questions:

  1. Is the location always the part that follows FMH- FRC- or SOC-

  2. Are there any other possible prefixes?

  3. If (origin) HUB-FRC-01 is the same place as (destination) FMH-FRC-01 because both places are FRC-01 then why isn’t (origin) FMH-FRC-01 the same place as (destination) FMH-FRC-01 (as per @ArjenEX 's comment)

I think the above questions would be answered by your telling us a bit more about what the codes built into your data mean. You obviously know your data, but please keep in mind that to us it is all just codes with no meaning, so please can you give more detail.

2 Likes

This task is a little complicated, so I’m sorry for not making it clear.

In the logistics we practice today in the company where I work, we separate the packages, which is why FMH and HUB are the same address but separated by acronyms.

FMH means that the packages came from the supplier, and HUB that they will be delivered to the recipient.

By removing the acronyms, it is possible to arrive at a common sense, such as FRC-01 | SP5 and SP5 | FRC-01. What I need is exactly this to understand what goes back and forth.

Another Example SP5 | SP2 and SP2 | SP5 is the same thing, it just changes the origin but it is a round trip, which is what I need to do and return in the model shown above.

My director wants to understand how many routes we currently have, and how many are roundtrips, which is this “back and forth” model.

1 Like

Hi @Gabriel2020 , thanks for the explanation.

If you have SOC-SP5 | SOC-SP2 and SOC-SP2 | SOC-SP5 on two routes, how do you know if the round trip is
SP5 | SP2 | SP5
or
SP2 | SP5 | SP2
or are they both considered to be the same thing?

Is a round trip only ever from Place A to Place B and then back to Place A?
i.e. You aren’t trying to find more complex round trips involving more than two routes at a time?

Another question… you have multiple trips because this is a journey history. Are you wanting just the total distinct routes, or the total number of trips on each those routes (so if the same round trip occurs 10 times, you want it listed once or 10 times?)

Good evening, how are you?

In the last file I sent, I removed duplicates and unnecessary columns. Only Origin x destination and route ID remained.

I think it’s quite difficult to explain, but it’s a simple task.

I have route A with origin (X) and destination (Y).

And I have route B with origin ( Y ) and destination ( X ).

What I want to know is exactly this.

X and Y or Y and X is the same thing.

Therefore, the route is X | Y | X. And with that done I can apply the model I sent above, where I have what formed (X | Y | X) the ID (A) and the route ID (B)

Hi @Gabriel2020 , hopefully this gives you a starting point.

At the end the data is split into two tables. The upper table contains the round trips and the lower table contains the one-way trips.

I prioritised “origins” so a round trip is

FMH-SOC-HUB rather than HUB-SOC-FMH
or
HUB-SOC-HUB rather than SOC-HUB-SOC
This priority order is set in the Table Creator with the Value Lookup, so can be easily adjusted if necessary

There and back again.knwf (2.8 MB)

3 Likes

image
image

I’m trying to connect but it shows an error to install, for some reason I can’t

Sorry @Gabriel2020 , for some reason i thought you were on KNIME 5.2. When i get a chance, I’ll import it into 4.7 and replace those nodes with alternatives.

I’m upgrading to 5.2

Everything went well, Takk, can you forward me your number, I wanted some lessons on knime 5.2

1 Like

You might find this webinar of interest :wink:

3 Likes

Btw @Gabriel2020 , I’d recommend taking a full backup of your workspace folders before actively opening all your workflows in 5.2.

If you save in 5.2, it can replace some nodes such as column rename, and several others, making it incompatible if you ever need to go back to 4.7 to check something.

Good to have a backup anyway!

2 Likes

Thanks again for the tips, so far I haven’t opened the files, but they are backed up in the old version.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.