A sample trip sequence with Connect APIs
To manage multiple trips and to use PC*Miler route options and features for each trip, you must build a trip using a sequence like the one below. It calculates mileage for a trip with multiple stops, and it optimizes the stop sequence to get the most efficient route:
-
Open a connection to the engine (PCMSOpenServer).
-
Create a new trip with PCMSNewTripWithRegion and reuse it, if possible, for future trips. If PC*Miler Worldwide data is installed you can create trips with another region.
TIP: Trips are thread safe so multiple threads can be created but do not share the trips across multiple threads. Create a number of trips and threads that match the number of CPUs. That is, an 8-CPU system should have 8 threads and one unique trip per thread.
-
Set the route type to use the PRACTICAL routing calculation (PCMSSetCalcTypeEx).
-
Set the unit of distance to MILES (PCMSSetMiles).
-
Clear stops from previous trip—use whenever multiple trips are generated (PCMSClearStops).
-
Validate stop names (PCMSLookUp with option 5).
-
Optionally use PCMSGetFmtMatch4 to get lat/longs with 6-digit precision.
-
Add a batch of stops to the trip’s route (PCMSAddStop).
-
Set the resequence mode to keep the final destination of the route the same (PCMSSetResequence).
-
(Optional) Optimize the stop sequence (PCMSOptimize).
-
Calculate a route and distances (PCMSCalculate).
-
Delete the trip (PCMSDeleteTrip).
-
Close down the engine (PCMSCloseServer).