/// <summary> /// Search a new path to add to the current circuit /// </summary> /// <param name="u">start vertex</param> /// <returns>true if successfull, false otherwize</returns> protected bool Search(IVertex u) { foreach (IEdge e in SelectOutEdgesNotInCircuit(u)) { OnTreeEdge(e); IVertex v = e.Target; // add edge to temporary path TemporaryCircuit.Add(e); // e.Target should be equal to CurrentVertex. if (e.Target == CurrentVertex) { return(true); } // continue search if (Search(v)) { return(true); } else { // remove edge TemporaryCircuit.Remove(e); } } // it's a dead end. return(false); }
/// <summary> /// Merges the temporary circuit with the current circuit /// </summary> /// <returns>true if all the graph edges are in the circuit</returns> protected bool CircuitAugmentation() { EdgeCollection newC = new EdgeCollection(); int i, j; // follow C until w is found for (i = 0; i < Circuit.Count; ++i) { IEdge e = Circuit[i]; if (e.Source == CurrentVertex) { break; } newC.Add(e); } // follow D until w is found again for (j = 0; j < TemporaryCircuit.Count; ++j) { IEdge e = TemporaryCircuit[j]; newC.Add(e); OnCircuitEdge(e); if (e.Target == CurrentVertex) { break; } } TemporaryCircuit.Clear(); // continue C for (; i < Circuit.Count; ++i) { IEdge e = Circuit[i]; newC.Add(e); } // set as new circuit circuit = newC; // check if contains all edges if (Circuit.Count == VisitedGraph.EdgesCount) { return(true); } return(false); }