Exemple #1
0
        public void AddConnection(MarkovEdge edge)
        {
            TotalAdded++;
            var existingConnection = Connections.FirstOrDefault(c => c.IsConnectedTo(edge.TargetData));

            if (existingConnection != null)
            {
                existingConnection.Probability += (1.0 / TotalAdded);
            }
            edge.Probability = 1.0 / TotalAdded;
            Connections.Add(edge);
        }
Exemple #2
0
        public MarkovEdge GetEdgeBasedOnProbability()
        {
            double     chooser = 1.0;
            MarkovEdge chosen  = null;

            while (chosen == null && chooser > 0.0)
            {
                chooser -= _generator.NextDouble();
                var possibleEdges = Connections.Where(e => e.Probability >= chooser);
                if (possibleEdges.Any())
                {
                    chosen = possibleEdges.OrderBy(e => e.Probability).FirstOrDefault();
                }
            }
            return(chosen);
        }