Unwrapping a toroid into 2D space using only point neighbours - arrays

I'm trying to come up with an algorithm that can unwrap a toroid into a 2D array so I can address the various points using X, Y coordinates and walk over the mesh in a consistent manner.
My problem is that I don't have a whole lot of information to work with. I've got a list of uniquely identified points that make up the toroid, but the integer identifiers are randomized and non-contigous. I've got a list of neighbours associated with each point, but that list is an unordered set.
Somehow, I need to pick a starting point (presumably the point with the lowest identifier integer), then iterate over the entire mesh in such a way that I land up with a 2D array that describes the identifiers of each point as they're laid out across the toroid surface.
How would I best go about solving something like this?

If you have 2D toroid and you want to put him into 2D array with "neighbours" data, you can do this by this metod.
Toroid is symmetric, therefore you can take any point you want first and put him anywhere into array. I will put it into middle of array, but you can even start in corner, it does not matter.
For 5 x 5 toroid you create 5 x 5 array
X - X - X - X - X
X - X - X - X - X
X - X - X - X - X
X - X - X - X - X
X - X - X - X - X
You take one from your list and put him into middle
X - X - X - X - X
X - X - X - X - X
X - X - O - X - X
X - X - X - X - X
X - X - X - X - X
Now you want to find these neighbours N identified by neighbour of neighbour F. It is quite easy :
Find all neighbours of O
Create pairs between them
If pair of nodes have two same neighbours, remember them. The one of them is O (the first one) the second is new one F.
The first pair which fulfilled conditions :
X - X - X - X - X
X - X - N - F - X
X - X - O - N - X
X - X - X - X - X
X - X - X - X - X
You can get 4 pairs (at each direction), but because of symmetric structure, you can just take one and put it to that array
X - X - X - X - X
X - X - O - O - X
X - X - O - O - X
X - X - X - X - X
X - X - X - X - X
Now you have finally positioned the toroid to something and you can start filling it with values.
Look to these "N" nodes
X - X - X - X - X
X - X - O - O - X
X - X - O - O - X
X - X - N - N - X
X - X - X - X - X
Only two exact nodes fulfill these conditions. You already have "O" nodes in array, therefore you know their position. If I mark the important ones (in this step) as 1 and 2, it looks like this
X - X - X - X - X
X - X - O - O - X
X - X - 1 - 2 - X
X - X - N - N - X
X - X - X - X - X
And only two unrevealed nodes fulfill this : "N1 is connected to 1; N2 is connected to 2; N1 and N2 are connected". Therefore you find them and put them in.
X - X - X - X - X
X - X - O - O - X
X - X - O - O - X
X - X - O - O - X
X - X - X - X - X
You can finish whole line with this approach
X - X - O - O - X
X - X - O - O - X
X - X - O - O - X
X - X - O - O - X
X - X - O - O - X
And now you can do the same to the other direction
X - X - O - O - X
O - O - O - O - O
O - O - O - O - O
X - X - O - O - X
X - X - O - O - X
And then another one
X - X - O - O - X
O - O - O - O - O
O - O - O - O - O
O - O - O - O - O
O - O - O - O - O
And last
O - O - O - O - O
O - O - O - O - O
O - O - O - O - O
O - O - O - O - O
O - O - O - O - O

Related

How to get character like go down stairs in Google Sheets

I want to get a character from string but the path is like going downstairs in Google Sheets
The string is like:
y C I 6 8 V 5
~5 Z n I L w f
V ~s i w J d _
o R ~4 2 i v f
9 ^ j ~h r u #
Z y Q 7 ~1 u a
T t z u _ ~! Q
G Y n r * t ~^
J A l v F j d
a 2 l - y O B
h B w % n a 4
M t _ P D W a
And expect the output is:
5 s 4 h 1 ! ^
I put ~ in front of the character that demo the path I want to get.
The logic is I will find the first column which cell is 5 and then get start from that cell.
Example sheet link
https://docs.google.com/spreadsheets/d/1UQEGEl_rqAMFePDAGoueTI47xF8T_DyrvJ3de5pkLRA/edit#gid=306981885
I tried auto-fill but it could only incrementally either row or column. And I hope to incremental both row and column.
={INDIRECT("A"&MATCH(5, A1:A14, 0)),
INDIRECT("B"&MATCH(5, A1:A14, 0)+1),
INDIRECT("C"&MATCH(5, A1:A14, 0)+2),
INDIRECT("D"&MATCH(5, A1:A14, 0)+3),
INDIRECT("E"&MATCH(5, A1:A14, 0)+4),
INDIRECT("F"&MATCH(5, A1:A14, 0)+5),
INDIRECT("G"&MATCH(5, A1:A14, 0)+6)}
for a large scale scenario you can use this one and drag it to the right:
=INDIRECT(ADDRESS(MATCH(5, $A1:$A14, 0)+COLUMN()-1, COLUMN(), 4))
You can also do it with an array formula if you want to:
=ArrayFormula(hlookup(column(A2:G13),{column(A2:G13);A2:G13},match(5,A2:A13,0)+column(A2:G13)))

Supress/remove repeated values in Jdeveloper/ADF Table column

I need to supress the repeated values in a table so it will look like:
x y z
- - u
- b z
- - u
y y z
- - u
instead:
x y z
x y u
x b z
x b u
y y z
y y u
In Oracle OBI I can do that editing column properties of a table:
But I can't find this option in column/table properties from Jdeveloper, there is a way to do this?
You can't do this in a table.
You can use a pivot table to do this.
Or you can use an af:iterator to create this type of UI.

How to find the shortest path in 2D Array with multiple endpoints?

I have a program that creates a 2D array that looks similar to this:
X X X X X X X B X X
B X X X X X X X X X
B X X X X X X X X X
X X X X X X X B X X
X X X X X O B X X X
B X X X X X B X X X
X X X X X X X X X X
X X X X X X X X X X
X = empty space free to roam
B = blocked areas not free to roam
O = object being moved
And I would like help on figuring out how to find the shortest paths to any of the end points. Normally I would of used the Dijkstra's Algorithm however I have multiple points that are to be considered instead of having 1 point. The point of the object is getting to the edge and I would like to find the shortest path there.
Lee's algorithm: http://en.wikipedia.org/wiki/Lee_algorithm
It's essentially a BF search, here's an example: http://www.oop.rwth-aachen.de/documents/oop-2007/sss-oop-2007.pdf
To implement it effectively, check out: Change FloodFill-Algorithm to get Voronoi Territory for two data points? - when I say mark, you mark it with the number on the position you came from + 1.
For example, if you have this grid, where a * = obstacle and you can move up, down, left and right, and you start from S and must go to D, and 0 = free position:
S 0 0 0
* * 0 *
* 0 0 *
0 0 * *
* 0 0 D
You put S in your queue, then "expand" it:
S 1 0 0
* * 0 *
* 0 0 *
0 0 * *
* 0 0 D
Then expand all of its neighbours:
S 1 2 0
* * 0 *
* 0 0 *
0 0 * *
* 0 0 D
And all of those neighbours' neighbours:
S 1 2 3
* * 3 *
* 0 0 *
0 0 * *
* 0 0 D
And so on, in the end you'll get:
S 1 2 3
* * 3 *
* 5 4 *
7 6 * *
* 7 8 9
So the distance from S to D is 9. The running time is O(NM), where N = number of lines and M = number of columns. I think this is the easiest algorithm to implement on grids, and it's also very efficient in practice. It should be faster than a classical dijkstra, although dijkstra might win if you implement it using heaps.
Do this for any starting point and endpoint and chose the endpoint with the lowest integer in your case.

How to define some variables as non-commutative in Maxima

For example, I'd like to define x and y as non-commutative, and a and b as commutative (as usual). In other words,
x y ≠ y x, a x = x a, a b = b a .
Further,
(x + a y) (x - a y) = x^2 + a (y x - x y) - a^2 y^2 .
What is a code for defining x and y, and a symbol for multiplication (such as * and . ) ?
You can work with Maxima's commutative * and non-commutative . products in the way that you want by following the next two steps:
Declare the symbols a and b as scalars:
declare([a, b], scalar)$
Enable dotscrules:
dotscrules: true$
This simplifies non-commutative products involving scalars to commutative products (i.e., a.x becomes a*x).
Now you are ready. For example,
expand((a*x + b*y) . (a*x - b*y))
returns
a*b*y.x - b^2*y^^2 - a*b*x.y + a^2*x^^2
(note that ^^ is the non-commutative exponentiation operator).

tsql conditional maths equation

I need to perform some summations during a select query however depending on 2 values i will need to perform a different equation. hopefully an example will demonstrate
basically i need to perform the following summations
if x > y then (x - y + z) or
if x < y then (x - x + z) basically i am setting this to 0.
So far i thought that i could use 2 tables to dump the x > y values and the x < y values and then perform the relevant equations.
any ideas
You can use a case expression.
select case
when x > y then x - y + z
when x < y then x - x + z
else 0 -- x = y
end
from YourTable

Resources