Skip to content

API Package

AmitSheer edited this page Dec 19, 2020 · 5 revisions

API

To work with the project you need to:

  1. create an instance of the graph itself: DWGraph_DS graph = new DWGraph_DS()
  2. create an new node instance: NodeData node = new NodeData({KEY})
  3. add nodes to the graph by giving the function a specific key: graph.addNode(key), add as many as you need.
  4. add edges, connections: graph.addEdge(node2key,node1key)
  5. create an instance of the graph algorithm: DWGraph_Algo algo = new DWGraph_Algo()
  6. initialize the algo with the graph you created: algo.init(graph)
  7. then use the methods provided to run and use the graph:\
    • algo.isConnected() to check if the graph you created all nodes connect
    • algo.shortestPath(src,dest) to find all the nodes between the src node to the dest node
    • algo.shortestPathDist(src,dest) to find how many nodes are between the src node to the dest node

Structure

Package api

Classes

  • DWGraph_Algo
    Responsible for running the algorithm on specific graph
  • DWGraph_DS
    Controls the graph. Adding,Removing nodes and creating connections between nodes
  • EdgeData
    Saves the data of an edge in the graph
  • NodeData
    Save the location and key of node in graph
  • GeoLocation
    Save the location in x,y,z graph
  • GraphParser
    Takes a graph and converts it to or from JSON form
  • Trajan
    Algorithm to find SCC, strongly connected connections, in a graph

Interfaces

  • dw_graph_algorithms
  • directed_weighted_graph
  • edge_data
  • node_data
  • game_service
  • geo_location

General Description of Methods, Divided by Class

  • WGraph_Algo

    • init(graph g)
      initializes a new graph object into the class.
    • copy()
      creates a deep copy of the initialized graph and returns it
    • isConnected()
      checks if there is a way to get from every node to any other node in graph, using Tarjan Class
    • shortestPath(int src, int dest)
      returns the shortest path from one node to the other, if it exists, in the form of a list containing all the nodes in the path
    • shortestPathDist(int src, int dest)
      finds the shortest path, as in the smallest sum of the distance between nodes according to the edges
    • save(String path)
      saves the init graph in the algo into a file, the output file is in JSON format
    • load(String path)
      loads graph from a file, according designated path only support for JSON formatted files
    • getGraph()
      returns the graph currently loaded into instance
  • DWGraph_DS

    • getNode(int key)
      gets a node from the graph, given that the given key is of an existing node in the graph
    • getNode(int src, int dest)
      gets the edge, if exist between two nodes, src and dest
    • addNode(node_data n)
      adds a new node to the graph
    • connect(int node1,int node2)
      create a connection between two nodes, given that the connection doesn't already exist
    • edgeSize()
      gets how many edges are in the graph
    • getMC()
      counts how many changes were made to the graph
    • getV()
      gets all the nodes in the graph
    • getE(int node_id)
      returns all the connected nodes to the node with given id
    • hasEdge(int node1, int node2)
      checks if there is a connection between two nodes
    • nodeSize()
      returns the number of nodes in graph
    • removeEdge(int node1, int node2)
      deletes the connection between nodes
    • removeNode(int key)
      deletes the node with given key, and all of its connections in other node
    • toString()
      return the graph in string form
  • EdgeData

    • getSrc()
      returns the src node key of the edge
    • _getDest()
      returns the dest node key of the edge
    • getWeight()
      returns the weight of the edge
    • getInfo()
      returns the info held on graph
    • setInfo(String s)
      sets the info held in graph
    • getTag()
      returns current graph tag
    • setTag(int t)
      sets current graph tag
    • toString()
      return the edge in string form
  • NodeData

    • getKey()
      returns the key
    • _getLocation()
      returns node currents location
    • getWeight()
      returns the weight of the edge
    • setLocation(geo_location p)
      sets node current location
    • setWeight(double w)
      sets the node current weight
    • getInfo()
      returns the info held on graph
    • setInfo(String s)
      sets the info held in graph
    • getTag()
      returns current graph tag
    • setTag(int t)
      sets current graph tag
    • toString()
      return the node in string form
  • GeoLocation

    • x()
      returns the x coordinates
    • y()
      returns the y coordinates
    • z()
      returns the z coordinates
    • distance(geo_location g)
      calculates the distance between two points
    • toString()
      return the node in string form
  • GraphParser

    • Json2Graph(JsonReader reader)
      converts text in JSON format to Graph and returns it
    • Json2Graph(String json)
      converts text in JSON format to Graph and returns it
    • Graph2Json(directed_weighted_graph graph)
      converts graph to JSON format and returns it
  • Tarjan

    • getSccNodes()
      returns a list of list, that contains all of the scc in a certain graph
    • init(directed_weighted_graph g)
      returns if the true if the entire graph is scc
Clone this wiki locally