コード例 #1
0
 public InfectionNode(InfectionNode originalNode)
 {
     NodeStatus          = originalNode.NodeStatus;
     NodeType            = originalNode.NodeType;
     DayOfInfection      = originalNode.DayOfInfection;
     DaysUntilSuceptible = originalNode.DaysUntilSuceptible;
 }
コード例 #2
0
        public Graph RunIteration()
        {
            var infectionNodes = networkNodes[_currentNetworkKey];

            var rand = new Random(DateTime.Now.Millisecond);

            var previousStates = new Dictionary <string, InfectionNode>();

            foreach (var key in infectionNodes.Keys)
            {
                previousStates[key] = new InfectionNode(infectionNodes[key]);
            }

            foreach (var nodeKey in infectionNodes.Keys)
            {
                if (infectionNodes[nodeKey].NodeStatus == NodeStatus.Removed)
                {
                    MakeSuceptibleNode(nodeKey);
                }

                if (infectionNodes[nodeKey].NodeStatus == NodeStatus.Infected)
                {
                    var dayOfInfection = infectionNodes[nodeKey].DayOfInfection;
                    var resultadoAzar  = rand.NextDouble();

                    var recoveryLikelyhood = new ChiSquareDistribution(_parameters.ChiSquaredRecoveryDistributionDegreesOfFreedom).DistributionFunction(dayOfInfection + 1);

                    if (resultadoAzar <= recoveryLikelyhood)
                    {
                        RecoverNode(nodeKey);
                    }
                    else
                    {
                        WorsenNode(nodeKey);
                    }
                }
            }

            foreach (var edge in InfectionVisualNetworks[_currentNetworkKey].Edges)
            {
                var sourceKey      = edge.SourceNode.Id;
                var destinationKey = edge.TargetNode.Id;

                if ((previousStates[sourceKey].NodeStatus == NodeStatus.Infected && previousStates[destinationKey].NodeStatus == NodeStatus.Susceptible))
                {
                    var resultadoAzar = rand.NextDouble();
                    //var infectionLikelyhood = _parameters.InfectionProbabilities[previousStates[destinationKey].DayOfInfection];
                    var infectionLikelyhood = new ChiSquareDistribution(_parameters.ChiSquaredDistributionDegreesOfFreedom).ProbabilityDensityFunction(previousStates[sourceKey].DayOfInfection + 1);
                    infectionLikelyhood = infectionLikelyhood * _parameters.InfectionChiSquaredFactor;

                    if (previousStates[destinationKey].NodeType == NodeType.Vaccinated)
                    {
                        infectionLikelyhood = infectionLikelyhood * _parameters.VaccineEfficiencyRatio;
                    }

                    if (resultadoAzar <= infectionLikelyhood)
                    {
                        InfectNode(destinationKey);
                    }
                }
                else if ((previousStates[destinationKey].NodeStatus == NodeStatus.Infected && previousStates[sourceKey].NodeStatus == NodeStatus.Susceptible))
                {
                    var resultadoAzar = rand.NextDouble();
                    //var infectionLikelyhood = _parameters.InfectionProbabilities[previousStates[destinationKey].DayOfInfection];
                    var infectionLikelyhood = new ChiSquareDistribution(_parameters.ChiSquaredDistributionDegreesOfFreedom).ProbabilityDensityFunction(previousStates[destinationKey].DayOfInfection + 1);
                    infectionLikelyhood = infectionLikelyhood * _parameters.InfectionChiSquaredFactor;

                    if (previousStates[sourceKey].NodeType == NodeType.Vaccinated)
                    {
                        infectionLikelyhood = infectionLikelyhood * _parameters.VaccineEfficiencyRatio;
                    }

                    if (resultadoAzar <= infectionLikelyhood)
                    {
                        InfectNode(sourceKey);
                    }
                }
            }

            networkHistories[_currentNetworkKey].InfectedPerIteration.Add(GetCurrentInfectedNodes());
            networkHistories[_currentNetworkKey].AmountIterations++;

            return(InfectionVisualNetworks[_currentNetworkKey]);
        }