We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I'm trying to create an neighbor list for points in a nodal graph(set of points). Each point will have certain set of neighbor points. I'm trying to create this using arraylist of integer arraylist. I can declare one of the arraylist as objects of a class and use it to create a 2 dimensional array list. I have provided a sample of points below which expalins how the neighbor list looks like. Also i need to have flag array for each row of arraylist(0,1,2..) which will keep track of the points when i try to pick one of the neighbors from the list and use them to connect a line. and the same node should not be connected.
0 -> 1 4 5 6
1 -> 0 2 3 7
2 -> 4 3 5 9 11 12
3 -> ....................
Say, If 0 is connected to 1, 1 can't connect to zero and 1 should connect to some other points from the 2nd arraylist of neighbors ( 2 , 3 or 7).
Can you guys please help me provide a sample code using class objects and arraylist in java for the above scenario. It would be real helpful. Please. Thanks in advance
Answers
is this a 2D grid ?
with cells and neighbors?
@Chrisir , Thanks for your reply. Well it's not a 2d grid.
I have a set of points random points say 30 points. I'm trying to connect each point randomly with among its neighbors. So I'm trying to create a simplex where each point has a set of neighbors based on the distance constraint. for eg:
0 -> 1,2,4,8,10
1-> 0,3,5,11,15,16,17
2-> 0,4,8,10,9 . . . 29 -> 21,17,20,28,10
Such that after connecting all points, either it forms a loop or it doesn't.
One constraint while connecting the points is that any point can connect to a point only once and not the reverse way during its path and each point can be traversed only once. so i have to have a track of flag or pointers for each point such that when 0 connected to 1 doesn't go back and connect 1 to 0.
It's an array-list of array-list since both of them are dynamic in size. I have to add the neighbor points to the inner arraylist using class object(arraylist).
My code suits the requirements in its data structure, just make the necessary adjustments, e.g. distance constraint
eg. after line 8 say (pseudo code)
we took care of this:
It sounds like you have a very specific set of directed graph requirements, so this may not be relevant.
However, one algorithm for choosing edges to connect a set of random points is a Delaunay triangulation -- there is an implementation of this in the Processing mesh library.
@chrisir, I'm unable to understand the code. Can you please explain in detail. I'm sorry. Please forgive for my stupidity.
I just need a help to create a program for this scenario,
I have set of points point ( x , y )
Now i have to create a neighbor list for the set of 6 points, each point having it's neigbor list based on the distance constraint say <150 .
So the neighbor arraylist will look like
This simplex of neighbor list should be in a separate data structure so that it's global and i can use it in other places of my code.
==> ((1 3 4),(0 4),(3 4 5),(0 2),(0 1 2),(2)) - A two dimensional array list formed using a class object. A class having one of the object as arraylist and other arraylist declared in the main program.
Also, an additional flag pointer to keep track of the neighbor points, such that when 0 is connected to 1. 1 connects to other point namely 4 in our case and 2 connects to 3 or 5 and not 4.
Can you please write a code for this scenario.
is the numerber of points constant (6)
Do they not move so the neighbours are constant?
then make an array (the points) of arraylist (the neighbours)?
you wrote: So the neighbor arraylist will look like
do you mean : point number - neighbours as the index of the points?
?
my approach qoes just what you require, it just uses a class and objects.
are you familiar with that?
The points are in an ArrayList named grid
each point has an index (0,1,2...) and an ArrayList of its own for its neighbours
@chrisir , Thank you chris. It seems to be working now. Just one doubt. How do i access and print the arraylist. both the outer arraylist and the innerarraylist.
??
You need to understand classes and objects and oop when you want to understand this. See tutorial on this objects.
Anyway: the outer ArrayList is addressed in lines 22 to 24
The inner ArrayList that each point owns: 51 to 54
You could easily make a list for println when you copy both parts to a double for loop
new version that shows the primary
Arraylist
and also the inner ArrayList of each object at the end ofsetup()
asprintln
:I named the for-loops as
// 1st control loop
and// 2nd control loop
: