Author Topic: Tree walking a model from element to element via relationships  (Read 207 times)

ducatiross

  • EA User
  • **
  • Posts: 79
  • Karma: +0/-0
    • View Profile
Tree walking a model from element to element via relationships
« on: November 16, 2017, 10:10:45 pm »
Hi everyone,

I've tried for a few hours for searching for this but came up with nothing.

So, is there a method for tree walking a model - starting at one element, then walking up/down the relationships listing the relationship type and element it is linked to in a recursive fashion, perhaps looking for a target element type that could be many relations distant from the original, but linked through a series of other elements ?

This would replicate a similar functionality in BEASI where an ArchiMate model can be automatically drawn using derived relations from one element all the way up to another.

I would use BEASI, but a) I don't want to be forced to use custom ArchiMate elements - it must work with standard ArchiMate elements and b) I want to do this for other models, not just ArchiMate.

I might want to put the output in a diagram showing the starting element, the relation to the next element and so on recursively up the hierarchy of that relationship tree to the final element.

Or, I might just want to list out all the points in the tree in a grid/excel style tabular fashion.

Has anyone done this and if so, could they help me get started on it ?

Thanks in advance.


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7730
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Tree walking a model from element to element via relationships
« Reply #1 on: November 16, 2017, 10:35:19 pm »
If you know exactly the number of hops between your source and target then you could easily do this as an SQL query, which is of course the preferred solution for tabular output.

If you don't then a script solution is required (which will be a LOT slower)

I haven't done anything specific like that, but you would basically have to keep iterating the Element.Connectors in a recursive called function and test the target element for type or stereotype or whatever you make the criteria for your target.
Just make sure you keep a list of visited elements in order to avoid endless loops.

Geert


ducatiross

  • EA User
  • **
  • Posts: 79
  • Karma: +0/-0
    • View Profile
Re: Tree walking a model from element to element via relationships
« Reply #2 on: November 16, 2017, 11:02:00 pm »
Hi Geert,

There would be an unknown number of hops between the source and target, so scripting sounds like it is unavoidable. Bearing in mind my coding skills are 20 years out of date and I don't know JavaScript, this might be a bit problematic for me !

Thanks for responding.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7730
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Tree walking a model from element to element via relationships
« Reply #3 on: November 16, 2017, 11:10:43 pm »
To get some inspiration you can check out my VBscript library:
https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library

In case coding yourself is too much of a hassle you can always hire me or another EA consultant ;)

Geert

ducatiross

  • EA User
  • **
  • Posts: 79
  • Karma: +0/-0
    • View Profile
Re: Tree walking a model from element to element via relationships
« Reply #4 on: November 17, 2017, 04:49:38 am »
 :) Like your style Geert ! Thanks for sharing the examples. I can feel my inner coder coming back to life  ...  ;D

steen.jensen@sll.se

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Tree walking a model from element to element via relationships
« Reply #5 on: November 17, 2017, 10:23:04 am »
I used Prolog in the  last centuries (1985-1990) for large tree search as train time-table search for complete country railway.
Wonder if its possible to call EA scripts engine from other langues, ie SWI-prolog.org  :-*
 

qwerty

  • EA Guru
  • *****
  • Posts: 8952
  • Karma: +136/-123
  • I'm no guru at all
    • View Profile
Re: Tree walking a model from element to element via relationships
« Reply #6 on: November 17, 2017, 07:57:43 pm »
Yes, sure you can. EA has an API and I use Perl and Python. There are only very little constraints when using certain languages.

q.