/// <summary> /// Parsing of the CDKRGraph. This is the recursive method /// to perform a query. The method will recursively /// parse the CDKRGraph thru connected nodes and visiting the /// CDKRGraph using allowed adjacency relationship. /// </summary> /// <param name="traversed">node already parsed</param> /// <param name="extension">possible extension node (allowed neighbors)</param> /// <param name="forbidden">node forbidden (set of node incompatible with the current solution)</param> private void ParseRec(BitArray traversed, BitArray extension, BitArray forbidden) { BitArray newTraversed = null; BitArray newExtension = null; BitArray newForbidden = null; BitArray potentialNode = null; CheckTimeOut(); // if there is no more extension possible we // have reached a potential new solution if (BitArrays.IsEmpty(extension)) { Solution(traversed); } // carry on with each possible extension else { // calculates the set of nodes that may still // be reached at this stage (not forbidden) potentialNode = ((BitArray)GraphBitSet.Clone()); BitArrays.AndNot(potentialNode, forbidden); potentialNode.Or(traversed); // checks if we must continue the search // according to the potential node set if (MustContinue(potentialNode)) { // carry on research and update iteration count NbIteration = NbIteration + 1; // for each node in the set of possible extension (neighbors of // the current partial solution, include the node to the solution // and parse recursively the CDKRGraph with the new context. for (int x = BitArrays.NextSetBit(extension, 0); x >= 0; x = BitArrays.NextSetBit(extension, x + 1)) { #if !DEBUG && !TEST if (IsStop) { break; } #endif // evaluates the new set of forbidden nodes // by including the nodes not compatible with the // newly accepted node. newForbidden = (BitArray)forbidden.Clone(); newForbidden.Or((Graph[x]).Forbidden); // if maxIterator is the first time we are here then // traversed is empty and we initialize the set of // possible extensions to the extension of the first // accepted node in the solution. if (BitArrays.IsEmpty(traversed)) { newExtension = (BitArray)((Graph[x]).Extension.Clone()); } // else we simply update the set of solution by // including the neighbors of the newly accepted node else { newExtension = (BitArray)extension.Clone(); newExtension.Or((Graph[x]).Extension); } // extension my not contain forbidden nodes BitArrays.AndNot(newExtension, newForbidden); // create the new set of traversed node // (update current partial solution) // and add x to the set of forbidden node // (a node may only appear once in a solution) newTraversed = (BitArray)traversed.Clone(); newTraversed.Set(x, true); forbidden.Set(x, true); // parse recursively the CDKRGraph ParseRec(newTraversed, newExtension, newForbidden); } } } }
/// <summary> /// Reinitialisation of the TGraph. /// </summary> public void Clear() { Graph.Clear(); GraphBitSet.SetAll(false); }