public static void UsingAGraphTypeHelper() { //Create a clique helper Clique <Guid> cliqueHelper = new Clique <Guid>(VertexFactory: new StatefulVertexFactory <VertexState>(new EnumState(VertexState.HEALTHY)), EdgeFactory: new DefaultEdgeFactory(), IdentityProvider: new DefaultIdentityProvider()); //Use it to construct a graph Graph <Guid> cliqueGraph = cliqueHelper.Create(100).Graph; //StatefulVertexFactory gives all vertices a default value of VertexState.HEALTHY. //For the simulation we need at least one mutant. The first vertex will do. StatefulVertex <Guid, VertexState> v = cliqueGraph.Vertices.OfType <StatefulVertex <Guid, VertexState> >().First(); v.State.ChangeStateValue(VertexState.MUTANT); MoranProcessRunner moranProcess = new MoranProcessRunner(new StateSelector(), new VertexSelector(), new VictimSelector()); MoranProcessResult result = moranProcess.RunOn(cliqueGraph, 1000, 10000, 3.0d); Console.WriteLine("UsingAGraphTypeHelper :: Result"); Console.WriteLine("\t Repetitions " + result.RepetitionsPerformed); Console.WriteLine("\t Fixations " + result.Fixations); Console.WriteLine("\t Extinctions " + result.Extinctions); Console.WriteLine("\t Timeouts" + result.Timeout); Console.WriteLine("\t p(Fixation) " + result.FixationProbability); Console.WriteLine("\t p(Extinction) " + result.ExtinctionProbability); Console.WriteLine("\t p(Timeout) " + result.TimeoutProbability); }
public void Verify_Chain_MutantAtSecond_p0Fixation() { ChainInfo <Guid> chainInfo = (new Chain <Guid>(new StatefulVertexFactory <VertexState>(new EnumState(VertexState.HEALTHY)), new DefaultEdgeFactory(), new DefaultIdentityProvider())) .Create(50, true); ((StatefulVertex <Guid, VertexState>)chainInfo.StartOfChain.NextVertex.Vertex).State.ChangeStateValue(VertexState.MUTANT); MoranProcessResult result = runner.RunOn(chainInfo.Graph, Repetitions, Iterations, 3.0d); Assert.AreEqual(result.FixationProbability, 0.0d); Assert.AreEqual(result.ExtinctionProbability, 1.0d); }
public void Verify_Clique_MutantAtAny_Fitness5_p0_8ishFixation() { CliqueInfo <Guid> cliqueInfo = (new Clique <Guid>(new StatefulVertexFactory <VertexState>(new EnumState(VertexState.HEALTHY)), new DefaultEdgeFactory(), new DefaultIdentityProvider())) .Create(50); cliqueInfo.Graph.Vertices.OfType <StatefulVertex <Guid, VertexState> >() .First() .State.ChangeStateValue(VertexState.MUTANT); MoranProcessResult result = runner.RunOn(cliqueInfo.Graph, Repetitions, Iterations, 5.0d); //Probabilities are allowed to be within 2% //This is a tradeoff for having shorter running tests Assert.IsTrue((result.FixationProbability >= 0.79) && (result.FixationProbability <= 0.81)); Assert.IsTrue((result.ExtinctionProbability >= 0.19) && (result.ExtinctionProbability <= 0.21)); }
public static void UsingAManuallyBuiltGraph() { IIdentityProvider <Guid> identity = new DefaultIdentityProvider(); Graph <Guid> graph = new Graph <Guid>(identity); StatefulVertex <Guid, VertexState> v1 = new StatefulVertex <Guid, VertexState>(identity, new EnumState(VertexState.MUTANT)); StatefulVertex <Guid, VertexState> v2 = new StatefulVertex <Guid, VertexState>(identity, new EnumState(VertexState.MUTANT)); StatefulVertex <Guid, VertexState> v3 = new StatefulVertex <Guid, VertexState>(identity, new EnumState(VertexState.MUTANT)); StatefulVertex <Guid, VertexState> v4 = new StatefulVertex <Guid, VertexState>(identity, new EnumState(VertexState.MUTANT)); StatefulVertex <Guid, VertexState> v5 = new StatefulVertex <Guid, VertexState>(identity, new EnumState(VertexState.MUTANT)); graph.AddVertex(v1); graph.AddVertex(v2); graph.AddVertex(v3); graph.AddVertex(v4); graph.AddVertex(v5); graph.AddEdge(new Edge <Guid>(v1, v2, identity), false); graph.AddEdge(new Edge <Guid>(v1, v3, identity), false); graph.AddEdge(new Edge <Guid>(v1, v4, identity), false); graph.AddEdge(new Edge <Guid>(v4, v5, identity), false); graph.AddEdge(new Edge <Guid>(v4, v3, identity), false); MoranProcessRunner moranProcess = new MoranProcessRunner(new StateSelector(), new VertexSelector(), new VictimSelector()); MoranProcessResult result = moranProcess.RunOn(graph, 1000, 10000, 3.0d); Console.WriteLine("UsingAManuallyBuiltGraph :: Result"); Console.WriteLine("\t Repetitions " + result.RepetitionsPerformed); Console.WriteLine("\t Fixations " + result.Fixations); Console.WriteLine("\t Extinctions " + result.Extinctions); Console.WriteLine("\t Timeouts" + result.Timeout); Console.WriteLine("\t p(Fixation) " + result.FixationProbability); Console.WriteLine("\t p(Extinction) " + result.ExtinctionProbability); Console.WriteLine("\t p(Timeout) " + result.TimeoutProbability); }