Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-04 Thread Henry Rich
I have put my solution to this problem in http://code.jsoftware.com/wiki/Essays/PropagatingMinimum The details are a little different, but the basic idea is the same. Henry Rich On 3/2/2016 3:15 PM, Brian Schott wrote: Oops, I forgot to enter "the following sentence": expand;<./@lineup each

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-02 Thread Brian Schott
Oops, I forgot to enter "the following sentence": expand;<./@lineup each DD([,+)each each PP On Wed, Mar 2, 2016 at 3:14 PM, Brian Schott wrote: > Upon a closer look, and Henry's earlier comment (see below) regarding "...the > little piece excP...", and noticing that my most recent last line re

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-02 Thread Brian Schott
Upon a closer look, and Henry's earlier comment (see below) regarding "...the little piece excP...", and noticing that my most recent last line really requires that the verb excD (which is almost identical to excP)must be executed at each step also, I can tell more efficiency is required. I am say

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-02 Thread Brian Schott
I have a faster script which pre processes all the lines except the line. Only the last line is executed at each step. The boxing, lining up, and unboxing worries me, but this is a speed improvement, for me. H =: 99 NB. can be any large value, like 1e6 L =: _1 D =: H, H, 1, H, 5, H, 8, H, 11, L,

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-01 Thread Henry Rich
Yes, an external process updates the data D but not the penalties (or the positions of the blockages indicated by L). This code gets called maybe 2000-5000 times on a list of length 100 or so and needs to take less than 0.1 seconds to run all the iterations. Henry Rich On 3/1/2016 3:51 PM, J

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-01 Thread Joe Bogner
Raul, yes, that helps. Thanks I'm not entirely clear about the performance issues with any of the approaches outlined. It would be useful to be able to simulate that I think so any of the approaches outlined or new ones could be tested. It sounds like the approach will be called multiple times pe

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-01 Thread Raul Miller
I implemented what I think is a scalar model of how this could work: H =: 1e6 L =: _1 D =: H, H, 1, H, 5, H, 8, H, 11, L, L, H, H, 20,3 P =: 1, 1, 1, 2, 4, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2 mdi=:dyad define x+y P=.x r=. D=.y for_j. }.i.#D do. p=. j{P d0=. (j-1){D d1=. j{D if.

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-01 Thread Joe Bogner
Henry, just curious, do you have a scalar solution to the problem? You mentioned it'd be trivial to write so I was curious if there is one. It'd be helpful to compare against. Is the pseudocode on wikipedia what you had in mind? https://en.wikipedia.org/wiki/A*_search_algorithm#Pseudocode On Mo

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-01 Thread Henry Rich
You can avoid splitting the input into sections. Henry Rich On 3/1/2016 7:52 AM, Brian Schott wrote: By not needing to calculate the whole thing, do you mean that because the L's are permanent you only need to calculate the sums for sections between the Ls, or is there something else? On Tue,

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-01 Thread Brian Schott
By not needing to calculate the whole thing, do you mean that because the L's are permanent you only need to calculate the sums for sections between the Ls, or is there something else? On Tue, Mar 1, 2016 at 7:39 AM, Henry Rich wrote: > Now you're talkin'. You don't have to calculate the entire

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-01 Thread Henry Rich
Now you're talkin'. You don't have to calculate the entire +/\\. either. FSM is not needed. Henry Rich On 3/1/2016 7:35 AM, Brian Schott wrote: Henry, I suspect the trick is that the list P does not change and that +/\\. can be precalculated (perhaps with boxed lists of sums), and then reus

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-01 Thread Brian Schott
Henry, I suspect the trick is that the list P does not change and that +/\\. can be precalculated (perhaps with boxed lists of sums), and then reused when D changes. Maybe even an fsm could be developed to combine the new D's. What say you? -- (B=) -

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-03-01 Thread Brian Schott
Henry, I can now see how a slight improvement on D++/\\.P can accomplish the desired result, but can you say if even that much is too slow. If that is not two slow, then my next question is this: The +/\\.P constructs a square matrix with incrementally more 0 fills on each row. I want the fills

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-29 Thread Henry Rich
I can't follow what the verb is doing, but I tried it on some other cases & it produced correct results. Needless to say, a much faster version is needed. Even the little piece excP, which potentially runs the verb < on each atom, would be too slow. Henry Rich On 2/29/2016 5:36 PM, Brian Sc

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-29 Thread Brian Schott
I have a non iterative script which seems to work on the test sample. Can you tell me if it works more generally, please? H =: 99 NB. can be any large value, like 1e6 L =: _1 D =: H, H, 1, H, 5, H, 8, H, 11, L, L, H, H, 20,3 P =: 1, 1, 1, 2, 4, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2 excP =: (1,L=])<;._1

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-26 Thread Henry Rich
No. The first atom of the array might potentially affect the result in the last atom. I need a method that takes at most a couple of dozen machine instructions per atom. Any method that starts a verb on each atom of the array is too slow. Henry Rich On 2/25/2016 10:35 PM, Brian Schott wr

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-25 Thread Brian Schott
Does your really fast algorithm start with something like my mask, but instead of a while. loop on the whole array, do you just check to update the indices one above each altered atom of the revised D? On Wed, Feb 24, 2016 at 11:43 AM, Henry Rich wrote: > That looks like the right result. > > He

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-24 Thread Henry Rich
That looks like the right result. Henry Rich On 2/24/2016 11:20 AM, Brian Schott wrote: Not FAST, but is this correct? H =. 1e6 L =. _1 D =: H, H, 1, H, 5, H, 8, H, 11, L, L, H, H, 20,3 P =: 1, 1, 1, 2, 4, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2 proc=: dyad define P=. x D=. y while

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-24 Thread Brian Schott
Not FAST, but is this correct? H =. 1e6 L =. _1 D =: H, H, 1, H, 5, H, 8, H, 11, L, L, H, H, 20,3 P =: 1, 1, 1, 2, 4, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2 proc=: dyad define P=. x D=. y while. +./mask=.(L~:H,}:D)*.D>D<.P+H,}:D do. D=. mask{"0 1|: D,:P+H,}:D end. D ) D,:P proc D 100

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-23 Thread Henry Rich
You are right, the last 2 atoms could be *s. Penalties & distances are measured in the same units & are essentially the same in this context. To move to a new atom you must pay a penalty and traverse a distance, both of which are rolled into the value in P. D holds accumulated values of P, e

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-23 Thread Brian Schott
Henry, Why in your example answer for D aren't the rightmost 2 atoms *s, since they have not changed from 20 and 3? Does that suggest that the "new" 20 and 3 are calculated but that you are not giving their calculations? Also you say, "An atom of D indicates the minimum number of penalty points t

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-23 Thread Henry Rich
'proc' has the right idea, but CP+<./\ CD does not take into account all the P values between the minimum point found by <./\CD and the point that the minimum value is being propagated to. It adds in only the last P. [Also it doesn't prevent a value from affecting results on the other side of

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-22 Thread Raul Miller
So, ok, maybe we can talk a bit more about the system this fits into, in dissect? Please forgive me for being slow, I'm not thinking about this very well at the moment. My first attempt at an implementation looked like this: H =. 1e6 L =. _1 D =: H, H, 1, H, 5, H, 8, H, 11, L, L, H, H, 20,3 P =:

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-22 Thread Henry Rich
No, the weights are fixed. I am implementing essentially the A* algorithm: https://en.wikipedia.org/wiki/A*_search_algorithm The code is for dissect: given a number of blocks and a set of (source,destination) pairs, find paths to connect the pairs, on a discrete routing grid. One important

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-22 Thread Michal Wallace
Huh? :) I'm not sure I understand what any of this has to do with finding a shortest path. You say D is a list of ordered distances... Distances between what? Is the idea that you have a graph, with a fixed number of nodes, but the edge costs have shifting weights for some reason? (Like say, tr

Re: [Jprogramming] A practical problem: minimum distance with penalties

2016-02-22 Thread Henry Rich
I left out one important point. The list P, and the locations of blocked-off sections of D, do not change over the many iterations of the verb you are asked to design. They represent the obstacles that the router is trying to avoid. What changes between iterations is the non-blocked values o

[Jprogramming] A practical problem: minimum distance with penalties

2016-02-22 Thread Henry Rich
This task shows J in my hands at its best and its worst. Best, because I found a good solution; worst, because it took me 4 hours to come up with something that would have been trivial in a scalar language. See what you can do with it. The task is to write a REALLY FAST program to solve the