Syntax
[EL,CL]=ELcorrect(EL)
Input Parameter
EL : | | Edge list with edges in wrong direction |
Output Parameter
EL : | | EL |
CL : | | List of turned edges in the original direction |
Examples
ELcorrect([1 2;2 3;3 4;5 4; 1 5])
ELcorrect(ELunsort([1 2;2 3;3 4;5 4; 1 5]))
Copyright 2023-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This algorithm is designed to correct the direction of edges in an edge list (EL) and return a list of edges that were turned to their original direction (CL).
Input Parameters
- EL: An edge list where each row represents an edge with two nodes. The edges may be in the wrong direction.
Output Results
- EL: The corrected edge list with edges in the correct direction.
- CL: A list of edges that were turned to their original direction.
Algorithm Steps
- Identify unique nodes in the edge list using
unique(EL)
.
- Find nodes that are not the starting node of any edge using
~ismember(uu,EL(:,1))
.
- Initialize
CL
as a zero matrix with the same size as EL
and a counter k
set to 0.
- While there are nodes that are not starting nodes:
- Select the first such node
mm
.
- Find edges where this node is the ending node using
find(EL(:,2)==mm)
.
- If there is more than one such edge:
- Select the first edge
zz
and the second edge ff
.
- Flip the direction of the second edge by swapping its nodes.
- Increment the counter
k
and store the flipped edge in CL
.
- Reorder the edges in
EL
to maintain consistency.
- Update
mm
to the new ending node of the flipped edge.
- If there is only one such edge, clear
mm
to exit the loop.
- Return the corrected edge list
EL
and the list of turned edges CL
.
Algorithm explaination created using ChatGPT on 2025-08-19 00:00. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21