GraphAlgs banner

GraphAlgs

13 devlogs
24h 20m 15s

Some graph traversal algorithms that I’m implementing in C++ to refresh my knowledge of C++ and the algorithms used in my exam board. All three algorithms are linked nicely in a helper function that handles all the printing.

This project uses AI

Copilot for debugging and teaching me C++ again. Claude helped me with the mathematics for force-directed placement for the graph visualisation

Demo Repository

Loading README...

Olly

Shipped this project!

I have now created an epic GUI that visualises the graph. The rendering has some epic physics using force-directed placement. I created my own buttons. The hardest part was definitely wrestling with 3rd party libraries for buttons and CMake. In the end, I gave up and wrote my own class. The same with the entry box that I made.
I learned how to use an enumeration, they’re actually really useful!

Olly
  • Fix dijkstra, because it was broken and I didn’t realise until I was taking screenshots.
  • Fix a little issue with the entryWindow
  • The algorithms now have their path returned to a string that is displayed on the screen, instead of just printing to stdout.
Attachment
0
Olly

Massive update

  • I have made my own buttons!
  • I have made my own entry boxes!
  • The buttons now run a function that handles running the graph editing functions.
  • I learned how to make my own enumeration, I use it to handle which text to display in the entryWindow
  • Changed the GitHub workflow to zip the executable with the font file that I use to allow for a single download.
1

Comments

Olly
Olly 3 days ago

Please don’t grill my light theme IDE. I couldn’t see it properly, it’s nice and bright today

Olly

I have now implemented button clicking logic. In this video I only have functionality hooked up to the exit button, but soon I’ll have the traversal algorithms re-implemented and connected to the buttons.

2

Comments

Olly
Olly 4 days ago

Ignore that it closed on the DFS button, I have now fixed the bug.

Olly
Olly 3 days ago

Ummm the browser screen recorder I used stretched this sm wow

Olly

I designed the layout of how I want the buttons to look, and I implemented them. I have a function that creates a vector of buttons by reading their coordinates and labels from 2 other vectors. Then I have another function that takes the list of buttons and renders them to the screen automatically.

Attachment
0
Olly

So, I have spent nearly 2 hours wrestling with CMake trying to get SFML to compile with a library that would give me nice buttons to use straight out of the box. However, I failed 3 time with 3 different libraries, so I think that I will just make them myself. It definitely wasn’t worth spending all of this wasted time. But I have made some general improvements too, did a bunch of commenting, made an area for the buttons to eventually be in. (for context, these buttons will run the algorithms eventually.)

Attachment
1

Comments

Olly
Olly 7 days ago

I’m demonstrating in this photo that the nodes cannot travel into the bottom 200px

Olly

You can now drag the nodes around to rearrange their positions. I also reduce the repulsive force between the nodes while dragging them around so that its easier to make cool formations!!!

0
Oliver

Tagged your project as well cooked!

🔥 Oliver marked your project as well cooked! As a prize for your nicely cooked project, look out for a bonus prize in the mail :)

Olly

I have now added the weights of the edges (connections) as text labels. I calculate the midpoint along the vertex (drawn line) by adding the vector (points) of the edge together and dividing by 2 - I effectively just calculate the average of the two coordinates, and place the text there. I have now also added circles to where the nodes are. I just place the circle on the node coordinate.

Attachment
0
Olly

So, I now have the graph’s edges showing in a GUI. I asked Claude to tell me how I could implement having the graph in a fluid and natural way; it told me to use force-directed placement which makes the nodes repel each other like magnets, and the edges act like springs pulling it back together. The physics of it are really nice!

Attachment
0
Olly

I have installed a new library called SFML - Simple and Fast Media Library. I chose this library because a Reddit thread suggested that it is quite similar to PyGame which from a quick glance at the documentation, it does. And after 15 mins of trying to get a Noto Sans font file load, I now have a Hello World window!

Attachment
0
Olly

Shipped this project!

Hours: 5.67
Cookies: 🍪 125
Multiplier: 21.97 cookies/hr

I’m happy with the way this turned out, it runs fast (it’s C++ duh!). The ascii art looks cool on startup and in my README, shoutout to the website that I got it from (credit in my README). The traversals and path finding work, and my proficiency in modern C++ is way better now. I think in my next version, I might look to add a GUI for the user to visualise the graph, and interactively add and remove parts of the graph!

Olly

I have now added a README, some sweet ascii art to the program and the README, and the breadth first search algorithm!

Attachment
Attachment
0
Olly

I have now implemented a depth first search algorithm into my application! I had an issue where the program would segfault when I ran it. Turns out I missed that I was creating a vector of integers and then treating them like a vector of booleans :p

While I was making that algorithm, I made this nice simple CLI that users can now use to interact with the graph simulation. I have made a nice printMenu() function that means that I don’t have a big print statement clogging up my main function. Also there is a BFS (breadth-first search) option, but that will be implemented next!

Attachment
0
Olly

My Dijkstra’s algorithm now works nicely! The next item on the agenda will be a nice CLI to allow users to easily add to/remove from and modify the graph and select which algorithms they’d like to run

Attachment
0
Olly

I now have my own Stack, Queue and Priority Queue classes. I use inheritance on the priority queue class, as it is almost the exact same as the normal queue class, except for pushing, as it makes sure that all of the elements are ordered correctly. There is no output for these yet, however my graph class works, and I have made a method that prints the graph to show you guys!

Attachment
0