Skip to content
Browse files

Create individual from a stream of random data, not a simple array.

  • Loading branch information...
1 parent 2df5597 commit d17a00ebf9551dcc6d5b0f1d6bab8493e76e61c9 @kylc committed Feb 21, 2012
View
12 Seve/ILC.Seve.Examples.Skyscraper/SkyscraperSimulation.cs
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using ILC.Seve.Genetics;
-using ILC.Seve.Graph;
-using System;
+using ILC.Seve.Util;
namespace ILC.Seve.Examples.Skyscraper
{
@@ -19,18 +18,15 @@ public class SkyscraperSimulation
static void Main(string[] args)
{
- var random = new Random();
+ var random = new RandomDataStream();
var constructor = new SkyscraperBinarySerializer(VertexCount, Max);
// Create the initial population
var individuals = new List<Individual>(PopulationSize);
for (int i = 0; i < PopulationSize; i++)
{
- // TODO: How about figuring out how much data we actually need?
- var randomData = new byte[1024];
- random.NextBytes(randomData);
-
- individuals.Add(constructor.FromBinary(randomData));
+ var individual = constructor.FromBinary(random);
+ individuals.Add(individual);
}
var crossFunction = new ConstantCrossFunction(CrossConstant);
View
71 Seve/ILC.Seve.Util/RandomDataStream.cs
@@ -0,0 +1,71 @@
+using System.IO;
+using System;
+
+namespace ILC.Seve.Util
+{
+ public class RandomDataStream : Stream
+ {
+ private readonly Random Random = new Random();
+
+ public override bool CanRead
+ {
+ get { return true; }
+ }
+
+ public override bool CanSeek
+ {
+ get { return false; }
+ }
+
+ public override bool CanWrite
+ {
+ get { return false; }
+ }
+
+ public override void Flush()
+ {
+ throw new NotImplementedException();
+ }
+
+ public override long Length
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public override long Position
+ {
+ get
+ {
+ throw new NotImplementedException();
+ }
+ set
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public override long Seek(long offset, SeekOrigin origin)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void SetLength(long value)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ byte[] randomData = new byte[count];
+ Random.NextBytes(randomData);
+ Array.Copy(randomData, 0, buffer, offset, count);
+
+ return count;
+ }
+
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
View
1 Seve/Seve.csproj
@@ -75,6 +75,7 @@
<Compile Include="ILC.Seve.Genetics\IBinarySerializer.cs" />
<Compile Include="ILC.Seve.Genetics\ICrossFunction.cs" />
<Compile Include="ILC.Seve.Genetics\IMutateFunction.cs" />
+ <Compile Include="ILC.Seve.Util\RandomDataStream.cs" />
<Compile Include="ILC.Seve.Web\JSONWebSerializer.cs" />
<Compile Include="ILC.Seve.Web\WebSerializer.cs" />
<Compile Include="ILC.Seve\SerialSimulation.cs" />

0 comments on commit d17a00e

Please sign in to comment.
Something went wrong with that request. Please try again.