Beispiel #1
0
        public void Or_Test(int[] bits)
        {
            var size      = 12;
            var array1    = CreateArray(size);
            var expected1 = new System.Collections.BitArray(size);

            foreach (var bit in bits)
            {
                array1[bit] = expected1[bit] = true;
            }

            var array    = array1.Not();
            var expected = expected1.Not();

            CollectionAssert.AreEqual(array, expected);
            Assert.AreEqual(expected.Count, array.Count);
        }
Beispiel #2
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);
                    }
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            #region https://youtu.be/_UtKEYYhi24
            Coleccion show = new Coleccion();
            System.Collections.BitArray bitArray =
                new System.Collections.BitArray(
                    new byte[] { 1, 2, 4, 8, 16 });// Convertiendo byte a bit

            CountElement.Count(bitArray);
            Coleccion.Show(bitArray, 2);

            //// Obtenemos un bit en particular
            System.Console.WriteLine(bitArray.Get(3));

            //// ponemos un bit en particular
            bitArray.Set(3, true);
            System.Console.WriteLine(bitArray.Get(3));
            Coleccion.Show(bitArray, 2);


            //https://youtu.be/pGS78ttnqfY

            // Clonacion del BitArray
            System.Collections.BitArray bitArray2 =
                (System.Collections.BitArray)bitArray.Clone();

            //// Invertir el Array, NOT
            bitArray2.Not();
            Coleccion.Show(bitArray2, 2);

            // Creando otro Array
            System.Collections.BitArray bitArray3 =
                new System.Collections.BitArray(new byte[] { 5, 7, 9, 13, 15 });
            Coleccion.Show(bitArray3, 2, "3°Array");

            //// Hacemos Or entre Arreglos
            bitArray3.Or(bitArray); // El resultado se guarda en el Array que llevo
                                    //acabo la invocacion.
            Coleccion.Show(bitArray, pNombre: "1°Array");
            Coleccion.Show(bitArray3, 3, pNombre: "Result");
            System.Console.WriteLine("=|||||||||=");

            //// Hacemos AND entre Array
            Coleccion.Show(bitArray, pNombre: "1°Array");
            Coleccion.Show(bitArray3, pNombre: "3°Array");

            // Hacemos el AND, BitArray 3 se modifica con el resultado
            bitArray3.And(bitArray);
            Coleccion.Show(bitArray3, 3, "Result");
            System.Console.WriteLine("=&&&&&&&&&&&=");

            //// Hamos XOR entre Array
            bitArray3 =
                new System.Collections.BitArray(new byte[] { 5, 7, 9, 13, 21 });
            Coleccion.Show(bitArray, pNombre: "1°Array");
            Coleccion.Show(bitArray3, pNombre: "3°Array");

            // Hacemos el XOR, Array 3 se modifica con el resultado
            bitArray3.Xor(bitArray);
            Coleccion.Show(bitArray3, pNombre: "Result");

            System.Console.ReadKey();
            #endregion
        }