axkr / symja_android_library

:coffee: Symja - computer algebra language & symbolic math library. A collection of popular algorithms implemented in pure Java.
https://matheclipse.org/
GNU General Public License v3.0
379 stars 85 forks source link

implement Path object* from graph theory would be epic. #496

Open masta99wrfvsHsa opened 2 years ago

masta99wrfvsHsa commented 2 years ago

Is your feature request related to a problem? Please describe. A bit lazy to re-implement a homeroll graph.due to graph and path are fundamental inputs in graph theory.

Is it possible to implement Path* object as described in graph theory? Since symja already have Graph object and even a bunch of related property test functions. Adding Path would enable testing of euler path,validpath,etc...

Describe the solution you'd like Ideally it should be fast and simple .the internal structure can use the existing symja List object. As I believe most symja user would be habitual typing {c, d,....} as seen in D() have {x,n} also. A list also have (commonly left to right sequence embedded in most people mind.) Just adding a line of:The argument Path goes from left to right as a list.*(is probably acceptable by most people)

However,if you want to keep the mathematical representation accurate then I believe a Path object is probably a must,as it has a specified flow and arrow symbol.(a>b>c)

Describe alternatives you've considered Homeroll my own path object and re-implement the graph object and misll functions that is already in symja.#extremely pointless.

Additional context With Path,the other related functions could be implemented easily. But should never implement a Cycle object. as its essentially a path,that just happens to have property being a cycle.

It would be epic and extremely useful if in the future we have a graphproperties function. and it just dumps various analysis result.Awesome right? eg>graphproperties(Graph(.....),{.....}) {false,false,.....}

Then we parse the result and add the description. iseulercycle=false iseulerpath=false is..... is... ..... Add any other context or screenshots about the feature request here.

If necessary discuss the feature in the Discord Symja chat.

axkr commented 2 years ago

For graphs we are using:

Here you can find examples of which functions can be useful to be implemented as a JGrapht function call.

masta99wrfvsHsa commented 2 years ago

awesome it seems like its possible to even implement iseulerpath() right away.

one of the possible minimal signature: iseulerpath(Graph(),{vertexList})

I think https://jgrapht.org/javadoc/org.jgrapht.core/org/jgrapht/graph/GraphWalk.html

is very useful. possible implementation in my mind.

iseulerpath(...){ Graph graphobj =ast.arg1(); java.util.List vertexList=ast.arg2(); double weight=1d;//assume 1 to simplify the user needed minimum input.

org.jgrapht.graph.GraphWalk gwobj=new org.jgrapht.graph.GraphWalk(graphobj,vertexList,weight);

//we need to make sure path is valid in graph, because graphwalk no check validity. //all vertex in path must be in graph else invalid. if(graph.vertexSet().contains(vertexList)){//list compare,pseudocode //to check use all edge in graph.pseudocode. return graph.edgeSet()==gwobj.getEdgeList();

}else{return F.nil;}

}

axkr commented 2 years ago

Something like:

EulerianGraphQ({1 -> 2, 2 -> 3, 3 -> 1, 1 -> 3, 3 -> 4, 4 -> 1 })

or

FindEulerianCycle(Graph({1 -> 2, 2 -> 3, 3 -> 4, 4 -> 1}))

should already work.

See: https://github.com/axkr/symja_android_library/blob/master/symja_android_library/doc/functions/EulerianGraphQ.md

masta99wrfvsHsa commented 2 years ago

eulerpath is not equal to eulerian graph.If I am not wrong its a path property, eg from a to b.while being in a graph. So it definitely will need a graph object and a path object*.

masta99wrfvsHsa commented 2 years ago

proveeuleriangraphnotequaleulerpath

for example look at the pic,D>C>A>D>B>A would have gone through all of the path in the graph,BUT,its not eulerian graph. because eulerian graph uses the definition of having a eulercycle.(a full loop onto start)