How to avoid duplicate edges in the path in Tinkerpop 3? - tinkerpop

In Tinkerpop3, we have SimplePath to prevent a traverser repeating the vertices. But what if I want it to traverse each edge only once?
For example,Graph.
In this graph, I want to get all the possible path if I start from V1 and traverse each edge no more than once per path and then return to V1 at last. One possible path is V1->E2->V2->E1->V1->E5->V4->E7->V3->E3->V1.

I remember this graph and just recently answered a similar question here: Query to check if there is a cycle in a graph with edges visited only once
This should answer your question too.

Related

How to obtain accurate value of segment-distances and segment-weights for creating bendpoints?

I am trying to create edges with bends for a layout. Normally, I am using a haystack edge in the graph but whenever an edge bend has to be created, the curve-style of the edge is changed to segments. Currently, I am only creating edges with single bends. I have tried the code provided in this post but it is not creating proper edges. Currently, I am using the code from cytoscape.js-edge-editing, since it is creating better results.
The main problem is that the segment-distances values which cause the bendpoint to be created at the wrong location. Since, the functions in the above provided codes are not creating proper bendpoints, what is the right way to go about this?
A sample problem is as shown:
An edge bend has to created created in the edge from n12 to n15 where n12 is the source. The values of segment-distances and segment-weights are shown in the console. Having a positive value of segment-distances creates the bendpoint at the wrong position. It was actually supposed to be to the right of n12 and to the top of n15.
Whereas in another scenario, as shown in the following figure, an edge bend has to be created in the edge from n3 and n2. And the positions of these nodes are quite similar to n12 and n15 wrt each other. Their edge is given the same values of segment-distances and segment-weights as for the edge in the previous figure. And yet, the bendpoint is created (not accurately) but almost near to the expected location. Whereas the same value of segment-distance creates the bendpoint at the opposite location in the previous scenario.
I do not understand why this is happening. Can someone please guide me as how to solve this problem?
Refer to edge-distances:
edge-distances : With value intersection (default), the line from source to target for segment-weights is from the outside of the source node’s shape to the outside of the target node’s shape. With value node-position, the line is from the source position to the target position. The node-position option makes calculating edge points easier — but it should be used carefully because you can create invalid points that intersection would have automatically corrected.
https://js.cytoscape.org/#style/segments-edges
The intersection point is different from the node centre point (position).
If you want right-angled edges, you should probably just use taxi edges: https://js.cytoscape.org/#style/taxi-edges

How to access net displacements in pyiron

Using pyiron, I want to calculate the mean square displacement of the ions in my system. How do I see the total displacement (i.e. not folded back by periodic boundary conditions) without dumping very frequently and checking when an atom passes over the boundary and gets wrapped?
Try to compare job['output/generic/unwrapped_positions'][-1] and job.structure.positions+job.output.total_displacements[-1]. If they deliver the same values, it's definitely fine both ways. If not, you can post the relevant lines in your notebook here.
I'd like to add a few comments to Jan's answer:
While job['output/generic/unwrapped_positions'] returns the unwrapped positions parsed from the output files, job.output.total_displacements returns the displacement of atoms calculated from each pair of consecutive snapshots. So if an atom moves more than half the box length in any direction, job.output.total_displacements will give wrong coordinates. Therefore, job['output/generic/unwrapped_positions'] is generally more trustworthy, but it is not available in all the codes (since some codes simply do not provide an output for unwrapped positions).
Moreover, if an interactive job is used, it is possible that job.structure.positions does not return the initial positions, i.e. job.structure.positions+job.output.total_displacements won't be initial positions + displacements.
So, in short, my answer to your question would be rather "Use job['output/generic/unwrapped_positions'] and if it's not available, use job.structure.positions+job.output.total_displacements but be aware of potential problems you might be running into."

How would I find all paths between two nodes using cytoscape.js?

I have a telecommunications mesh network graph where there are multiple path between multiple nodes.
I want to be able to select 2 nodes and highlight all inter connected nodes and edges that make up the paths between them.
How would you recommend I tackle this?
I've tried using aStar, then removing the nodes and edges and reiterating, however some paths share edges so that didn't work.
To get all of the paths between two nodes in Cytoscape.js you can use the following:
function findPaths(src,dest) {
let successors = src.successors();
let predecessors = dest.predecessors();
return successors.intersection(predecessors);
}
This takes all of the nodes and edges from src and keeps only those that are also in the set of those leading to dest.
It does not enumerate the paths - it is just the full set of nodes and edges in the paths.
To actually enumerate all the individual possible paths (it can be a large number if you're dealing with a complex graph) you would do a depth first recursion on the results of this function. Each time dest is visited, you would display the path that led to the visit.

Gurobi Python - Add certain vars

I'm new to Gurobi and I'd like to know how to add certain variables to a model. For example, if I have an uncomplete graph, I'd like to add a variable x[i,j] for each arc of the graph. I don't want to add all the arcs of the complete graph, because it has a huge number of nodes and my computer runs out of memory. So I'm trying to avoid defining variables with lists for it's indexes.
Thanks in advance,
I think that you know arcs that you want to add. If it is that, you can define a set (list ou dict) of arcs like Arcs={(i,j): value of arc (i,j)}. This set concern only arcs that you want to add.
This is illustrated in the netflow.py example, which can be found in the examples\python subdirectory.

Variation (complex?) on the shortest path

I have the following problem. Given a directed graph G=(V,E) with edge costs cij between all edges {i,j}. We have multiple sources, say s1,...,sk, and one target, say t. The problem is to find the lowest combined costs going from s1,...sk to t, where the total amount of visited vertexes by all different paths is M. (The sources and target don't count as visited vertexes and 0 <= M <= |V|-k+1, so if M = 0 all paths go directly from source to target.)
I came up with the following, but haven't found a solution yet.
The problem is similar to multiple targets (t1,...,tk) and one source by just reversing all the edges and making the sources targets and the target source. I thought this could be useful since e.g. Dijkstra computes shortest path from one source to all other vertexes in the graph.
With just one target and one source one can find the shortest path with max. amount of visited vertexes M with the Bellman Ford algorithm. This is done by increasing the number of visited vertexes iteratively.
The problem of finding the shortest path from one source to one target while vertexes v1,...,vk have to be visited can, for small k, be solved as follows:
i) compute shortest path between all vertexes.
ii) check which of the k! permutations is the shortest.
I thought this could be useful when transforming my adjusted problem at 1) into the problem of going from one source to one "supertarget", with mandatory visits at the "old" targets t1=v1,...,tk=vk.
Unfortunately, combining 1, 2 and 3 doesn't provide a solution but it may help. Does anyone know the solution? Can this be solved efficiently?
Why not do a separate Dijkstra for each s, and later sum the costs?
Something like:
float totalCost;
for (int i=0; i<k; i++)
totalCost += Dijkstra(myGraph,s[i],t);
I hope I understood the question correctly.