예제 #1
0
        public EEGResult RunOn <TIdentity, TEnvironment, TIndividual>(Graph <TIdentity> G, int Repetitions, int Iterations, double MismatchedFitness, Evolve2.State.IState <TIndividual>[] FixatingStates)
            where TIdentity : struct
            where TEnvironment : struct
            where TIndividual : struct
        {
            // Do some pre-flight checks to make sure all the vertices are of the type we expect
            if (!G.Vertices.All(v => v.GetType().IsAssignableFrom(typeof(EnvironmentalVertex <TIdentity, TEnvironment, TIndividual>))))
            {
                throw new ArgumentException("G", "All vertices in the supplied graph must be of type EnvironmentalVertex or more derived");
            }

            EEGResult result = new EEGResult();

            result.RepetitionsPerformed = Repetitions;

            for (int rep = 0; rep < Repetitions; rep++)
            {
                Graph <TIdentity> repGraph = (Graph <TIdentity>)G.Clone();

                int iter = 0;
                while (iter < Iterations && !graphFixated <TIdentity, TEnvironment, TIndividual>(repGraph, FixatingStates))
                {
                    IEnumerable <TIdentity> targetState = _stateSelector.Select <TIdentity, TEnvironment, TIndividual>(repGraph, _random, MismatchedFitness);
                    TIdentity vertex = _vertexSelector.Select <TIdentity, TEnvironment, TIndividual>(targetState, repGraph, _random);
                    IEnumerable <TIdentity> destinationVertices = repGraph.VerticesConnectedToVertex(vertex);
                    TIdentity victim = _victimSelector.Select <TIdentity, TEnvironment, TIndividual>(destinationVertices, repGraph, _random);

                    //It's possible for there to be no victim.
                    //Consider the end of a chain where there are no neighbours
                    //No action should be taken, but it should still take up an iteration
                    if (!default(TIdentity).Equals(victim))
                    {
                        EnvironmentalVertex <TIdentity, TEnvironment, TIndividual> vert = (EnvironmentalVertex <TIdentity, TEnvironment, TIndividual>)repGraph.FindVertex(vertex);
                        EnvironmentalVertex <TIdentity, TEnvironment, TIndividual> vict = (EnvironmentalVertex <TIdentity, TEnvironment, TIndividual>)repGraph.FindVertex(victim);

                        vict.State.ChangeStateValue(vert.State.CurrentState);
                    }
                    iter++;
                }

                if (!graphFixated <TIdentity, TEnvironment, TIndividual>(repGraph, FixatingStates))
                {
                    result.Timeout++;
                }
                else
                {
                    result.Fixations++;
                }
            }

            return(result);
        }
예제 #2
0
        public MoranProcessResult RunOn <TIdent>(Graph <TIdent> G, int Repetitions, int Iterations, double MutantFitness)
            where TIdent : struct
        {
            MoranProcessResult result = new MoranProcessResult();

            result.RepetitionsPerformed = Repetitions;

            for (int rep = 0; rep < Repetitions; rep++)
            {
                Graph <TIdent> repGraph = (Graph <TIdent>)G.Clone();

                int iter = 0;
                while (iter < Iterations && !graphFixated(repGraph) && !graphExtinct(repGraph))
                {
                    IEnumerable <TIdent> targetState = _stateSelector.Select(repGraph, _random, MutantFitness);
                    TIdent vertex = _vertexSelector.Select(targetState, repGraph, _random);
                    IEnumerable <TIdent> destinationVertices = repGraph.VerticesConnectedToVertex(vertex);
                    TIdent victim = _victimSelector.Select(destinationVertices, repGraph, _random);

                    //It's possible for there to be no victim.
                    //Consider the end of a chain where there are no neighbours
                    //No action should be taken, but it should still take up an iteration
                    if (!default(TIdent).Equals(victim))
                    {
                        StatefulVertex <TIdent, VertexState> vert = (StatefulVertex <TIdent, VertexState>)repGraph.FindVertex(vertex);
                        StatefulVertex <TIdent, VertexState> vict = (StatefulVertex <TIdent, VertexState>)repGraph.FindVertex(victim);

                        vict.State.ChangeStateValue(vert.State.CurrentState);
                    }
                    iter++;
                }

                if (!graphFixated(repGraph) && !graphExtinct(repGraph))
                {
                    result.Timeout++;
                }
                else
                {
                    if (graphFixated(repGraph) && !graphExtinct(repGraph))
                    {
                        result.Fixations++;
                    }
                    else if (!graphFixated(repGraph) && graphExtinct(repGraph))
                    {
                        result.Extinctions++;
                    }
                }
            }

            return(result);
        }