Esempio n. 1
0
        private VertexGraph RunPhysics(Individual individual)
        {
            var world = new DefaultRigidBodyWorld(individual.Graph);
            var physics = new PhysicsEngine(world);

            // Run for 30 seconds of simulated time
            // TODO: Increase this, it just makes it easier to test
            var graph = physics.RunSimulation(60);

            // TODO: Do we still need this for rigid bodies?
            // - Dean: Don't think so, mem mngment doesn't seem to be an issue
            // world.DisposeIndividual();

            return graph;
        }
Esempio n. 2
0
        public Individual Cross(Individual father, Individual mother, BinarySerializer serializer)
        {
            byte[] fatherData = serializer.ToBinary(father);
            byte[] motherData = serializer.ToBinary(mother);

            if (fatherData.Length != motherData.Length)
            {
                throw new ArgumentException("Individuals must compose to binary representations of the same length to be crossed.");
            }

            byte[] childData = new byte[fatherData.Length];

            var splitIndex = (long)(fatherData.Length * Ratio);
            Array.Copy(fatherData, childData, splitIndex);
            Array.Copy(motherData, splitIndex, childData, splitIndex, childData.Length - splitIndex);

            return serializer.FromBinary(childData);
        }
Esempio n. 3
0
        public override byte[] ToBinary(Individual _individual)
        {
            var individual = (SkyscraperIndividual)_individual;
            var graph = individual.Graph;

            var stream = new MemoryStream();

            using (stream)
            {
                var writer = new BinaryWriter(stream);

                // Write the locations of each point on the graph (3 floats)
                foreach (var vertex in graph.Vertices)
                {
                    writer.Write(vertex.X);
                    writer.Write(vertex.Y);
                    writer.Write(vertex.Z);
                }
            }

            return stream.ToArray();
        }
Esempio n. 4
0
 public abstract byte[] ToBinary(Individual individual);