Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Your example has 36 cells with only 11 non positive ones. That means only one third of the cells need to be skipped.

After excluding start and stop it's obvious that the best theoretical result is to pass by all remaining 24=34-10 positive ones exactly one time, hence in minimal 25 moves.

tybalt89 has demonstrated that such a path exists, provided his "slides" were legal. (I already expressed my doubt. Please clarify!!! )

Now the following is based on the assumption these slides were correct.

If your 50000x50000 matrix has the same density of > 2/3 positive ones, than the likelihood to find a trivial but optimal solution is very high.

To achieve this I'd reshuffle the matrix by putting the start and end cell at opposing corners.

The rows and columns in between then need to be sorted ascending by number of positive cells.

The trivial solution is based on the fact that you can always reach all positive cells inside your actual row (or column in a dual approach).

What really matters is the jump to the next row with a positive cell in the same column.

(NB: That approach is symmetric by swapping rows and columns)

This is hardest with rows with low density and becomes easier afterwards, hence the pre-sorting.

If this trivial solution fails, you'll still be able to construct a nearly optimal solution by including some non positive cells.

That's a pragmatic approach to ignore the possibility of a slightly better solution, which is much harder to compute.

But this should finish in reasonable time.

HTH!

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re: Highest total sum path problem by LanX
in thread Highest total sum path problem by baxy77bax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-16 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found