Kahn algorithm & reachability

时间:2015-05-08 10:07:59

标签: objective-c algorithm core-data graph visual-programming

For learning purpose I'm developping an application that in real life would work basically like Quartz Composer or the recent Vuo. I'm building the graph of nodes on a Core Data Framework basis.

Basically I have a Node entity with a to-many relationship with Input and Output entities (a node can have multiple inputs and multiple outputs). Input has a to-one relationship to a Connection entity, while Output has a to-many relationship with the latter (an input can have only one connection, while an output can have many).

To read the graph I'm using a Topological Sorting algorithm (Kahn's one), described here. The code is as follows :

<div class="row">
    // Contents
</div>

I'm trying to understand the logic of how (and where in this code) I'd have to compute reachability for each Node (therefore for each Input) entity, if it is possible.

My questions are :

  • Is it possible to compute the reachability of nodes inside the Kahn's algorithm ?
  • If appropriate, where and how to do it, so I can understand why it is working ?

Thank you.

1 个答案:

答案 0 :(得分:0)

从快速浏览一下代码,我建议首先创建您创建的NSManagedObjects的子类(节点等),这样您就可以编写简单的代码来访问您创建的关系。这将使代码更易于维护。

总的来说,我不确定我是否理解这个问题。您可以按照关系来测试任何托管对象/节点的可访问性。这实际上与核心数据无关。