Commit 087efa88 by xiaotong

TarjanVisit code

parent 59a7030a
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
namespace nts{ namespace nts{
unsigned unsigned int netIDGlobal = 0; unsigned int netIDGlobal = 0;
MUTEX_HANDLE netMutex; MUTEX_HANDLE netMutex;
/* generate a network id */ /* generate a network id */
...@@ -109,7 +109,12 @@ depth-first search (Tarjan's algorithm) ...@@ -109,7 +109,12 @@ depth-first search (Tarjan's algorithm)
*/ */
void XNet::Traverse(XList &roots) void XNet::Traverse(XList &roots)
{ {
id = MakeNetID();
nodes.Clear(); nodes.Clear();
for (int i = 0; i < roots.count; i++)
TarjanVisit((XTensor*)roots.Get(i), nodes, id);
} }
/* /*
...@@ -126,7 +131,7 @@ void XNet::TarjanVisit(XTensor * node, XList &orders, const unsigned int code) ...@@ -126,7 +131,7 @@ void XNet::TarjanVisit(XTensor * node, XList &orders, const unsigned int code)
if(node->visitMark == code + 1){ if(node->visitMark == code + 1){
ShowNTErrors("There is a circle in the network\n"); ShowNTErrors("There is a circle in the network\n");
} }
else if(node->visitMark <= code || node->visitMark > code + 2){ else if(node->visitMark <= code || node->visitMark >= code + 2){
node->visitMark = code + 1; node->visitMark = code + 1;
XLink &income = node->income; XLink &income = node->income;
for(int i = 0; i < income.tailNum; i++){ for(int i = 0; i < income.tailNum; i++){
......
...@@ -32,6 +32,9 @@ namespace nts{ ...@@ -32,6 +32,9 @@ namespace nts{
/* management of tensor net (or graph) */ /* management of tensor net (or graph) */
struct XNet struct XNet
{ {
/* id of the network */
unsigned int id;
/* tensor nodes of the network (in order) */ /* tensor nodes of the network (in order) */
XList nodes; XList nodes;
......
...@@ -140,7 +140,7 @@ public: ...@@ -140,7 +140,7 @@ public:
bool isTmp; bool isTmp;
/* mark for traversing the gragh */ /* mark for traversing the gragh */
int visitMark; unsigned int visitMark;
/* /*
the link used to form networks. Note that when we compute on tensors, we actually create a the link used to form networks. Note that when we compute on tensors, we actually create a
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论