Skip to content

Commit

Permalink
graph_Mat completed, as needs, further modifications will likely be i…
Browse files Browse the repository at this point in the history
…n inherited child classes

Major Change - User inputs in form of rows*columns, but graph internally uses it as y*x (logically), and also the boxes are intitialized with the usual xy coordinate system only
  • Loading branch information
adi-g15 committed Oct 20, 2020
1 parent 7f8a541 commit 882d6fc
Show file tree
Hide file tree
Showing 19 changed files with 507 additions and 206 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(CMAKE_CXX_STANDARD 17)

file(GLOB SOURCES "src/*.cpp")
add_executable(simulator main.cpp ${SOURCES})
add_executable(test graphMat/test.cxx)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
Expand All @@ -13,3 +14,4 @@ target_link_libraries(simulator PRIVATE Threads::Threads)

target_include_directories(simulator PRIVATE includes)
target_include_directories(simulator PRIVATE .)
target_include_directories(test PRIVATE .)
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2020 Aditya Gupta

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2020 Aditya Gupta
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions graphMat/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
38 changes: 19 additions & 19 deletions graphMat/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "cl.exe - Build and debug active file",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}\\test.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "C/C++: cl.exe build active file"
}
]
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "cl.exe - Build and debug active file",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}\\test.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "C/C++: cl.exe build active file"
}
]
}
11 changes: 10 additions & 1 deletion graphMat/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
"new": "cpp",
"numeric": "cpp",
"system_error": "cpp",
"ostream": "cpp"
"ostream": "cpp",
"list": "cpp",
"vector": "cpp",
"xlocnum": "cpp",
"xstring": "cpp",
"iosfwd": "cpp"
},
"C_Cpp.default.includePath": [
"${default}",
"${workspaceFolder}/.."
],
"workbench.colorCustomizations": {
"activityBar.background": "#551B00",
"titleBar.activeBackground": "#772600",
Expand Down
2 changes: 2 additions & 0 deletions graphMat/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"args": [
"/Zi",
"/EHsc",
"/std:c++latest",
"/I..",
"/Fe:",
"${workspaceFolder}\\test.exe",
"${workspaceFolder}\\test.cxx"
Expand Down
42 changes: 21 additions & 21 deletions graphMat/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Matrix as a Graph
----

The title mostly says it, i will complete it more as needed by the main project
This is a subproject for the worldline project (a catchy name, but an interesting small simulator for me)

## Purpose -

I needed a matrix like data structure, that can have
1. expansion and deletetion capabilities like that of a list (ie. no need to copy again and again for expansion as in std::vector (and i am not talking about the capacity vs size here, that would not work for my purpose))

2. access as a vector 2x2 matrix, or atleast fast access

Then, i had read somewhere, _A matrix is inherently a graph, each node connected to 4 adjacent nodes_, though it maybe very simple, but quite intutive it seems.

So, now the point of it, So i created a matrix data structure, based on a graph, that completes the requirements for `point 1 above`, though it doesn't have constant time lookups like std::vector, but for my case, i chose to create it like this.

## Probable Uses -

It will likely be used as the `world plot`, since think, this world will be expanding (continuosly or on need basis, so I didn't wanted `vector<vector>`, that had been quite an overhead for expansion like 40\*40 to 100\*100)
Also, in case of `vector<vector>`, you will likely have it grow in ONLY TWO DIRECTIONS, and I WANTED IT TO GROW EQUALLY IN ALL FOUR DIRECTIONS, now this would, almost always mean, that even for a simple expansion, the `vector<vector>` has to completely allocate to a whole new place
# Matrix as a Graph
----

The title mostly says it, i will complete it more as needed by the main project
This is a subproject for the worldline project (a catchy name, but an interesting small simulator for me)

## Purpose -

I needed a matrix like data structure, that can have
1. expansion and deletetion capabilities like that of a list (ie. no need to copy again and again for expansion as in std::vector (and i am not talking about the capacity vs size here, that would not work for my purpose))

2. access as a vector 2x2 matrix, or atleast fast access

Then, i had read somewhere, _A matrix is inherently a graph, each node connected to 4 adjacent nodes_, though it maybe very simple, but quite intutive it seems.

So, now the point of it, So i created a matrix data structure, based on a graph, that completes the requirements for `point 1 above`, though it doesn't have constant time lookups like std::vector, but for my case, i chose to create it like this.

## Probable Uses -

It will likely be used as the `world plot`, since think, this world will be expanding (continuosly or on need basis, so I didn't wanted `vector<vector>`, that had been quite an overhead for expansion like 40\*40 to 100\*100)
Also, in case of `vector<vector>`, you will likely have it grow in ONLY TWO DIRECTIONS, and I WANTED IT TO GROW EQUALLY IN ALL FOUR DIRECTIONS, now this would, almost always mean, that even for a simple expansion, the `vector<vector>` has to completely allocate to a whole new place
24 changes: 12 additions & 12 deletions graphMat/direction.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once

#include <vector>

enum Direction: uint8_t{ // intentionally not enum class now
UP,
DOWN,
RIGHT,
LEFT
};

typedef std::vector<Direction> directionalPath; // can use std::queue<Dimension> too, that would allow popping too
#pragma once

#include <vector>

enum Direction: uint8_t{ // intentionally not enum class now
UP,
DOWN,
RIGHT,
LEFT
};

typedef std::vector<Direction> directionalPath; // can use std::queue<Dimension> too, that would allow popping too
2 changes: 2 additions & 0 deletions graphMat/graph__square_mat.hpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#pragma once

#include "graph__square_mat_decl.hpp"
#include "graph_mat.hpp"
9 changes: 7 additions & 2 deletions graphMat/graph__square_mat_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ class Square_Matrix: public Graph_Matrix<node_type, dimen_t>{
dimen_t getOrder() const{ //order of the matrix
return this->_total_y_abs;
}
void resize(dimen_t new_order) override{
this->resize(new_order, new_order);
void resize(dimen_t new_order){
Graph_Matrix::resize(new_order, new_order);
}

Square_Matrix(): Square_Matrix(1){}
Square_Matrix(dimen_t order): Graph_Matrix(order, order){

}

};
2 changes: 1 addition & 1 deletion graphMat/graph_box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <utility>

#include "direction.hpp"
#include "includes/declarations.hpp"
#include "../includes/declarations.hpp"

// equivalent to {x,y} in a matrix, this typedef defines the position of a box/point, in an intuitive way (to me atleast :D), and feels more closer to the implementation than to give indices, since here we have directions mostly
typedef std::vector<std::pair< Direction, uint16_t >> graph_position;
Expand Down
Loading

0 comments on commit 882d6fc

Please sign in to comment.