tpm_tracebestroute

Land Desktop Development ARX CPP SDK

Up a level
tpm_tracebestroute
 
 

Calculates the best round-trip route.

ade_id

tpm_tracebestroute

ade_id tpm_id,

ade_id trace_id,

struct resbuf *nodes);

Returns a topology ID or ADE_NULLID.

tpm_id The topology ID representing the network you are analyzing.
trace_id The tracing model ID returned by tpm_tracealloc.
nodes List of nodes to visit.

The list of nodes is implemented as a resbuf chain, which you can create like this:

struct resbuf* pNodeListRb = acutBuildList(
                                            RTREAL, 8.0,// start node
                                            RTREAL, 1.0,// visit point 1
                                            RTREAL, 5.0,
                                            RTREAL, 11.0,
                                            RTREAL, 6.0,
                                            RTREAL, 7.0,
                                            RTREAL, 10.0,
                                            RTREAL, 13.0,
                                            RTREAL, 12.0,
                                            RTREAL, 9.0,
                                            RTREAL, 4.0,
                                            RTREAL, 2.0,// visit point 11
                                            0);

The best route topology, whose ID this function returns if successful, is assigned an arbitrary name and is open for read. To get its name, use tpm_infoname. To change its name, use tpm_mntrename.

For the best route trace to succeed, the total calculated resistance cannot be greater than the value set for the maximum resistance or less than the value set for the minimum resistance. See tpm_tracesetmaxres and tpm_tracesetminres. The accumulated resistance value is the total resistance of the nodes and links that make up the best route.

The following sample creates a best route using tpm_tracebestroute(). The tpm_id param is obtained using tpm_acload() and tpm_acopen(). The trace_id param is obtained using tpm_tracealloc(). A resbuf containing the list of nodes which serve as visit points is then created. Tpm_tracebestroute() is called with all required parameters, the returned value is checked against ADE_NULLID. A successful operation displays the name of the best route topology. The resbuf is then released as required.

char* pszTopoName = "NetTopo";
int topoWriteAccess = 1;
int returnCode = tpm_acload(pszTopoName, NULL);
ade_id topoId = tpm_acopen(pszTopoName, topoWriteAccess);
ade_id traceId = tpm_tracealloc(topoId, NULL, NULL, NULL, NULL);
struct resbuf* pNodeListRb = acutBuildList(
                                            RTREAL, 8.0,
                                            RTREAL, 1.0,
                                            RTREAL, 5.0,
                                            RTREAL, 11.0,
                                            RTREAL, 6.0,
                                            RTREAL, 7.0,
                                            RTREAL, 10.0,
                                            RTREAL, 13.0,
                                            RTREAL, 12.0,
                                            RTREAL, 9.0,
                                            RTREAL, 4.0,
                                            RTREAL, 2.0,
                                            0);
ade_id bestRouteTraceId = tpm_tracebestroute(topoId, traceId, pNodeListRb);
if (bestRouteTraceId != ADE_NULLID) {
    char pszBestRouteName[25];
    int topoNameLen = 25;
    int returnCode = tpm_infoname(bestRouteTraceId, pszBestRouteName, topoNameLen);
    if (RTNORM == returnCode){
        acutPrintf(
            "\n\nThe best route is named: \"%s\"."
            , pszBestRouteName);
    }
    else {
        acutPrintf(
            "\nNo best route could be calculated.");
    }
}
acutRelRb(pNodeListRb);
tpm_acclose(topoId);
tpm_acunload(pszTopoName);