Use of ngraph.path library in Palantir - Foundry

62 Views Asked by At

I'm trying to utilise the aStar algorithm in the ngraph.path library in Palantir - Foundry. With the problems I've had, I'm wondering if the library, or at least the aStar function, is incompatible with Palantir. Any help anyone can give me is much appreciated.

This is error I get when I try and run the Typescript function I've written.

(0 , a.default) is not a function.
Error Parameters: {}
TypeError: (0 , a.default) is not a function
    at u.Optimum_Path (UserCode:28:66486)
    at te.executeFunctionInternal (FunctionsIsolateRuntimePackage:2:910734)
    at Oe (FunctionsIsolateRuntimePackage:2:909762)
    at async te.executeFunction (FunctionsIsolateRuntimePackage:2:910105)
    at async userFunction (FunctionsInitialization:8:43)

This is the function I wrote:

import { Function, Integer, Double, Float,OntologyEditFunction , Edits, DoublePropertyBaseType, GeoPoint  } from "@foundry/functions-api";
import { Objects, Ports, Nodes, Edges} from "@foundry/ontology-api";
import createGraph from 'ngraph.graph';
import * as ngraph from 'ngraph.path';

import { aggregateNode } from "@foundry/functions-typescript-runtime-internal-api";

interface Node {
    id: string;
    latitude: number;
    longitude: number;
}

interface Edge {
    source: string;
    target: string;
    distance: number; 
   
}

type NodeId = string | number; 

interface GraphNode {
    id: NodeId; 
}

interface GraphLink {
    data: {
        length: number; 
    };
}
export class MyFunctions {

    @Function()
    public async Optimum_Path(start_node_id: string, end_node_id: string): Promise<string> {

        const graph = createGraph();

        const nodes_data: Nodes[] = Objects.search().nodes().all();
        const edges_data: Edges[] = Objects.search().edges().all();

        nodes_data.forEach((node: Nodes) => {
            graph.addNode(node.nodeId, { lat: node.latitude, lon: node.longitude });
        });

        edges_data.forEach((edge: Edges) => {
            if (typeof edge.endNodeId !== 'undefined') {
            graph.addLink(edge.startNodeId, edge.endNodeId, { length: edge.distance })};
        });

        const pathFinder = ngraph.aStar(graph);
        
        const optimal_path = pathFinder.find(start_node_id, end_node_id);

        return `Optimal path from ${start_node_id} to ${end_node_id}: ${JSON.stringify(optimal_path)}`;
    }
    

}
0

There are 0 best solutions below