void Start() { AdjacencyGraph <MazeGraphVertex, MazeGraphEdge <MazeGraphVertex> > g = new AdjacencyGraph <MazeGraphVertex, MazeGraphEdge <MazeGraphVertex> > (); MazeVertexFactory vFact = new MazeVertexFactory(); MazeEdgeFactory <MazeGraphVertex> eFact = new MazeEdgeFactory <MazeGraphVertex> (); System.Random rnd = new System.Random(); MazeGraphOptions opts = new MazeGraphOptions(6, 10, 3, 3, 3, false); MazeGraphFactory.Create(g, vFact.Create, eFact.Create, rnd, opts); print(g.ToString()); }
static int Main(string[] args) { AdjacencyGraph <MazeGraphVertex, MazeGraphEdge <MazeGraphVertex> > g = new AdjacencyGraph <MazeGraphVertex, MazeGraphEdge <MazeGraphVertex> > (); MazeVertexFactory vFact = new MazeVertexFactory(); MazeEdgeFactory <MazeGraphVertex> eFact = new MazeEdgeFactory <MazeGraphVertex> (); System.Random rnd = new System.Random(); MazeGraphOptions opts = new MazeGraphOptions(6, 10, 3, 3, 3, false); MazeGraphFactory.Create(g, vFact.Create, eFact.Create, rnd, opts); Console.WriteLine(g.ToString()); return(0); }
public static void Create <TEdge>( IMutableVertexAndEdgeListGraph <MazeGraphVertex, TEdge> g, VertexFactory <MazeGraphVertex> vertexFactory, EdgeFactory <MazeGraphVertex, TEdge> edgeFactory, Random rnd, MazeGraphOptions opts ) where TEdge : IEdge <MazeGraphVertex> { Contract.Requires(g != null); Contract.Requires(vertexFactory != null); Contract.Requires(edgeFactory != null); Contract.Requires(rnd != null); Contract.Requires(opts.vertexCount > 0); Contract.Requires(opts.edgeCount >= 0); Contract.Requires( !(!g.AllowParallelEdges && !opts.selfEdges) || opts.edgeCount <= opts.vertexCount * (opts.vertexCount - 1) // directed graph ); var vertices = new MazeGraphVertex[opts.vertexCount]; for (int i = 0; i < opts.vertexCount; ++i) { g.AddVertex(vertices[i] = vertexFactory()); } var freeVertices = new List <MazeGraphVertex> (vertices); MazeGraphVertex a; MazeGraphVertex b; int j, k; j = k = 0; while (j < opts.edgeCount) { a = freeVertices[rnd.Next(opts.vertexCount - k)]; do { b = vertices[rnd.Next(opts.vertexCount)]; }while (opts.selfEdges == false && a.Equals(b)); if (g.AddEdge(edgeFactory(a, b))) { if (g.OutDegree(a) >= opts.branchingFactor) { freeVertices.Remove(a); ++k; } ++j; } } j = k = 0; while (j < opts.treasures) { a = MazeGraphFactory.GetVertex(g, rnd); if (!(a.HasTreasure)) { a.HasTreasure = true; ++j; } } while (k < opts.startingPoints) { b = MazeGraphFactory.GetVertex(g, rnd); if (!(b.StartingPoint)) { b.StartingPoint = true; ++k; } } }