protected override SortedDictionary <Double, Double> CalculateActivePartModelB()
        {
            // Retrieving research parameters from network. Research MUST be Activation. //
            Debug.Assert(network.ResearchParameterValues != null);
            Debug.Assert(network.ResearchParameterValues.ContainsKey(ResearchParameter.ActivationStepCount));
            Debug.Assert(network.ResearchParameterValues.ContainsKey(ResearchParameter.ActiveMu));
            Debug.Assert(network.ResearchParameterValues.ContainsKey(ResearchParameter.Lambda));
            Debug.Assert(network.ResearchParameterValues.ContainsKey(ResearchParameter.TracingStepIncrement));

            SortedDictionary <Double, Double> ActiveParts = new SortedDictionary <Double, Double>();
            UInt32 Time   = Convert.ToUInt32(network.ResearchParameterValues[ResearchParameter.ActivationStepCount]);
            Double Mu     = Convert.ToDouble(network.ResearchParameterValues[ResearchParameter.ActiveMu]);
            Double Lambda = Convert.ToDouble(network.ResearchParameterValues[ResearchParameter.Lambda]);
            object v      = network.ResearchParameterValues[ResearchParameter.TracingStepIncrement];
            UInt32 tracingStepIncrement = ((v != null) ? Convert.ToUInt32(v) : 0);

            Double    P1   = Mu / (Lambda + Mu);
            Int32     t    = 0;
            RNGCrypto Rand = new RNGCrypto();
            uint      currentTracingStep = tracingStepIncrement;
            int       curActiveNodeCount = container.GetActiveNodesCount();

            while (t <= Time && curActiveNodeCount != 0)
            {
                Int32 RandomActiveNode = GetRandomActiveNodeIndex(Rand);
                if (Rand.NextDouble() <= P1)
                {
                    container.SetActiveStatus(RandomActiveNode, false);
                }
                else
                {
                    int x = 0;
                    //foreach (int x in container.Neighbourship[RandomActiveNode])
                    //{
                    if (Rand.NextDouble() < Lambda && container.GetActiveStatus(x) == true)
                    {
                        container.SetActiveStatus(x, true);
                    }
                    //}
                }

                /*if (currentTracingStep == t)
                 * {
                 *  container.Trace(network.ResearchName + "_ActivePartB",
                 *      "Realization_" + network.NetworkID.ToString(),
                 *      "Matrix_" + currentTracingStep.ToString());
                 *  currentTracingStep += tracingStepIncrement;
                 *
                 *  network.UpdateStatus(NetworkStatus.StepCompleted);
                 * }*/

                ++t;
                curActiveNodeCount = container.GetActiveNodesCount();
                Double ActivePartA = (Double)curActiveNodeCount / (Double)container.Size;
                ActiveParts.Add(t - 1, ActivePartA);
            }
            Debug.Assert(t > Time || !container.DoesActiveNodeExist());

            return(ActiveParts);
        }
Example #2
0
 private void GenerateInitialGraph(double probability)
 {
     for (int i = 0; i < container.Size; ++i)
     {
         for (int j = i + 1; j < container.Size; ++j)
         {
             if (rand.NextDouble() < probability)
             {
                 initialcontainer.AddConnection(i, j);
             }
         }
     }
 }
 /// <summary>
 /// Fills values in the two-dimensional array of bits which define the connectedness
 /// of clusters between each other.
 /// </summary>
 /// <param name="treeMatrix">Two-dimensional array of bits which define the connectedness
 /// of clusters between each other.</param>
 /// <param name="mu">Density parameter.</param>
 private void GenerateData(BitArray[][] treeMatrix, Double mu)
 {
     for (int currentLevel = 0; currentLevel < container.Level; ++currentLevel)
     {
         if (treeMatrix[currentLevel].Length > 0)
         {
             uint branchSize = container.Branches[currentLevel][0];
             int  counter = 0, nodeNumber = 0;
             for (int i = 0; i < treeMatrix[currentLevel].Length; i++)
             {
                 for (int j = 0; j < treeMatrix[currentLevel][i].Length; j++)
                 {
                     if (counter == (branchSize * (branchSize - 1) / 2))
                     {
                         ++nodeNumber;
                         counter    = 0;
                         branchSize = container.Branches[currentLevel][nodeNumber];
                     }
                     double k = rand.NextDouble();
                     if (k <= (1 / Math.Pow(container.CountLeaves(currentLevel, nodeNumber), mu)))
                     {
                         treeMatrix[currentLevel][i][j] = true;
                     }
                     else
                     {
                         treeMatrix[currentLevel][i][j] = false;
                     }
                     ++counter;
                 }
             }
         }
     }
 }
Example #4
0
        /// <summary>
        /// Generates random data for current level of block-hierarchic tree.
        /// </summary>
        /// <node>Current level must be initialized.</node>
        private void GenerateData(BitArray[][] treeMatrix,
                                  Int32 currentLevel,
                                  Int32 branchingIndex,
                                  Int32 maxLevel,
                                  Double mu)
        {
            List <EdgesAddedOrRemoved> edgesOnCurrentLevel = new List <EdgesAddedOrRemoved>();

            for (int i = 0; i < treeMatrix[maxLevel - currentLevel].Length; i++)
            {
                for (int j = 0; j < treeMatrix[maxLevel - currentLevel][i].Length; j++)
                {
                    if (rand.NextDouble() <= (1 / Math.Pow(branchingIndex, currentLevel * mu)))
                    {
                        treeMatrix[maxLevel - currentLevel][i][j] = true;
                        edgesOnCurrentLevel.Add(new EdgesAddedOrRemoved(i, j, true));
                    }
                    else
                    {
                        treeMatrix[maxLevel - currentLevel][i][j] = false;
                    }
                }
            }
            GenerationSteps.Add(edgesOnCurrentLevel);
        }
Example #5
0
        private void AddTwoBlocksConnection(Double probability, UInt32[] firstBlock, UInt32[] secondBlock)
        {
            Boolean stop = false;

            while (!stop)
            {
                for (UInt32 i = 0; i < firstBlock.Length; ++i)
                {
                    for (UInt32 j = 0; j < secondBlock.Length; ++j)
                    {
                        if (probability >= rand.NextDouble())
                        {
                            container.AddConnection(Convert.ToInt32(firstBlock[i]), Convert.ToInt32(secondBlock[j]));
                            stop = true;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Sets random active statuses with given probability to all nodes of the network.
        /// </summary>
        /// <param name="p">Activation probability for each node.</param>
        public void RandomActivating(Double p)
        {
            RNGCrypto rand = new RNGCrypto();

            activeNodes = new BitArray(Size, false);
            for (Int32 i = 0; i < Size; ++i)
            {
                if (rand.NextDouble() <= p)
                {
                    activeNodes[i] = true;
                }
            }
        }
Example #7
0
        private void GenerateInitialGraph(Double probability)
        {
            List <EdgesAddedOrRemoved> initialStep = (GenerationSteps != null) ? new List <EdgesAddedOrRemoved>() : null;

            for (Int32 i = 0; i < container.Size; ++i)
            {
                for (Int32 j = i + 1; j < container.Size; ++j)
                {
                    if (rand.NextDouble() < probability)
                    {
                        container.AddConnection(i, j);
                        if (initialStep != null)
                        {
                            initialStep.Add(new EdgesAddedOrRemoved(i, j, true));
                        }
                    }
                }
            }
            if (GenerationSteps != null)
            {
                GenerationSteps.Add(initialStep);
            }
        }
Example #8
0
 private void FillValuesByProbability(double p)
 {
     for (int i = 0; i < container.Size; ++i)
     {
         for (int j = i + 1; j < container.Size; ++j)
         {
             double a = rand.NextDouble();
             if (a < p)
             {
                 container.AddConnection(i, j);
             }
         }
     }
 }
Example #9
0
        private void FillValuesByProbability(double p)
        {
            int edgesAdded               = 0;
            int numberOfVertices         = container.Size;
            List <EdgesAddedOrRemoved> l = new List <EdgesAddedOrRemoved>();

            if (GenerationSteps != null)
            {
                GenerationSteps.Add(null);
            }

            for (int i = 0; i < container.Size; ++i)
            {
                for (int j = i + 1; j < container.Size; ++j)
                {
                    if (rand.NextDouble() < p)
                    {
                        container.AddConnection(i, j);
                        if (GenerationSteps != null)
                        {
                            l.Add(new EdgesAddedOrRemoved(i, j, true));
                            if (edgesAdded >= ((numberOfVertices - 1) / p))
                            {
                                GenerationSteps.Add(l);
                                l          = new List <EdgesAddedOrRemoved>();
                                edgesAdded = 0;
                            }
                            edgesAdded++;
                        }
                    }
                }
            }

            if (GenerationSteps != null)
            {
                if (l.Count != 0)
                {
                    GenerationSteps.Add(l);
                }
            }
        }
Example #10
0
 /// <summary>
 /// Generates random data for current level of block-hierarchic tree.
 /// </summary>
 /// <node>Current level must be initialized.</node>
 private void GenerateData(BitArray[][] treeMatrix,
                           UInt32 currentLevel,
                           UInt32 branchingIndex,
                           UInt32 maxLevel,
                           Double mu)
 {
     for (int i = 0; i < treeMatrix[maxLevel - currentLevel].Length; i++)
     {
         for (int j = 0; j < treeMatrix[maxLevel - currentLevel][i].Length; j++)
         {
             double k = rand.NextDouble();
             if (k <= (1 / Math.Pow(branchingIndex, currentLevel * mu)))
             {
                 treeMatrix[maxLevel - currentLevel][i][j] = true;
             }
             else
             {
                 treeMatrix[maxLevel - currentLevel][i][j] = false;
             }
         }
     }
 }
        private void Algorithm1(AbstractNetworkContainer containerToChange)
        {
            Int32 RandomActiveNode = Rand.Next(0, containerToChange.Size);

            Debug.Assert(RandomActiveNode < containerToChange.Size);

            if (containerToChange.GetActiveStatus(RandomActiveNode))
            {
                if (Rand.NextDouble() < lambda)
                {
                    ActivateVertex(containerToChange, true, RandomActiveNode);
                }
                if (Rand.NextDouble() < mu)
                {
                    containerToChange.SetActiveStatus(RandomActiveNode, false);
                }
            }
        }
Example #12
0
 /// <summary>
 /// Fills values in the two-dimensional array of bits which define the connectedness
 /// of clusters between each other.
 /// </summary>
 /// <param name="treeMatrix">Two-dimensional array of bits which define the connectedness
 /// of clusters between each other.</param>
 /// <param name="mu">Density parameter.</param>
 private void GenerateData(BitArray[][] treeMatrix, Double mu)
 {
     for (int currentLevel = 0; currentLevel < container.Level; ++currentLevel)
     {
         if (treeMatrix[currentLevel].Length > 0)
         {
             List <EdgesAddedOrRemoved> edgesOnCurrentLevel = new List <EdgesAddedOrRemoved>();
             int branchSize = container.Branches[currentLevel][0];
             int counter = 0, nodeNumber = 0;
             for (int i = 0; i < treeMatrix[currentLevel].Length; i++)
             {
                 for (int j = 0; j < treeMatrix[currentLevel][i].Length; j++)
                 {
                     if (counter == (branchSize * (branchSize - 1) / 2))
                     {
                         ++nodeNumber;
                         counter    = 0;
                         branchSize = container.Branches[currentLevel][nodeNumber];
                     }
                     double k = rand.NextDouble();
                     if (k <= (1 / Math.Pow(container.CountLeaves(currentLevel, nodeNumber), mu)))
                     {
                         treeMatrix[currentLevel][i][j] = true;
                         edgesOnCurrentLevel.Add(new EdgesAddedOrRemoved(i, j, true));
                     }
                     else
                     {
                         treeMatrix[currentLevel][i][j] = false;
                     }
                     ++counter;
                 }
             }
             GenerationSteps.Add(edgesOnCurrentLevel);
         }
     }
 }
Example #13
0
        public void Calculate()
        {
            NonHierarchicContainer containerToChange = (NonHierarchicContainer)container.Clone();

            containerToChange.InitializeEvolutionInformation();

            RNGCrypto rand = new RNGCrypto();
            int       currentStep = 0, currentTracingStep = tracingStepIncrement;

            Cycles3Trajectory.Add(currentStep, currentCycle3Count);

            while (currentStep != stepCount)
            {
                NonHierarchicContainer savedContainer = (NonHierarchicContainer)containerToChange.Clone();
                ++currentStep;

                List <EdgesAddedOrRemoved> edges = visualMode ? new List <EdgesAddedOrRemoved>() : null;
                double deltaCount = permanentDistribution ?
                                    containerToChange.PermanentRandomization(ref edges) :
                                    containerToChange.NonPermanentRandomization(ref edges);
                double newCycle3Count = currentCycle3Count + deltaCount;

                int delta = (int)(newCycle3Count - currentCycle3Count);
                if (delta > 0) // accept case
                {
                    Cycles3Trajectory.Add(currentStep, newCycle3Count);
                    if (visualMode)
                    {
                        EvolutionInformation.Add(edges);
                    }
                    currentCycle3Count = newCycle3Count;
                }
                else
                {
                    double probability = Math.Exp((-omega * Math.Abs(delta)));
                    if (rand.NextDouble() < probability) // accept case
                    {
                        Cycles3Trajectory.Add(currentStep, newCycle3Count);
                        if (visualMode)
                        {
                            EvolutionInformation.Add(edges);
                        }
                        currentCycle3Count = newCycle3Count;
                    }
                    else // reject case
                    {
                        Cycles3Trajectory.Add(currentStep, currentCycle3Count);
                        containerToChange = savedContainer;
                    }
                }

                network.UpdateStatus(NetworkStatus.StepCompleted);

                // TODO closed Trace

                /*if (currentTracingStep == currentStep)
                 * {
                 *  container.Trace(network.ResearchName,
                 *      "Realization_" + network.NetworkID.ToString(),
                 *      "Matrix_" + currentTracingStep.ToString());
                 *  currentTracingStep += tracingStepIncrement;
                 *
                 *  network.UpdateStatus(NetworkStatus.StepCompleted);
                 * }*/
            }
        }