public static TryFunc <TVertex, IEnumerable <TEdge> > TreeCyclePoppingRandom <TVertex, TEdge>(
#if !NET20
            this
#endif
            IVertexListGraph <TVertex, TEdge> visitedGraph,
            TVertex root,
            IMarkovEdgeChain <TVertex, TEdge> edgeChain)
            where TEdge : IEdge <TVertex>
        {
            Contract.Requires(visitedGraph != null);
            Contract.Requires(root != null);
            Contract.Requires(visitedGraph.ContainsVertex(root));
            Contract.Ensures(Contract.Result <TryFunc <TVertex, IEnumerable <TEdge> > >() != null);

            var algo = new CyclePoppingRandomTreeAlgorithm <TVertex, TEdge>(visitedGraph, edgeChain);
            var predecessorRecorder = new VertexPredecessorRecorderObserver <TVertex, TEdge>();

            using (predecessorRecorder.Attach(algo))
                algo.Compute(root);

            var predecessors = predecessorRecorder.VertexPredecessors;

            return(delegate(TVertex v, out IEnumerable <TEdge> edges)
            {
                return EdgeExtensions.TryGetPath(predecessors, v, out edges);
            });
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CyclePoppingRandomTreeAlgorithm{TVertex,TEdge}"/> class.
 /// </summary>
 /// <param name="host">Host to use if set, otherwise use this reference.</param>
 /// <param name="visitedGraph">Graph to visit.</param>
 /// <param name="edgeChain">Edge chain strategy to use.</param>
 public CyclePoppingRandomTreeAlgorithm(
     [CanBeNull] IAlgorithmComponent host,
     [NotNull] IVertexListGraph <TVertex, TEdge> visitedGraph,
     [NotNull] IMarkovEdgeChain <TVertex, TEdge> edgeChain)
     : base(host, visitedGraph)
 {
     EdgeChain = edgeChain ?? throw new ArgumentNullException(nameof(edgeChain));
 }
Exemple #3
0
 public CyclePoppingRandomTreeAlgorithm(
     IAlgorithmComponent host,
     IVertexListGraph <TVertex, TEdge> visitedGraph,
     IMarkovEdgeChain <TVertex, TEdge> edgeChain
     )
     : base(host, visitedGraph)
 {
     //Contract.Requires(edgeChain != null);
     this.edgeChain = edgeChain;
 }
 public RandomWalkAlgorithm(IVertexListGraph g)
 {
     this.visitedGraph = null;
     this.endPredicate = null;
     this.edgeChain = new NormalizedMarkovEdgeChain();
     this.rnd = new Random((int) DateTime.Now.Ticks);
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     this.visitedGraph = g;
 }
 public CyclePoppingRandomTreeAlgorithm(
     IAlgorithmComponent host,
     IVertexListGraph <TVertex, TEdge> visitedGraph,
     IMarkovEdgeChain <TVertex, TEdge> edgeChain
     )
     : base(host, visitedGraph)
 {
     if (edgeChain == null)
     {
         throw new ArgumentNullException("edgeChain");
     }
     this.edgeChain = edgeChain;
 }
 public CyclePoppingRandomTreeAlgorithm(IVertexListGraph g)
 {
     this.visitedGraph = null;
     this.colors = new VertexColorDictionary();
     this.edgeChain = new NormalizedMarkovEdgeChain();
     this.successors = new VertexEdgeDictionary();
     this.rnd = new Random((int) DateTime.Now.Ticks);
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     this.visitedGraph = g;
 }
		/// <summary>
		/// Constructs the algorithm around <paramref name="g"/> using
		/// the <paramref name="edgeChain"/> Markov chain.
		/// </summary>
		/// <param name="g">visited graph</param>
		/// <param name="edgeChain">
		/// Markov <see cref="IEdge"/> chain generator
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="g"/> or <paramref name="edgeChain"/>
		/// is a null reference
		/// </exception>
		public CyclePoppingRandomTreeAlgorithm(
			IVertexListGraph g,
			IMarkovEdgeChain edgeChain
			)
		{
			if (g==null)
				throw new ArgumentNullException("g");
			if (edgeChain==null)
				throw new ArgumentNullException("edgeChain");

			this.visitedGraph = g;
			this.edgeChain = edgeChain;
		}
 /// <summary>
 /// Constructs the algorithm around <paramref name="g"/> using
 /// the <paramref name="edgeChain"/> Markov chain.
 /// </summary>
 /// <param name="g">visited graph</param>
 /// <param name="edgeChain">
 /// Markov <see cref="IEdge"/> chain generator
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="g"/> or <paramref name="edgeChain"/>
 /// is a null reference
 /// </exception>
 public RandomWalkAlgorithm(
     IVertexListGraph g,
     IMarkovEdgeChain edgeChain
     )
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (edgeChain == null)
     {
         throw new ArgumentNullException("edgeChain");
     }
     this.visitedGraph = g;
     this.edgeChain    = edgeChain;
 }
Exemple #9
0
 public CyclePoppingRandomTreeAlgorithm(
     IVertexListGraph <TVertex, TEdge> visitedGraph,
     IMarkovEdgeChain <TVertex, TEdge> edgeChain)
     : this(null, visitedGraph, edgeChain)
 {
 }