Thanks, Raul. Some of these changes are great.

A few aren't what I'm looking for though. One of the biggest is that while
my example happened to have steps with uniform length, I'd like my A*
program to work on arbitrary graphs, where a step from one space to another
can have any non-negative real length. Thus it doesn't work to simply count
the length of the path for the general case.

For validIn, it seems like the right half of the outermost fork ((|~ #)
-:"1 [) is checking for within-bounds-ness of the index parameter.
Unfortunately, I think it fails for higher-dimensional cases like index 0 3
0 of array of shape 2 5 2.
Example:
  0 3 0 ((|~ #) -:"1 [) i.2 5 2 NB. Returns 0, which is a bug
I'm pretty sure this is because you're checking the residue of only the
first dimension, so if the dimensions aren't the same size you get bugs.
(An identical bug exists on the left half of the outermost fork.)

Here's my newest version, with some of your changes incorporated, and some
changes inspired by your work: http://pastebin.com/RjQA69j6

Thanks!
 - Max

P.S. If you're having trouble understanding the dynamic-cost nature of A*,
consider the following extendPath function:

gridExtendPathWithSwampsInsteadOfHoles =: 1 : 0
oldDist  =. > {. y
path     =. > {: y
newPoses =. (1:"0 m) gridNeighbors {: path
newPaths =. path ,"_ 1 newPoses
newDists =. 6 + oldDist - 5*(m atIndex newPoses)
newDists (; <)"_1 newPaths
)

On Tue, Jul 10, 2012 at 5:29 PM, Raul Miller <rauldmil...@gmail.com> wrote:

> There's a change I am tempted to make, but I think it would make the
> code more complex.
>
> So, instead, here's some "simplifications":
>
> http://pastebin.com/xa5cgLwF
>
> Here's a brief recap of my thinking:
>
> J nouns know how big they are, so we should not add complexity to our
> data structures to keep a redundant copy of this kind of information.
>
> J verbs like to deal with collections, and letting them do that can
> eliminate redundant processing.
>
> J adverbs can generate "bytecode" if we keep their jobs simple enough,
> so that's probably good.
>
> We should be able to make g be a rank 3 array without any other code
> changes (our starting and ending locations would also have to have 3
> elements).  Untested.
>
> Instead of reversing our lists of indices every time we use them, why
> not just transpose the grid once?
>
> (You can always add an explicit rank to a verb if you feel like
> writing one that doesn't want to deal with collections.  So I think
> that these changes should be fine from a modularity point of view.)
>
> FYI,
>
> --
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to