Exemplo n.º 1
0
        public Edge GetRandomEdgeOut(double[] probabilityMultipliers, bool canVisitTheSameNode, List <Node> visitedNodes)
        {
            var randomValue = UtilHelper.GetRandomDoubleValue() * probabilityMultipliers.Last();

            var edgeMinWeight = probabilityMultipliers
                                .Select((v, i) => new { value = v, index = i })
                                .OrderBy(_ => _.value)
                                .First(_ => _.value >= randomValue)
                                .index + 1;

            var baseEdgeMinWeight = edgeMinWeight;

            while (true)
            {
                var edgesWithRequiredWeight = EdgesOut
                                              .Where(_ => _.Weight == edgeMinWeight &&
                                                     (canVisitTheSameNode || !visitedNodes.Contains(_.ToNode)))
                                              .ToList();

                if (edgesWithRequiredWeight.Any())
                {
                    var randomEdgeWithRequiredWeight = edgesWithRequiredWeight.ElementAt(UtilHelper.GetRandomValue(edgesWithRequiredWeight.Count));
                    return(randomEdgeWithRequiredWeight);
                }

                if (edgeMinWeight > baseEdgeMinWeight && edgeMinWeight != DnaSequence.Length - 1)
                {
                    edgeMinWeight++;
                }
                else if (edgeMinWeight == DnaSequence.Length - 1)
                {
                    edgeMinWeight = baseEdgeMinWeight - 1;
                }
                else if (edgeMinWeight != 1)
                {
                    edgeMinWeight--;
                }
                else
                {
                    return(EdgesOut.Last());
                }
            }
        }
Exemplo n.º 2
0
 public Edge GetRandomEdgeOut() => EdgesOut.ElementAt(UtilHelper.GetRandomValue(EdgesOut.Count));