Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 5 of 5

Handling Route that Calculates but does not Optimize

This is a discussion on Handling Route that Calculates but does not Optimize within the MapPoint Desktop Discussion forums, part of the Map Forums category; MapPoint Programming Challenge Come up with the best solution and get recognition in the next newsletter as well as receive ...

  1. #1
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    Handling Route that Calculates but does not Optimize

    MapPoint Programming Challenge

    Come up with the best solution and get recognition in the next newsletter as well as receive your choice of a Large MapPoint Mug or a AutoRoute 2004.



    Some collections of stops cannot be Optimized. If this is being done programmatically, execution hangs.

    A minimal example of a route that will not Optimize can be downloaded here:
    http://www.mp2kmag.com/downloads/florida_ptm.zip

    The route will calculate fine, but when you try to optimize, it returns an error "Unable to get directions from ... move one or both of the stops, and try again".

    Specifically, it is the route up on Hilton street that is preventing it from Optimizing, if you shift it even slightly it seems to be fine.

    So working Interactively, this is not really a problem. But programmatically from Excel, I am having trouble finding a way to trap for this condition.

    Stops can be tested and those that that are totally unroutable (stuck behind a one-way road or on a mini-road network not connected to the main road network) can be caught as an error is generated from this condition. You can then shift the individual stop's position until it works.

    Optimize does not generate a trappable error in the same way, it just hangs.

    Here's the same minimal route in Excel, the code is included below.
    http://www.mp2kmag.com/downloads/florida_xls.zip

    When you run it, you see MapPoint uses cpu for several minutes, then just gives up.. there is no error generated, it just hangs. (hit ctrl-alt-del and kill mappoint to get back to excel).

    How is it possible to detect this hanging or have it trigger and error and continue program execution without user intervention?

    Good luck!
    Eric

    Code:
    Private Sub CommandButton1_Click()
      'This will prevent the waiting for ole application warning from popping up
      Application.DisplayAlerts = False
    
      Set oApp = CreateObject("MapPoint.Application.NA.11")
      oApp.Visible = True
      Set objMap = oApp.NewMap
      Set objRoute = objMap.ActiveRoute
    
      For i = 2 To 5
        objRoute.WayPoints.Add objMap.GetLocation(Worksheets("Sheet1").Cells(i, 2), _
          Worksheets("Sheet1").Cells(i, 3)), Worksheets("Sheet1").Cells(i, 1)
      Next
      
      Stop
      'The route can be calculated i.e. all the stops are routable
      objRoute.Calculate
      
      Stop
      'It is this Optimize that hangs and unfortunately doesn't generate an error trappable
      'by Excel. The error only appears when working interactively with MapPoint.
      objRoute.WayPoints.Optimize
    
      'Set back to true
      Application.DisplayAlerts = False
    End Sub

  2. #2
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    MapPoint Programming Challenge - any solutions?

    Hey All,

    Did anybody come up with thoughts on the programming challenge? ("Some collections of stops cannot be Optimized. If this is being done programmatically, execution hangs.") I see no posts here... we'd much like some help with this one as it has us banging our heads.

    -Tom

  3. #3
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: MapPoint Programming Challenge - any solutions?

    Hi Tom,

    A workaround could be to create the mappoint component in a thread and execute it invisible. Or maybe the object model. After a certain timeout then kill the thread.

    However: I really dont know if the component or the object model or both are thread safe.

  4. #4
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4
    Oh, that's good I am not the only one. The best we have come up with is to have a separate (asynch) thread running to check for a failed (0 cpu usage) and hanging instance of MapPoint.

    Eric
    ~ Order MapPoint MapPoint 2013 Here and Get Free Access to the MapForums Downloads ~
    ~~
    ~ Upgrade to Get Access to the MapForums Downloads ~

  5. #5
    rskrzydlo is offline Junior Member White Belt
    Join Date
    Feb 2005
    Posts
    7

    trapping the error

    I use Visual foxpro to program rather than VB, but I am sure that you have the similar error trapping code to mine. In Visual Foxpro I had a similar problem where one location in the route created the error message that Mappoint was unable to find driving directions to that point. I simply put in an "ON ERROR" snippet that allowed me to perform other logic when this happened. In my case, I was looking for distances between 2 points so my on error section changed the calculation of distances from the calculate command to the distance as the crow flies which is less accurate but still close enough for my purposes.

    In your case, once you trap the problem with "ON ERROR" you can perhaps put in code to look for a nearby location that is calculable.

    At the very least, you are not stuck in limbo.

    Ralph Skrzydlo
    www.technologix.ca

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Optimize and calculate a Route
    By rms62 in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 08-22-2003, 03:55 PM
  2. Optimize a Route with Scheduled Time windows
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 07-09-2003, 07:20 AM
  3. Calculate route with Segment preferences vs optimize
    By David Kachuck in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 01-03-2003, 04:29 PM
  4. Route optimize: shortest vs quickest
    By David Kachuck in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 12-16-2002, 08:23 PM
  5. I am developing a VB application which calculates ....
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 04-04-2002, 02:26 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96