Esempio n. 1
0
        public override void FillStubs(IEvolutionState state, IBreedingSource source)
        {
            // fill the stubs in my stub-pipeline first with my parent source
            StubSource.FillStubs(state, source);

            // fill subsidiary stubs with my stubpipeline, including my immediate source
            base.FillStubs(state, StubSource);
        }
        public override int Produce(
            int min,
            int max,
            int subpop,
            IList <Individual> inds,
            IEvolutionState state,
            int thread,
            IDictionary <string, object> misc)
        {
            int start = inds.Count;

            IBreedingSource s = state.Generation < GenerationSwitch ? Sources[0] : Sources[1];

            int total;

            if (GenerateMax)
            {
                if (MaxGeneratable == 0)
                {
                    MaxGeneratable = MaxChildProduction;
                }
                var n = MaxGeneratable;
                if (n < min)
                {
                    n = min;
                }
                if (n > max)
                {
                    n = max;
                }

                total = s.Produce(n, n, subpop, inds, state, thread, misc);
            }
            else
            {
                total = s.Produce(min, max, subpop, inds, state, thread, misc);
            }

            // clone if necessary
            if (s is SelectionMethod)
            {
                for (var q = start; q < total + start; q++)
                {
                    inds[q] = (Individual)(inds[q].Clone());
                }
            }

            return(total);
        }
Esempio n. 3
0
 public override void FillStubs(IEvolutionState state, IBreedingSource source)
 {
     for (int x = 0; x < Sources.Length; x++)
     {
         if (Sources[x] == null) // fill the stub
         {
             if (source == null)
             {
                 state.Output.Fatal("BreedingPipeline needed to fill a stub, but no BreedingSource was provided to fill it.\n" +
                                    "This is probably because no parent pipeline was a StubPipeline.");
             }
             Sources[x] = source;
         }
         else
         {
             Sources[x].FillStubs(state, source);
         }
     }
 }
Esempio n. 4
0
        //int IBreedingSource.PickRandom(IBreedingSource[] sources, double prob)
        //{
        //    return PickRandom(sources, prob);
        //}

        #endregion // Probability

        public virtual void FillStubs(IEvolutionState state, IBreedingSource source)
        {
        }
Esempio n. 5
0
        public override void Setup(IEvolutionState state, IParameter paramBase)
        {
            base.Setup(state, paramBase);
            MyBase = paramBase;

            var def = DefaultBase;

            Likelihood = state.Parameters.GetDoubleWithDefault(paramBase.Push(P_LIKELIHOOD), def.Push(P_LIKELIHOOD), 1.0);
            if (Likelihood < 0.0 || Likelihood > 1.0)
            {
                state.Output.Fatal("Breeding Pipeline likelihood must be a value between 0.0 and 1.0 inclusive",
                                   paramBase.Push(P_LIKELIHOOD),
                                   def.Push(P_LIKELIHOOD));
            }

            var numsources = NumSources;

            if (numsources == DYNAMIC_SOURCES)
            {
                // figure it from the file
                numsources = state.Parameters.GetInt(paramBase.Push(P_NUMSOURCES), def.Push(P_NUMSOURCES), 0);
                if (numsources == -1)
                {
                    state.Output.Fatal("Breeding pipeline num-sources value must exist and be >= 0", paramBase.Push(P_NUMSOURCES), def.Push(P_NUMSOURCES));
                }
            }
            else if (numsources <= DYNAMIC_SOURCES)  // it's negative
            {
                throw new InvalidOperationException("In " + this + " numSources() returned < DYNAMIC_SOURCES (that is, < -1)");
            }
            else
            {
                if (state.Parameters.ParameterExists(paramBase.Push(P_NUMSOURCES), def.Push(P_NUMSOURCES))) // uh oh
                {
                    state.Output.Warning("Breeding pipeline's number of sources is hard-coded to " + numsources + " yet num-sources was provided: num-sources will be ignored.",
                                         paramBase.Push(P_NUMSOURCES), def.Push(P_NUMSOURCES));
                }
            }

            Sources = new IBreedingSource[numsources];

            for (var x = 0; x < Sources.Length; x++)
            {
                var p = paramBase.Push(P_SOURCE).Push("" + x);
                var d = def.Push(P_SOURCE).Push("" + x);

                var s = state.Parameters.GetString(p, d);
                if (s != null && s.Equals(V_SAME))
                {
                    if (x == 0)
                    {
                        // oops
                        state.Output.Fatal("Source #0 cannot be declared with the value \"same\".", p, d);
                    }

                    // else the source is the same source as before
                    Sources[x] = Sources[x - 1];
                }
                else if (s != null && s.Equals(V_STUB))
                {
                    Sources[x] = null;
                }
                else
                {
                    Sources[x] = (IBreedingSource)state.Parameters.GetInstanceForParameter(p, d, typeof(IBreedingSource));
                    Sources[x].Setup(state, p);
                }
            }
            state.Output.ExitIfErrors();
        }