Coder Social home page Coder Social logo

riedlerod / basav Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 141 KB

Python application that visualizes Sorting algorithms. Much more focus is laid on giving actual information from the visualisation than making pretty sounds and looking cool.

Python 100.00%
sorting-algorithms sorting sorting-algorithm-visualizations sorting-visualization python3 bucket swaps inserts python

basav's Introduction

Currently on hold, see here.

This project is aimed to provide the user with as much information about Sorting algorithms as possible.I always value amount and quality of information over how pretty it is to look at. This being said, this project is a visualizer of sorting algorithms. You can see when new buckets are created, reads are displayed in green, writes in red. Stats are displayed for reads, swaps, inserts, bucket creation/deletion, and passing cycles. All Algorithms work via a sort-of-API that consists of 8 different statements. One statement per cycle can be returned.

  • READ can read an item in a bucket
  • SWAP swaps two items in the same bucket
  • INSERT inserts an items at a index in the same bucket
  • NEW_BUCK creates a new bucket and CAN transfer one item from another bucket to it
  • BUCKSWAP swaps an item from one bucket to another item from another bucket
  • BUCKINSERT inserts an item from one bucket to an index in another bucket
  • DEL_BUCK deletes a bucket. If the bucket is not empty, nothing happens
  • PULL pulls an item from the end of a bucket into the variable space
  • PUSH pushes an item from the variable space onto a bucket
  • PULSH pulls an item from one bucket and onto another one
  • FIN ends the sorting

The Algorithms only have access to unlimited variable space, the length of the initial array and these statements. There may exist some sort of pseudo-multithreading support in the future, where an algorithm can return multiple statements that will get processed in random order, but count as one cycle. 4 different shufflers and a reverser are implemented with this 'API' and can be accessed through the 'Reverse' and 'Shuffle' buttons. The Randomness can be determined with the 'Randomness' Button. The user can also set the cycles per frame and maximum fps/ups with the buttons 'Speed' and 'FPS/UPS', respectively. There will be a description for each Algorithm in the future.

Even though this is made with Python, I will always make sure even very weak machines can run this at 60fps. All known bugs will be fixed until a release is issued, except for minor and very specific ones. Only Linux is officially supported, but other ones should work too. If they don't, please file an issue. Depending on the severity of the issue, and the accessibility of the OS, it will get fixed more or less quickly.

How to Install

Currently, no installation packages exist, so you have to run it from source. This will be changed before 1.0 and maybe even before 0.1.

Dependencies

Of course, python 3 ist required. The project is aimed at Python 3.8, but it should work for older versions too. Please file an issue if it doesn't. Dependencies installable through pip include:

  • pyglet < 2.0

running

In order to start the program, you have to run main.py with python. This opens the game in borderless window mode. You can close the program by pressing ESC.

Videos

Current problems with this program

  • no graphics settings configurable over CLI, which might cause issues with hosts that don't like VSync, oversampling, etc.
  • I'm ticking the clock in the draw function (bad practice)
  • freezes sometimes, no idea why (possibly related to the previous issue)
  • the window is overloaded, which is… bad practice. I think? It overcomplicates things, anyway.
  • audio playback is one giant hack. It would need to be completely rewritten I think.
  • not compatible with pyglet 2.0 To achive, according to Benjamin, I have to:
    • use GL_TRIANGLES instead of GL_QUADS (maybe there's a gl type for lines now?)
    • tweak 'a few things'

basav's People

Contributors

mfederczuk avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

0xsimulacra

basav's Issues

Add new actions PULL,PUSH,PULSH

For better algorithm control and the possibility of #20, a new action PULSH will be added. This will allow the Algorithm to PULL an item from the end of a bucket, and then PUSH it onto another one. There will also be the PUSH and PULL actions for storing one item while doing other stuff. They will be callable for algorithms through the following action:

yield (PULSH,buck1,buck2)

or

yield (PULL,buck1)
yield (PUSH,buck2)

where buck1 is a bucket with at least one item and buck2 is a bucket with at least one empty spot (which is a given in BASAV if buck1 isn't empty).

Pulshing any item that isn't at the end of a bucket to a position that isn't at the end of another bucket is possible through insertions, which defeats any performance gains PULSH would have. Which means it's not an action to make current algorithms faster, but to distinguish technically faster PULSH operations and usually slow BUCKINSERT operations in the stats. Also, as mentioned above, for insertless mode.

The PULSH operations will count as one PULL and one PUSH in the stats.

Get FPS and UPS up to 60 when handling 2048 items

Newest on top:
commit fd3fe1274d60756ecfcbe3eb525955ecfa8ca26e
Greatly improved audio playback quality and performance
UPS|FPS
59|59 Without Load
(Sound OFF)
48|24 Merge Sort
55|34 Radix LSD 10
28|14 Radix LSD 10 OOP
(Sound ON)
40|23 Merge Sort
48|31 Radix LSD 10
25|14 Radix LSD 10 OOP

commit a4c499acfcb00dfeea62d0b488c4886108ac679c
Added a button to disable audio and a better way to get the average UPS/FPS
UPS|FPS
59|59 Without Load
(Sound OFF)
58|56 Bubble Sort
47|24 Merge Sort
56|35 Radix LSD 10
29|14 Radix LSD 10 OOP
(Sound ON)
32|16 Merge Sort
37|19 Radix LSD 10
22|14 Radix LSD 10 OOP

commit 5339da37ef1e2343c8fa91659cf63acddaf7da4e
I changed the wact/ract rendering system from setting all possible vertices and then assigning the colors when needed to generate an amount of verteces in the correct x positions below the screen and updating the y corrdinates when needed.
UPS|FPS
59|59 Without Load
40|25 Bubble Sort
30|17 Merge Sort
35|16 Radix LSD 10
23|13 Radix LSD 10 OOP

commit 7d74706a3926c7ea480eee2d0f20d21931ced469
added somewhat capable audio playback here
UPS|FPS
59|59 Without Load
38|24 Bubble Sort
30|14 Merge Sort
37|17 Radix LSD 10
18|10 Radix LSD 10 OOP

commit 40b01d61286e6377748172185b765334af01c082
"much much faster rendering system"
UPS|FPS
59|59 Without Load
58|49 Bubble Sort
40|20 Merge Sort
50|25 Radix LSD 10
25|12 Radix LSD 10 OOP

Add stats

Either:

Read: n
Write: n
Pass: n

Or:

Read: n
Swap: n
Insert: n
Bucket: n
Pass: n

I haven't decided yet.

add per-algorithm settings

planned would be a dict where algorithms can choose up to 20 settings by defining a member like so:

opts={
    "base":(int,4,2,None,"Base"),
    "oop":(bool,False,"Out-of-Place","In-Place"),
    "version":(list,2,("This","That","Ananas"),"Version: %s"),
    …
}

, where the option "base" is an integer from 2 to infinity, and a default value of 4, "oop" is a bool with the default value False, where "Out-of-place" is displayed for True and "In-Place" for False, and "version" is a list (a flip-through button in the UI) with the item on index 2 in "vals" being the default. If an option is defined with illegal values, e.g. the default value being out of range in an int, or the possible values in a list being less than 2. If there are more than 20 settings, the additional ones should be hidden and set to their default values. (maybe the maximum amount of settings will increase in the future if demand arises)

The options can be set by the user and on algorithm start, the selected values will be accessible to the algorithm like so:

def gen(self):
    b=self.vals["base"]
    oop=self.vals["oop"]
    v=self.vals["version"]
    …

Then the algorithm can modify itself with the specified values as it pleases.

This feature is aimed to reduce the amount of unique algorithms to select in the algorithm selector drastically and increase the amount of different options a user can choose from. E.g. the Radix LSD algorithm alone used up 6 spaces, but only base 2,4, and 10 can be selected, with an additional OOP option.

Planned is the setup:

  • Bubble Sort (unchanged)
  • Cocktail Shaker (unchanged)
  • Odd-Even Sort (unchanged)
  • InsertionSort (OOP/IP)
  • SelectionSort (OOP/IP,Single/Double)
  • QuickSort (Lomuto/Hoare,Singular/Concurrent)
  • Radix (LSD/MSD,base 2-inf,OOP/IP)
  • Merge Sort (IP/OOP)
  • Bogo Sort (unchanged)
    This would mean a reduction from 25 to 9 unique Algorithms.

Sorting algorithms have to make sure all possible configurations are functional. E.g. if there's a base 4 OOP version, but not a base 7 OOP version, then the algorithm should either limit the possible bases, scrap the OOP versions alltogether, or make the combination work. Note that there can be set boundaries which integer values are possible, but no single value can be excluded. If its a finite list, consider using a list instead.

add unsafe mode

add a button that disables safety checking for a (more or less effective) performance increase. All algorithms should be stable anyway, so safety checking really is just for implementing and testing new features. I still want an extra layer of stability that's enabled by default so the program doesn't crash if I mess up.

Change algorithm API to use yield

because the current one is unnecessarily complicated & yielding stuff would make stuff way easier.
The only problem I still have to solve is passing the read values.

Write a Readme

  • explain capablilities of project
  • "Even though this is made with Python, I will always make sure even very weak machines can run this at 60fps."
  • "All known bugs will be fixed until a release is issued, except for minor and very specific ones."
  • "Only Linux is officially supported, but other ones should work too. If they don't, please file an issue. Depending on the severity of the issue, and the accessibility of the OS, it will get fixed more or less quickly."
  • How to install
  • How to contribute algorithms
  • link coding log playlist
  • link vis-only playlist
  • display screenshots

decouple the main logic class from the main window class

It'd be nice not having to fear that some weird window member could get overritten by a new logic member.

It should be split like so:
The new class MainWin() will go into the CONSTANTS.py file, along with its invokation as win and the constants that get set regarding window size. The new class MainLogic() with most of the members and functions from the current GameWin() will stay in the main.py file.

Add Algorithms

Now the really really bad ones. These actually exist. Mostly for fun, so these are mostly simple.

  • Stooge Sort
  • Bad Sort
  • Silly Sort
  • Slow Sort
  • Gnome Sort
  • Bogo Sort
    • Randomness option
  • Demon Sort
    • Rollout Motion
    • Rollin Motion
    • Randswap Motion
    • Inwards checking
    • Outwards checking
    • Concurrent mode
  • DropSort
    this one actually is not a valid sorting algorithm; but there is one slightly different version that's usable at the bottom of the site.

Now the ones that will like never be implemented for various reasons

  • Gravity/Bead Sort
    this one changes the values of items, which is impossible using my API. I suggest reading the wikipedia article on it, as it's very interesting.
  • Pigeonhole Sort
    this one just creates a bucket for every number in the range and the puts the items in there accordingly and then puts them back in the original bucket – not generally that bad, but very much so in this program, as it's not designed to handle more than 20 buckets. It already struggles with 10. Technically its possible to implement, but I don't want to crash peoples PCs.
    I could possibly implement a In-Place version, but that'd look like magic 😅

Add pseudo- multithreading

Should be somewhat possible to implement something like this with a few new actions:

  • NEW_THREAD(*args,**kwargs)
    Creates a new thread and supplies the specified *args and **kwargs to the thread constructor
  • LOCK_LOCK(n)
    waits until the nth lock is released & locks it
  • RELEASE_LOCK(n)
    releases the nth lock
  • WAIT_LOCK(n)
    waits until the nth lock is released

and Algorithm callbacks:

  • new_thread(*args,**kwargs):
    (algorithms may define it without *args and **kwargs)
    gets called when NEW_THREAD is yielded, and should return a new generator that inherits BaseAlgorithm.
    (this is a classmethod)

Threads should be handled like separate algorithms, where each non-waiting thread gets called equally often than the others. This should be implemented by calling them 'in a circle'. If an algorithm yields to wait, the member thread.lock should be set to the number that is specified. Every time a thread should be called, its member thread.lock has to be read & checked. If the lock is currently locked, the thread should not be called & it should continue with the next one. If a full round has been completed without a thread being called, the algorithm should be stopped and the user should be notified (per print) that a deadlock has occured.

Check windows compatibility before 1.0 release

I just want to see if it works, only major bugs will be fixed, but all bugs I encounter will be recorded.

Also, I don't have windows right now, so I'll ask someone else to try it while recording the screen.

Add a reset Button

when pressed, the button should

  • stop the current algorithm (if any)
    by pressing the start/stop button if it's on stop
  • delete all current buckets
  • create one new bucket

This button will be useful for several purposes:

  • resetting if weird bugs are encountered by the user
  • resetting if the item count changes (see #5)
  • sorting the list without having to wait for an algorithm to sort it
  • filling the hole in the left top corner of the UI

Add no-inserts mode

A mode where inserts are emulated through swaps. The algorithms are still able to use the INSERT and BUCKINSERT actions, but those will then be translated to the according SWAP actions by BASAV.

This won't be a problem as long as no BUCKINSERTs are done, as those cannot be done through other actions. To solve this problem, a new action will be introduced. See #21.

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.