pub fn compute_acyclic(&self, start_index: usize) -> Result<Graph<NullVertex, NullEdge>> {
        let mut graph = Graph::new();
        for vertex in &self.vertices {
            graph.insert_vertex(NullVertex::new(*vertex.0))?;
        }

        let predecessors = self.compute_predecessors()?;

        let mut visited = FxHashSet::default();
        let mut queue = VecDeque::new();
        queue.push_back(start_index);

        while !queue.is_empty() {
            let vertex_index = queue.pop_front().unwrap();

            visited.insert(vertex_index);

            let vertex_predecessors = &predecessors[&vertex_index];

            for successor in &self.successors[&vertex_index] {
                // skip edges that would create a loop
                if visited.contains(successor) && vertex_predecessors.contains(successor) {
                    continue;
                }
                // successors we haven't seen yet get added to the queue
                if !visited.contains(successor) && !queue.contains(successor) {
                    queue.push_back(*successor);
                }

                graph.insert_edge(NullEdge::new(vertex_index, *successor))?;
            }
        }

        Ok(graph)
    }
/// Creates an acyclic graph with NullVertex and NullEdge
Creates an acyclic graph with NullVertex and NullEdge
Creates an acyclic graph with NullVertex and NullEdge
pub fn compute_acyclic(&self, start_index: usize) -> Result<Graph<NullVertex, NullEdge>> {
        let mut graph = Graph::new();
        for vertex in &self.vertices {
            graph.insert_vertex(NullVertex::new(*vertex.0))?;
        }
        let predecessors = self.compute_predecessors()?;
        let mut visited = FxHashSet::default();
        let mut queue = VecDeque::new();
        queue.push_back(start_index);
        while !queue.is_empty() {
            let vertex_index = queue.pop_front().unwrap();
            visited.insert(vertex_index);
            let vertex_predecessors = &predecessors[&vertex_index];
            for successor in &self.successors[&vertex_index] {
                // skip edges that would create a loop
                if visited.contains(successor) && vertex_predecessors.contains(successor) {
                    continue;
                }
                // successors we haven't seen yet get added to the queue
                if !visited.contains(successor) && !queue.contains(successor) {
                    queue.push_back(*successor);
                }
                graph.insert_edge(NullEdge::new(vertex_index, *successor))?;
            }
        }
        Ok(graph)
    }
pub fn compute_acyclic ( & self , start_index : usize ) -> Result < Graph < NullVertex , NullEdge > > { let mut graph = Graph :: new ( ) ; for vertex in & self . vertices { graph . insert_vertex ( NullVertex :: new ( * vertex . 0 ) ) ? ; } let predecessors = self . compute_predecessors ( ) ? ; let mut visited = FxHashSet :: default ( ) ; let mut queue = VecDeque :: new ( ) ; queue . push_back ( start_index ) ; while ! queue . is_empty ( ) { let vertex_index = queue . pop_front ( ) . unwrap ( ) ; visited . insert ( vertex_index ) ; let vertex_predecessors = & predecessors [ & vertex_index ] ; for successor in & self . successors [ & vertex_index ] { // skip edges that would create a loop if visited . contains ( successor ) && vertex_predecessors . contains ( successor ) { continue ; } // successors we haven't seen yet get added to the queue if ! visited . contains ( successor ) && ! queue . contains ( successor ) { queue . push_back ( * successor ) ; } graph . insert_edge ( NullEdge :: new ( vertex_index , * successor ) ) ? ; } } Ok ( graph ) }
Creates an acyclic graph with NullVertex and NullEdge
Creates an acyclic graph with NullVertex and NullEdge
&self
start_index
usize
&self
start_index
usize