Thanks, I will have a go.

Stewart.

On 30 May 2018 at 18:33, Sean Luke <[log in to unmask]> wrote:
Got it.

While I understand the consternation, I don't think this is a bug.  The way the locations lookup code works is by first identifying and adding into bags the relevant elements, and THEN optionally removing the origin.  That's somewhat faster than checking for the origin and optionally removing it along the way.

The origin is removed by using the remove(...) function on intBag.  This function works by swapping the removed-element with the top element, then just reducing the size of the bag by 1.  That's better than swapping everything down by 1, but as a result the top element in the bag is now out of order -- it's where the origin was.  That's the out of order thing you're seeing.

There aren't any guarantees that the locations or neighbors will be in any particular order -- you should view them as a set rather than a list.  And I  am hesitant to modify the code otherwise.  HOWEVER there is a solution for you.

In AbstractGrid2D and AbstractGrid3D there are the following methods:

protected void removeOrigin(int x, int y, IntBag xPos, IntBag yPos);
protected void removeOriginToroidal(int x, int y, IntBag xPos, IntBag yPos)

If you look at these methods you'll see that they use remove(...). 

Make a subclass of the grid class you're using (say, MyObjectGrid2D).  Then copy these methods into that subclass, but replace references to remove(...) with removeNondestructively(...).  You'll probably get better results then.

Sean


> On May 30, 2018, at 3:04 AM, Stewart Aitken <00000068a29a4109-dmarc-[log in to unmask]> wrote:
>
> Hello Sean,
>
> Modified Test.java for your attention.
> The incorrect listing is in "Neighbors - false exclude origin".
> In each case the list order is different between the include and exclude output.
>
> Observe the printout and you will see what I mean.
>
> Stewart.
>
> On 16 May 2018 at 21:28, Sean Luke <[log in to unmask]> wrote:
> getVonNeumannNeighbors calls getVonNeumannLocations to get locations, then extracts the elements at those locations.  So if you're having issues with the wrong stuff being returned, with a high probability it's getVonNeumannLocations.
>
> Sean
>
> > On May 16, 2018, at 3:27 PM, Stewart Aitken <00000068a29a4109-dmarc-[log in to unmask]> wrote:
> >
> > Thanks Sean,
> >
> > One thing that strikes me straight away is you are using:
> >
> > grid.getVonNeumannLocations(0, 8, 1, Grid2D.BOUNDED, true, xs, ys);
> >
> > and I am using:
> >
> > mySpace.getVonNeumannNeighbors(myX, myY, hop, Grid2D.BOUNDED, true, result, xNeighbors, yNeighbors);
> >
> > Is this incorrect?
> >
> > Having run your Test.java, I get the same results as you.
> >
> > Kind regards,
> >
> > Stewart.
> >
> >
> >
> >
> > On 15 May 2018 at 21:37, Sean Luke <[log in to unmask]> wrote:
> > > On May 12, 2018, at 3:36 PM, Stewart Aitken <00000068a29a4109-dmarc-[log in to unmask]> wrote:
> > >
> > > Hi Sean,
> > >
> > > Downloaded all of the updated files and added them to my MASON project in eclipse,
> > > carried out a clean and rebuild and it made no difference.
> > >
> > > Here are some outputs from the von Neumann Neighbourhood:
> > > Remember, the width and height count from 1 and the outputs count from 0.
> > > That accounts for the difference seen.
> >
> >
> > I'm sorry Stewart, but your message was just too cryptic to parse.  To nail down your problem, I need a specific and simple example, in code, of expected results and deviations.  To get you started, I made a little test program which prints out location results from the distance=1 von Neumann neighborhood at various locations in a 7x15 grid and with various modes.  You could modify this to find an example where it's producing the wrong results. [so far it seems correct]
> >
> >
> >
> >
> > Sean
> >
> > Here's what I'm getting printed out in the current version of MASON BTW:
> >
> >
> >
> > Bounded 7x15 Center: (0,8)
> > 0: (0, 7)
> > 1: (0, 8)
> > 2: (0, 9)
> > 3: (1, 8)
> > Unbounded 7x15 Center: (0,8)
> > 0: (-1, 8)
> > 1: (0, 7)
> > 2: (0, 8)
> > 3: (0, 9)
> > 4: (1, 8)
> > Toroidal 7x15 Center: (0,8)
> > 0: (6, 8)
> > 1: (0, 7)
> > 2: (0, 8)
> > 3: (0, 9)
> > 4: (1, 8)
> > Bounded 7x15 Center: (0,0)
> > 0: (0, 0)
> > 1: (0, 1)
> > 2: (1, 0)
> > Unbounded 7x15 Center: (0,0)
> > 0: (-1, 0)
> > 1: (0, -1)
> > 2: (0, 0)
> > 3: (0, 1)
> > 4: (1, 0)
> > Toroidal 7x15 Center: (0,0)
> > 0: (6, 0)
> > 1: (0, 14)
> > 2: (0, 0)
> > 3: (0, 1)
> > 4: (1, 0)
> > Bounded 7x15 Center: (6, 14)
> > 0: (5, 14)
> > 1: (6, 13)
> > 2: (6, 14)
> > Unbounded 7x15 Center: (6, 14)
> > 0: (5, 14)
> > 1: (6, 13)
> > 2: (6, 14)
> > 3: (6, 15)
> > 4: (7, 14)
> > Toroidal 7x15 Center: (6, 14)
> > 0: (5, 14)
> > 1: (6, 13)
> > 2: (6, 14)
> > 3: (6, 0)
> > 4: (0, 14)
> > Bounded 7x15 Center: (4, 0)
> > 0: (3, 0)
> > 1: (4, 0)
> > 2: (4, 1)
> > 3: (5, 0)
> > Unbounded 7x15 Center: (4, 0)
> > 0: (3, 0)
> > 1: (4, -1)
> > 2: (4, 0)
> > 3: (4, 1)
> > 4: (5, 0)
> > Toroidal 7x15 Center: (4, 0)
> > 0: (3, 0)
> > 1: (4, 14)
> > 2: (4, 0)
> > 3: (4, 1)
> > 4: (5, 0)
> > Bounded 7x15 Center: (4, 8)
> > 0: (3, 8)
> > 1: (4, 7)
> > 2: (4, 8)
> > 3: (4, 9)
> > 4: (5, 8)
> > Unbounded 7x15 Center: (4, 8)
> > 0: (3, 8)
> > 1: (4, 7)
> > 2: (4, 8)
> > 3: (4, 9)
> > 4: (5, 8)
> > Toroidal 7x15 Center: (4, 8)
> > 0: (3, 8)
> > 1: (4, 7)
> > 2: (4, 8)
> > 3: (4, 9)
> > 4: (5, 8)
> >
> >
> >
> >
> >
> > --
> >
> >
> >
> > EMAIL DISCLAIMER http://secure-web.cisco.com/1ejZdv09xipqWR5r9Pp1BOI1wCXg-Mw7_OS6HIE19wLC0KMJYrr15cKvsEeBqXSqQROtbGcjFVQYzS1dH8rrLqfu9keBZFOwTORhpS6nv03iK3n4Rfprcyye4-E6ncmWCQt2qyCT8O6DOP6Bzba8FMMtjP9m9GcIPzCx8jVG3s2TBK95C2QlkDIqiojxkfqtyY-v2y-ePSDVdps9QzfDGym6J-Ppo1Gp-sXLRW3hGyr1T4oQs-dzpb46WVVrynykUX1Lu_iwbBwIcHpTt_JSY5-NN156rzA_xvLlWf-Neq1JEgnBDWa5jElATLlvhFqVwW1W_qoDkcGujOBdcqSvrAaOrwo-sdpC_ASSxHbHrekIxJOGHNyNxsxjt2bshRCCoxVzj6xcSZUaLQpoSrypVLNxDCC01KXo7QaE_8kHt7xYyDFDAEI01fJZbYTiuEGe0fodYtyq9UInEFdGFRtBeyA/http%3A%2F%2Fwww.york.ac.uk%2Fdocs%2Fdisclaimer%2Femail.htm
>
>
>
> --
>
>
>
> EMAIL DISCLAIMER http://secure-web.cisco.com/1EvTWGf5VItEdcx3BgvUIuQ3s9TWVSgySPvdOz2n__G6eYTaeb0ndV2rnWmtr1fSlqyJXn86TkODpdGYQgH6swkdo5eejDbh4ObOvK1ZVwks07kpnkNDZ2WpwPHLrfK3wJhVbz2lMUQBr_BTCITHdhgbVUPds2CBmgJQYEZAZSIjoVC167C0rKB-XlrLQofe3utGX6hxO0bCFxUh3GqSZ52nBNKyyHbNVABX8rTZ-OT0nbl4TVLHkh1T7aNR1DIwrGW-rxBq8SRyHsqwFIW6j7c0bhqgaMcgVcReVu7dbdcRw6_7doVcxTX9YfgO2fFr4lyI_j6NdCG0INnVHuhNjJzjK9ASwYqNwzcnn0nN0sEHbqCLzxwpbWpMPxRR_RVo-iabxJlzS2geGdl_j_i_GMg80S5uCvbJohRxO-Y2C031aRHpqJ_i39amvzobSkkcUN0W4TiYXqgIRawtSZUcgDQ/http%3A%2F%2Fwww.york.ac.uk%2Fdocs%2Fdisclaimer%2Femail.htm

>





--



EMAIL DISCLAIMER http://www.york.ac.uk/docs/disclaimer/email.htm