Thank you, Michael.
Here is the code snippet in scala script. I need to implement isDirectedGraphCyclic(TinkerGraph) to detect the cycle.
{code}
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
def isDirectedGraphCyclic(graph: TinkerGraph): Boolean = {
//Need to write the query similar to
//g.V().as("a").repeat(out().simplePath()).emit(loops().is(gt(1))).where(out().as("a")).path()
return true
}
val graph = TinkerGraph.open
val g = graph.traversal
val vA = g.addV("a").next
val vB = g.addV("b").next
val vC = g.addV("c").next
val vD = g.addV("d").next
vA.addEdge("next", vB)
vA.addEdge("next", vD)
vC.addEdge("next", vA)
vC.addEdge("next", vD)
//Assert graph has no cycles
val resultNo = isDirectedGraphCyclic(graph)
//Add another edge and make sure it becomes cyclic
vB.addEdge("next", vC)
val resultYes = isDirectedGraphCyclic(graph)
{code}
/***********************************************/