MapPoint Forums

MapForums

Community of MapPoint and Bing Maps Users and Developers




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 ...


Go Back   MapPoint Forums > Map Forums > MapPoint Desktop Discussion

Today's Posts Twitter Feed Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-19-2004
Eric Frost's Avatar
Senior Member
Black Belt
 
Join Date: Jul 1992
Posts: 3,503
Blog Entries: 3
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 01-28-2005
Senior Member
Black Belt
 
Join Date: Jul 2002
Posts: 5,138
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 01-29-2005
Senior Member
Black Belt
 
Join Date: Nov 2004
Location: Belgium
Posts: 2,318
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 01-29-2005
Eric Frost's Avatar
Senior Member
Black Belt
 
Join Date: Jul 1992
Posts: 3,503
Blog Entries: 3
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
__________________
~ Now taking orders for MapPoint 2010 ~
~~
~ Upgrade to MapForums Plus membership ~
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 03-07-2005
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
calculates, handling, optimize, route


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

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


All times are GMT -5. The time now is 08:14 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
MP2K Magazine
Visitor Map



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