Esempio n. 1
0
        /// <summary>  Parsing of the RGraph. This is the recursive method
        /// to perform a query. The method will recursively
        /// parse the RGraph thru connected nodes and visiting the
        /// RGraph using allowed adjacency relationship.
        /// 
        /// </summary>
        /// <param name="traversed"> node already parsed
        /// </param>
        /// <param name="extension"> possible extension node (allowed neighbours)
        /// </param>
        /// <param name="forbiden">  node forbiden (set of node incompatible with the current solution)
        /// </param>
        private void parseRec(System.Collections.BitArray traversed, System.Collections.BitArray extension, System.Collections.BitArray forbidden)
        {
            System.Collections.BitArray newTraversed = null;
            System.Collections.BitArray newExtension = null;
            System.Collections.BitArray newForbidden = null;
            System.Collections.BitArray potentialNode = null;

            // if there is no more extension possible we
            // have reached a potential new solution
            if (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 forbiden)
                potentialNode = ((System.Collections.BitArray)graphBitSet.Clone());
                potentialNode.And(forbidden.Not());
                //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.Or' operation. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1083'"
                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++;

                    // for each node in the set of possible extension (neighbours of 
                    // the current partial solution, include the node to the solution
                    // and perse recursively the RGraph with the new context.
                    for (int x = nextSetBit(extension, 0); x >= 0 && !stop; x = nextSetBit(extension, x + 1))
                    {
                        // evaluates the new set of forbidden nodes
                        // by including the nodes not compatible with the
                        // newly accepted node.
                        newForbidden = (System.Collections.BitArray)forbidden.Clone();
                        //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.Or' operation. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1083'"
                        newForbidden.Or(((RNode)graph[x]).forbidden);

                        // if it 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 (isEmpty(traversed))
                        {
                            newExtension = (System.Collections.BitArray)(((RNode)graph[x]).extension.Clone());
                        }
                        // else we simply update the set of solution by
                        // including the neighbours of the newly accepted node
                        else
                        {
                            newExtension = (System.Collections.BitArray)extension.Clone();
                            //UPGRADE_NOTE: In .NET BitArrays must be of the same size to allow the 'System.Collections.BitArray.Or' operation. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1083'"
                            newExtension.Or(((RNode)graph[x]).extension);
                        }

                        // extension my not contain forbidden nodes
                        newExtension.And(newForbidden.Not());

                        // 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 = (System.Collections.BitArray)traversed.Clone();
                        SupportClass.BitArraySupport.Set(newTraversed, x);
                        SupportClass.BitArraySupport.Set(forbidden, x);

                        // parse recursively the RGraph
                        parseRec(newTraversed, newExtension, newForbidden);
                    }
                }
            }
        }
Esempio n. 2
0
    public static void TestNotIntervals()
    {
      var empty = new int[0].ToList();
      var a = new[] {0, 3}.ToList();
      var b = new[] {2, 2}.ToList();
      var c = new[] {0, 2}.ToList();
      var d = new[] {1, 1}.ToList();
      var e = new[] {2, 1}.ToList();
      var f = new[] {0, 1}.ToList();
      var g = new[] {3, 1}.ToList();

      Assert.That(b.Not(a), Is.EqualTo(c));
      Assert.That(a.Not(b), Is.EqualTo(g));
      Assert.That(d.Not(c), Is.EqualTo(f));
      Assert.That(c.Not(d), Is.EqualTo(empty));
      Assert.That(e.Not(c), Is.EqualTo(c));
      Assert.That(c.Not(e), Is.EqualTo(e));

      Assert.That(a.Not(), Is.EqualTo(new[] {3}));
    }