コード例 #1
0
ファイル: Particle.cs プロジェクト: lulzzz/BraneCloud
        public override void ReadIndividual(IEvolutionState state, BinaryReader dataInput)
        {
            base.ReadIndividual(state, dataInput);

            // Next, read auxillary arrays.
            if (dataInput.ReadBoolean())
            {
                Velocity = new double[dataInput.ReadInt32()];
                for (int i = 0; i < Velocity.Length; i++)
                {
                    Velocity[i] = dataInput.ReadDouble();
                }
            }
            else
            {
                Velocity = new double[genome.Length];
            }

            if (dataInput.ReadBoolean())
            {
                Neighborhood = new int[dataInput.ReadInt32()];
                for (int i = 0; i < Neighborhood.Length; i++)
                {
                    Neighborhood[i] = dataInput.ReadInt32();
                }
            }
            else
            {
                Neighborhood = null;
            }

            if (dataInput.ReadBoolean())
            {
                NeighborhoodBestGenome = new double[dataInput.ReadInt32()];
                for (int i = 0; i < NeighborhoodBestGenome.Length; i++)
                {
                    NeighborhoodBestGenome[i] = dataInput.ReadDouble();
                }
            }
            else
            {
                NeighborhoodBestGenome = null;
            }

            if (dataInput.ReadBoolean())
            {
                NeighborhoodBestFitness = (Fitness)Fitness.Clone();
                NeighborhoodBestFitness.ReadFitness(state, dataInput);
            }

            if (dataInput.ReadBoolean())
            {
                PersonalBestGenome = new double[dataInput.ReadInt32()];
                for (int i = 0; i < PersonalBestGenome.Length; i++)
                {
                    PersonalBestGenome[i] = dataInput.ReadDouble();
                }
            }
            else
            {
                PersonalBestGenome = null;
            }

            if (dataInput.ReadBoolean())
            {
                PersonalBestFitness = (Fitness)Fitness.Clone();
                PersonalBestFitness.ReadFitness(state, dataInput);
            }
        }
コード例 #2
0
ファイル: Particle.cs プロジェクト: lulzzz/BraneCloud
        public override void ReadIndividual(IEvolutionState state,
                                            StreamReader reader)
        {
            base.ReadIndividual(state, reader);

            // Next, read auxillary header.
            DecodeReturn d = new DecodeReturn(Code.ReadStringWithPreamble(AUXILLARY_PREAMBLE, state, reader));

            Code.Decode(d);
            if (d.Type != DecodeReturn.T_BOOLEAN)
            {
                state.Output.Fatal("Line " + d.LineNumber + " should have six boolean values but seems to have fewer.");
            }
            bool v = d.L != 0;

            Code.Decode(d);
            if (d.Type != DecodeReturn.T_BOOLEAN)
            {
                state.Output.Fatal("Line " + d.LineNumber + " should have six boolean values but seems to have fewer.");
            }
            bool n = d.L != 0;

            Code.Decode(d);
            if (d.Type != DecodeReturn.T_BOOLEAN)
            {
                state.Output.Fatal("Line " + d.LineNumber + " should have six boolean values but seems to have fewer.");
            }
            bool nb = d.L != 0;

            Code.Decode(d);
            if (d.Type != DecodeReturn.T_BOOLEAN)
            {
                state.Output.Fatal("Line " + d.LineNumber + " should have six boolean values but seems to have fewer.");
            }
            bool nbf = d.L != 0;

            Code.Decode(d);
            if (d.Type != DecodeReturn.T_BOOLEAN)
            {
                state.Output.Fatal("Line " + d.LineNumber + " should have six boolean values but seems to have fewer.");
            }
            bool pb = d.L != 0;

            Code.Decode(d);
            if (d.Type != DecodeReturn.T_BOOLEAN)
            {
                state.Output.Fatal("Line " + d.LineNumber + " should have six boolean values but seems to have fewer.");
            }
            bool pbf = d.L != 0;

            // Next, read auxillary arrays.
            if (v)
            {
                String s = reader.ReadLine();
                d = new DecodeReturn(s);
                Code.Decode(d);
                if (d.Type != DecodeReturn.T_INT)
                {
                    state.Output.Fatal("Velocity length missing.");
                }
                Velocity = new double[(int)d.L];
                for (int i = 0; i < Velocity.Length; i++)
                {
                    Code.Decode(d);
                    if (d.Type != DecodeReturn.T_DOUBLE)
                    {
                        state.Output.Fatal("Velocity information not long enough");
                    }
                    Velocity[i] = d.D;
                }
            }
            else
            {
                Velocity = new double[genome.Length];
            }

            if (n)
            {
                String s = reader.ReadLine();
                d = new DecodeReturn(s);
                Code.Decode(d);
                if (d.Type != DecodeReturn.T_INT)
                {
                    state.Output.Fatal("Neighborhood length missing.");
                }
                Neighborhood = new int[(int)(d.L)];
                for (int i = 0; i < Neighborhood.Length; i++)
                {
                    Code.Decode(d);
                    if (d.Type != DecodeReturn.T_INT)
                    {
                        state.Output.Fatal("Neighborhood information not long enough");
                    }
                    Neighborhood[i] = (int)(d.L);
                }
            }
            else
            {
                Neighborhood = null;
            }

            if (nb)
            {
                String s = reader.ReadLine();
                d = new DecodeReturn(s);
                Code.Decode(d);
                if (d.Type != DecodeReturn.T_INT)
                {
                    state.Output.Fatal("Neighborhood-Best length missing.");
                }
                NeighborhoodBestGenome = new double[(int)(d.L)];
                for (int i = 0; i < NeighborhoodBestGenome.Length; i++)
                {
                    Code.Decode(d);
                    if (d.Type != DecodeReturn.T_DOUBLE)
                    {
                        state.Output.Fatal("Neighborhood-Best genome not long enough");
                    }
                    NeighborhoodBestGenome[i] = d.D;
                }
            }
            else
            {
                NeighborhoodBestGenome = null;
            }

            if (nbf)
            {
                // here we don't know what kind of fitness it is.  So we'll do our best and guess
                // that it's the same fitness as our own Particle
                NeighborhoodBestFitness = (Fitness)(Fitness.Clone());
                NeighborhoodBestFitness.ReadFitness(state, reader);
            }

            if (pb)
            {
                String s = reader.ReadLine();
                d = new DecodeReturn(s);
                Code.Decode(d);
                if (d.Type != DecodeReturn.T_INT)
                {
                    state.Output.Fatal("Personal-Best length missing.");
                }
                PersonalBestGenome = new double[(int)(d.L)];
                for (int i = 0; i < PersonalBestGenome.Length; i++)
                {
                    Code.Decode(d);
                    if (d.Type != DecodeReturn.T_DOUBLE)
                    {
                        state.Output.Fatal("Personal-Best genome not long enough");
                    }
                    PersonalBestGenome[i] = d.D;
                }
            }
            else
            {
                PersonalBestGenome = null;
            }

            if (pbf)
            {
                // here we don't know what kind of fitness it is.  So we'll do our best and guess
                // that it's the same fitness as our own Particle
                PersonalBestFitness = (Fitness)Fitness.Clone();
                PersonalBestFitness.ReadFitness(state, reader);
            }
        }