Code Monkey home page Code Monkey logo

ex3's Introduction

Directed Weighted Graph - Python

Authors: Tzach Itshak Ofir and Gal Braymok

Description

In this project we applied graphs in the Python language.

The project includes the implementation of two interfaces:

GraphInteface:

Implemented by DiGraph class. This interface is responsible for the structure of the graph and many operations.

GraphAlgoInterface:

Implemented by GraphAlgo class. In this class there are various algorithms that can be applied on graphs

Structure:

Node - represents the set of operations applicable on a node (vertex) in a (directional) weighted graph.

DiGraph:

  • v_size - Returns the number of vertices in this graph.

  • e_size - Returns the number of edges in this graph.

  • get_all_v - Return a dictionary of all the nodes in the Graph, each node is represented using a pair (node_id, node_data).

  • all_in_edges_of_node - Return a dictionary of all the nodes connected to (into) node_id , each node is represented using a pair (other_node_id, weight).

  • all_out_edges_of_node - Return a dictionary of all the nodes connected from id1, each node is represented using a pair (other_node_id, weight)

  • get_mc - Returns the current version of this graph, on every change in the graph state - the MC should be increased.

  • add_edge - Adds an edge to the graph (if the edge already exists or one of the nodes dose not exists the functions will do nothing).

  • add_node - Adds a node to the graph (if the node id already exists the node will not be added).

  • remove_node - Removes a node from the graph (if the node id does not exists the function will do nothing).

  • remove_edge - Removes an edge from the graph (If such an edge does not exists the function will do nothing).

  • find_edge - Finds the index of the first occurence of an edge.

  • is_node_exist - Determines if a node exists in the graph.

  • is_in_edge - Determines if a node is one of an edge's vertices.

  • get_all_edges - Gets all the graph's edges.

  • get_nodes - Gets all the graph's nodes.

  • get_transpose - Gets the transpose of the graph. i.e, the original graph who's all its edges are inverted.

GraphAlgo:

  • get_graph - Return the directed graph on which the algorithm works on.

  • load_from_json - Loads a graph from a json file.

  • save_to_json - Saves a graph from a json file.

  • shortest_path - Returns the shortest path from node id1 to node id2 using Dijkstra's Algorithm.

  • connected_component - Finds the Strongly Connected Component(SCC) that node id1 is a part of.

  • connected_components - Finds all the Strongly Connected Component(SCC) in the graph.

  • plot_graph - Plots the graph. If the nodes have a position, the nodes will be placed there. Otherwise, they will be placed in a random but elegant manner.

Test Times

Python NetworkX Java

SCC

0.00099 0.0 0.01094

Dijkstra

0.0 0.0 0.01722

Plot

0.25981 0.15708 -----------

ex3's People

Contributors

tzacho avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.