public static void AddingAdditionalEdgesInToASubgraph() { //Construct the graph with the same identity provider as will be used for the vertices, edge and subgraphs IIdentityProvider <Guid> identityProvider = new DefaultIdentityProvider(); Graph <Guid> graph = new Graph <Guid>(identityProvider); //There must be at least one vertex in the graph before adding a subgraph, //so the subgraph has something to connect to Vertex <Guid> graph_v1 = new Vertex <Guid>(identityProvider); graph.AddVertex(graph_v1); //Create a second graph which will become the subgraph, providing the same identity provider Chain chainHelper = new Chain(identityProvider); Graph <Guid> subGraph = chainHelper.Create(10, false).Graph; //Add the subgraph //The source is the vertex in the main graph that the subgraph will connect to //The vertex producer should return the vertex in the subgraph which will be connected in to the main graph graph.AddSubgraph(graph_v1, subGraph, (g) => g.Vertices.First()); //Add a subgraph edge //The subgraph parameter must be a graph which is already a subgraph of the supergraph //And the result of VertexProducer must a vertex in the supplied subgraph graph.AddSubgraphEdge(graph_v1, subGraph, (g) => g.Vertices.ElementAt(1)); }
public static void AddingAVertex() { //Construct the graph with the same identity provider as will be used for the vertices IIdentityProvider <Guid> identityProvider = new DefaultIdentityProvider(); Graph <Guid> graph = new Graph <Guid>(identityProvider); //Create a vertex, ensuring the graph and the vertex have the same identity provider Vertex <Guid> v = new Vertex <Guid>(identityProvider); //Add the vertex graph.AddVertex(v); }
public static void AddingAnEdge() { //Construct the graph with the same identity provider as will be used for the vertices and edges IIdentityProvider <Guid> identityProvider = new DefaultIdentityProvider(); Graph <Guid> graph = new Graph <Guid>(identityProvider); Vertex <Guid> v1 = new Vertex <Guid>(identityProvider); Vertex <Guid> v2 = new Vertex <Guid>(identityProvider); //Create an edge, providing the same identity provider as the vertices and graph Edge <Guid> edge = new Edge <Guid>(v1, v2, identityProvider); //Add it to the graph. //If Directed is false, the graph adds an edge the opposite way (destination to source) graph.AddEdge(edge, false); }
private static void VerifyElementInsertion <TSource, TTarget>(IQuery query, MockLinqToDbDataBuilder ermDb, TSource sourceObject) where TSource : class, IIdentifiable <long>, new() where TTarget : class, IIdentifiable <long>, IFactObject, new() { var entityId = new DefaultIdentityProvider().GetId(sourceObject); ermDb.Has(sourceObject); var factory = new VerifiableRepositoryFactory(); Transformation.Create(query, factory) .ApplyChanges <TTarget>(entityId); factory.Verify <TTarget>( x => x.Add(It.Is(Predicate.ById <TTarget>(entityId))), Times.Once, string.Format("The {0} element was not inserted.", typeof(TTarget).Name)); }
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); }