Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding back files to be reviewed #1

Open
wants to merge 1 commit into
base: deleted_code
Choose a base branch
from

Conversation

tessavdheiden
Copy link
Owner

The code in the folder "visualizer" should not be reviewed. The "implementation/include" is where I created an interface "planner.h" and the implementation of the algorithm "implementation.h" and "implementation.cpp".

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ A review job has been created and sent to the PullRequest network.


Check the status or cancel PullRequest code review here - or - cancel by adding [!pr] to the title of the pull request.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicks mostly here.

I added CMake changes that may be beneficial to you.

Definitely want to add -Wall -Wextra to the compile options. Warnings are your friend.


Was this helpful? Yes | No


Moving downwards decreases the path time and upwards increases it. We can model this by changing the time with some X %. However, travelling upwards and downwards, may not be equally as coslty as on flat areas, so upwards should increase the time with some extra percentage.

Below we see the path planned with a small car (top picture) and a heavy car (bottum picture). The more "weight" the car has, the bigger the difference between going up vs going down for the path time. So a heavy car tries to avoid the hills more than a smaller car.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bottom picture


void print_coordinate(std::pair<int, int> a);

template<typename Location, typename Graph>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make more sense to flip the order of these arguments. template<typename Graph, typename Location>. I prefer following the order of the function arguments.


<img src="results/dijkstra.png" width="256" height="256" title="Dijkstra">

A* is a modification of Dijkstra’s Algorithm that is optimized for a single destination. Dijkstra’s Algorithm can find paths to all locations; A* finds paths to one location, or the closest of several locations. It prioritizes paths that seem to be leading closer to a goal. The picture below shows the path planned by A*.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The asterisk in A* may need to be escaped with a backslash to prevent markdown from taking it as a 'begin bold text' signal

enum {
IMAGE_DIM = 2048, // Width and height of the elevation and overrides image

ROVER_X = 159,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to create a struct Size { int width; int height; } and work with these.

You might consider also making a Point struct that you can then use with donut and scatter.

These structs are actually very, very common and it makes sense to introduce types for them.

const kBachelorSize = Size(1303, 85);

<img src="results/dijkstra_heavy.png" width="256" height="256" title="Dijkstra">

### Improvements
- The planner could be implemented with a Builder pattern. An algorithm (Dijktra or A*) receives a type of graph (grid or weighted grid) and a model (small or big).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dijkstra


### Improvements
- The planner could be implemented with a Builder pattern. An algorithm (Dijktra or A*) receives a type of graph (grid or weighted grid) and a model (small or big).
- The rule of five sais that every class requires a user-defined destructor, a user-defined copy constructor, or a user-defined copy assignment operator and move constructor. I did not implement the move and copy constructors, because for this small project, only 1 planner will be used.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rule of five says

@@ -0,0 +1,70 @@
#ifndef __IMPLEMENTATION_H__
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it a conscious choice to avoid "#pragma once"?

bm.bitmapinfoheader.bitsperpixel = bitsPerPixel;
bm.bitmapinfoheader.compression = 0;
bm.bitmapinfoheader.imagesize = pixelBytes;
bm.bitmapinfoheader.ypixelpermeter = 0x130B; //2835 , 72 DPI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest lifting 0x130B to a constant

};

// Some constants
enum {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way to sort these enums by values lowest to highest?

}


void setColor(std::vector<uint8_t>& vec, size_t i, uint8_t r, uint8_t g, uint8_t b)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap r,g,b in a type, maybe call it RGB.

{
uint8_t pixelValue = pixelFilter(x, height, *pixels);
out.write((const char*)&pixelValue, 1);
++ pixels;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix increment is generally a bad idea.

size_t startIndex,
size_t endIndex,
uint8_t startRed,
uint8_t startGreen,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using RGB, instead of this function taking 8 args, it can take 4.

Bitmap bm;

// Write header
memset(&bm, 0, sizeof(bm));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a BitMap constructor that handles all the things below.

* x (from the left), and y (from the top) position of the elevationData. See enum
* ImagePixelValues above for interesting values to return.
*/
void writeBMP(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the Size struct above instead of width height

size_t width,
size_t height)
{
size_t count = width * height;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you somehow use std::max?

add_subdirectory(implementation)

add_executable(Bachelor main.cpp)
target_link_libraries(Bachelor visualizer)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should do target_link_libraries(Bachelor PUBLIC visualizer)

std::unordered_map<Location, Location> &came_from,
std::unordered_map<Location, double> &cost_so_far);

void findShortestPath(void (*print_fun)(std::pair<int, int>), void (*search_fun)(implementation::Grid *,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of void (*searchfun).... I think you can just use one of the above templates.

I'm not too sure about the syntax but something like

void (*search<Grid, implementation::GridLocation>

add_subdirectory(visualizer)
add_subdirectory(implementation)

add_executable(Bachelor main.cpp)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd reach for storing the main.cpp in a SOURCE_FILES var

std::ofstream out(filepath);
std::stringstream ss;

for (auto location : result)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use { }


## Introduction

This project contains two algorithms for planning the quickest path for a rover to pick up a bachelor and carry him to his wedding. Shortest path problems are typically solved bij [Dijkstra](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) and it's improved version [A*](https://en.wikipedia.org/wiki/A*_search_algorithm). Follow the instructions below to run find your quickest path.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typically solved by

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to inactivity, PullRequest has cancelled this review job. You can reactivate the code review job from the PullRequest dashboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant