Giter VIP home page Giter VIP logo

datastructures.algorithms's Introduction

DataStructures and algorithms

A collection of basic algorithms and data structures (algodat)

DataStructures (Experimental)

  • AvlTree
  • BstTree
  • The graphs datastructure with it vertices and edges is implemented as "linked list".
    • The idea is that it is not neccessary to load the entire graph to execute an algorithm.
    • Each vertex can save a generic Value.
    • The graph is fully (de)serializeable.
  • LinkedList (will be reimplemented see)
  • Documentation

nugets

nuget.org
Abstract.DataStructures
Abstract.DataStructures.Algorithms
Abstract.DataStructures.Algorithms.Graph
Abstract.DataStructures.UI
Azure DevOps
Pipeline
Doc Release Pipeline

DataStructures.UI

Wpf control to visualize, create and edit a graph. See here.

Live Samples

A* search algorithm

alt text

BFS - breadth first search

alt text

Kruskal

alt text

Introduction

When taking a beginners class at the technical university of vienna, I started to implement and adopt some lessions from the algorithms and data structures course. I thought it would be fun to put my recently gained knowledge into practice.

Of course some frameworks regarding this topic already exist. For example linked list and various tree classes. When applying these I ran into several issues like limited extensibility, missing features and all of them came from diffrent sources. Therefore I wasn't able to combine the tree classes, especially the data structure classes.

So I started to create my own algorithms and data structures "framework".

Goal

With the old version of the framework I mainly focused on visually representing the graph data structure with wpf. (see UI\DataStructures.Demo)

Some algo related links

Graph control

When creating the graph with the ui (graph control) the proper model will be created in the background. alt tag

Another approach would be to overgive a graph data structure to the graph visualization control which created the proper ui graph. One of the benefits of the old implemention is that the kruskal algorithm creats a copy of the graph, therefore the vertices dont't stay in the same position.

alt tag

When modifying a graph during runtime, the graph visualization control updates the ui.

alt tag

The aforementioned features (graph visualization control) will be implemented into the new framework as well.

datastructures.algorithms's People

Contributors

herbertwraneschitz avatar mfe- avatar stephentoub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

datastructures.algorithms's Issues

IVertex parameter is null in OnBreadthFirstSearchCommand(IVertex vertex) method and Kruskal doesn't work

Repro steps:

  1. Clone the code from main branch and open with VS2022.

  2. Press F5 to launch the DataStructures.UI.Demo project.

  3. Select node 3 and right-click to choose BreadthFirstSearch option.
    image

  4. It will throw Object reference not set to an instance of an object at DataStructures.UI.Demo\Window1ViewModel.cs:line 116

Findings:
After checking the line 116, we found the vertex object is null.

Another issue:

  1. Press F5 to launch the DataStructures.UI.Demo project.
  2. Select node 3 and right-click to choose Kruskal option.

Excepted Result:
The screen should show this result.
image

Actual Result:
The screen doesn't do any changes. It keeps in this:
image

Too many collisions with <250000 edges when comparing with Edge.GetHashCode for transposed

When generating more than 250000 edges with Generate_Grid_Graph there are many collisions using Edge.GetHashCode

return Math.Abs(U.GetHashCode()) + (V != null ? Math.Abs(V.GetHashCode()) : 0);

U.GetHashCode() =       return this._Guid.Equals((obj as Vertex)?._Guid);

Currently workaround.

return ($"{U}{V}" == $"{edge.U}{edge.V}" || $"{U}{V}" == $"{edge.V}{edge.U}");

Maybe the Guid of the Vertex should be exposed in IVertex so it can be used for comparison in the implementation of Edge.
The Edge itself could generate a new Guid of Vertex.U and Vertex.V.

https://gist.github.com/mfe-/c23279f73f1b2373eeeb4a8baa5d7906

Directed graph with custom Vertex widthxheight shifts arrow wrong

When setting a custom width and height >40 on the VertexControl on a directed graph the arrow is underneath the control. Therefore it looks like that the arrow isn't displayed. The ShiftConverter is currently using hardcoded +-7.

To fix this:

  • Pass additonal parameter with width and height of control to ShiftConverter
  • Calculate a reasonable value which can be used to shift the arrow

Remove INPC from IVertex(Vertex)

image

Remove INPC from IVertex(Vertex).
Because the UI GraphControl requires INPC we can create an own Vertex class which implements INPC

Detect opposite edge in an easy way

vertices in a undirected graph will be connected by two edges.
E.g (where "->" and "<-" is representing an edge):
v1 -> v2
v1 <- v1

This fact requires to implement additonal checks in DFS and other graph algorithm.
E.g.:

    private static IEnumerable<IEdge> DepthFirstSearch(IVertex current, List<IEdge> edges, IVertex goal)
    {
        //mark edges
        foreach (IEdge e in current.Edges)
        {
            //check if we found the goal
            if (e.V.Equals(goal))
            {
                //some special behaviour duo circlues which we have to consider resulting of the our model (undirected: 1->3, 3->1)
                if (!edges.First().U.Edges.SelectMany(a => a.V.Edges).ToList().Exists(y => y.Equals(e))//schauen ob er zurückgehen will
                    || (edges.First().U.Edges.SelectMany(a => a.V.Edges).ToList().Exists(y => y.Equals(e) && //(kreis existiert mit IEdge ausgehend vom start), (schauen ob dazwischen noch andere IEdges sind)
                    edges.Find(delegate (IEdge ed) { return ed.V == e.U && ed.U != e.V; }) != null)))
                {
                    edges.Add(e);
                    return edges;
                }
           [...]

Therefore we should provide a method which considers the opposite edge when checking if the edge was already visitied.

lazy iterable vertex/ edge list

Keeping the whole vertex /edge list in memory allocates too much space in some scenarios.
When iterating over vertices /edge list, it should be possible to outsource them (for example into a file by using the existing deserializing function or simply save the guid of the vertex or edge).

  • Implement outsourcing part of the vertice/edge list by saving them into a file.

Make use of Guid for Vertex comparision

  • Define or extend interface of IVertex which makes it possible to use the internal Guid for comparision of vertex1 and vertex2; Possible candidate IComparable<Guid> or IEquatable<IntPtr>
  • Adjust algo.

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.