Closed seallard closed 4 years ago
How should I detect whether a possible link is recurrent (back edge)?
// This checks a POTENTIAL link between a potential in_node
// and potential out_node to see if it must be recurrent
// Use count and thresh to jump out in the case of an infinite loop
bool is_recur(NNode *potin_node,NNode *potout_node,int &count,int thresh);
// This checks a POTENTIAL link between a potential in_node and potential out_node to see if it must be recurrent
bool Network::is_recur(NNode *potin_node,NNode *potout_node,int &count,int thresh) {
std::vector<Link*>::iterator curlink;
++count; //Count the node as visited
if (count>thresh) {
//cout<<"returning false"<<endl;
return false; //Short out the whole thing- loop detected
}
if (potin_node==potout_node) return true;
else {
//Check back on all links...
for(curlink=(potin_node->incoming).begin();curlink!=(potin_node->incoming).end();curlink++) {
//But skip links that are already recurrent
//(We want to check back through the forward flow of signals only
if (!((*curlink)->is_recurrent)) {
if (is_recur((*curlink)->in_node,potout_node,count,thresh)) return true;
}
}
return false;
}
}
I will stick to solution 1 since it seems more intuitive and matches my current representation of nodes. I don't think it is necessary to recalculate the heights after crossover. No matter what, it should be straight forward to do.
It might be necessary to extract the creation of recurrent connections to a separate method to control the rate at which they occur.
The add_non_recurrent_link actually can add recurrent links, so yeah... 👍 This is fine, but I should rename the method. And I need to detect whether the created link is recurrent and mark it as such. Would be nice to write a test that verifies it works. Maybe create a network where the only possible link addition is a recurrent link.