-
Notifications
You must be signed in to change notification settings - Fork 23
homeworks by Krivoruchko Dmitry #15
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
Open
UmbrellaLeaf5
wants to merge
110
commits into
AlgorithmsDafeMipt2024:main
Choose a base branch
from
UmbrellaLeaf5:homeworks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 89 commits
Commits
Show all changes
110 commits
Select commit
Hold shift + click to select a range
9cfcf59
delete extra extension from docker
UmbrellaLeaf5 39f8a8f
update format CMakeLists
UmbrellaLeaf5 aa962ae
update lib folder
UmbrellaLeaf5 6e59658
update lib->utils name in CMakeLists
UmbrellaLeaf5 b5d47d1
Merge remote-tracking branch 'upstream/main'
UmbrellaLeaf5 ae45494
README beautify
UmbrellaLeaf5 4f484ef
lib: start writing class Graph (only constructors)
UmbrellaLeaf5 6803381
fix CMakeLists in sandbox and lib
UmbrellaLeaf5 ce19ac9
add new methods to Graph
UmbrellaLeaf5 1092d57
add Contains(vector, T) in util
UmbrellaLeaf5 ce3b73a
add primary Graph testing in sandbox
UmbrellaLeaf5 5c03e04
split the realization into files
UmbrellaLeaf5 9fbd61b
update tests and weight type in Graph
UmbrellaLeaf5 7265f36
update tests and fix some in Graph
UmbrellaLeaf5 f0c771d
simplify methods and add constructors on strs in Graph
UmbrellaLeaf5 7fc4b2b
add tuple methods to Graph
UmbrellaLeaf5 a9a1506
add methods with AdjMatrix and AdjList
UmbrellaLeaf5 1e0251a
add GetWeightOfEdge and ContainsEdge methods
UmbrellaLeaf5 50964ee
add Add and Remove methods to Graph
UmbrellaLeaf5 483ddc6
fix problem with adding and removing from undirected Graph
UmbrellaLeaf5 6a6834a
add comments and cmake flags
UmbrellaLeaf5 2cba59a
add templates to Graph
UmbrellaLeaf5 8ae16e7
continue templating Graph (separate size_t and std::string)
UmbrellaLeaf5 4b956db
finish primary templating Graph
UmbrellaLeaf5 c97e251
file system reconfigure
UmbrellaLeaf5 99adbdf
update Graph with comments and new types
UmbrellaLeaf5 ff87235
add concepts for Graph
UmbrellaLeaf5 f6256d9
update Graph and utils
UmbrellaLeaf5 8b90d16
update tests file name and main.cpp in sandbox
UmbrellaLeaf5 6032727
add graph_additional_task
UmbrellaLeaf5 bcd54e5
docker file back
UmbrellaLeaf5 5f755f3
start topology_sort
UmbrellaLeaf5 578fb60
update edge.Name()
UmbrellaLeaf5 bdd9a22
complete topological_sort for int types
UmbrellaLeaf5 2030d75
update templates
UmbrellaLeaf5 efb4384
update class Graph with unordered_map as AdjList
UmbrellaLeaf5 1e58f0e
complete topological_sort for std::string
UmbrellaLeaf5 225deae
delete extra TopologicalSort realization
UmbrellaLeaf5 bb564e6
update names and comments
UmbrellaLeaf5 00cd1d3
update tests for topological_sort
UmbrellaLeaf5 5230994
update edge.Name()
UmbrellaLeaf5 cf04922
update class Graph with unordered_map as AdjList
UmbrellaLeaf5 4c939f8
update names and comments
UmbrellaLeaf5 ff9397f
Merge remote-tracking branch 'upstream/main' into graph_additional_task
UmbrellaLeaf5 7cd0f7e
Merge remote-tracking branch 'upstream/main' into homework_1
UmbrellaLeaf5 f2c6305
CMakeLists hotfix
UmbrellaLeaf5 1ccac8e
CMakeLists hotfix
UmbrellaLeaf5 b85a801
Merge remote-tracking branch 'upstream/main' into graph_additional_task
UmbrellaLeaf5 f7d1a4f
Merge remote-tracking branch 'upstream/main' into homework_1
UmbrellaLeaf5 ffa9925
and const
UmbrellaLeaf5 56edbd2
add exception throwing for undirected graph
UmbrellaLeaf5 df614a2
update README.md
UmbrellaLeaf5 9b06396
update include
UmbrellaLeaf5 f737732
fix typo
UmbrellaLeaf5 a1026e2
fix typo and add ContainsVert method in graph class
UmbrellaLeaf5 6672c40
add ContainsVert method
UmbrellaLeaf5 12dc12a
beautify concepts (move from constructor)
UmbrellaLeaf5 43a33a9
beautify concepts (move from constructor) in graph class
UmbrellaLeaf5 9f3a3b2
Merge remote-tracking branch 'upstream/main' into homework_1
UmbrellaLeaf5 cfc14c9
Merge remote-tracking branch 'upstream/main' into graph_additional_task
UmbrellaLeaf5 f1d3404
code beautify
UmbrellaLeaf5 f9f0183
code beautify
UmbrellaLeaf5 2145bbb
change static funcs to anonymous namespace
UmbrellaLeaf5 f4321ff
update CMakeLists.txt
UmbrellaLeaf5 a197259
move graph class to lib
UmbrellaLeaf5 e09435b
primary complete FindBridge
UmbrellaLeaf5 fa95ee7
add comments
UmbrellaLeaf5 283bbf8
code beautify
UmbrellaLeaf5 e4b28eb
Merge branch 'homework_2' into homeworks
UmbrellaLeaf5 009f5f4
start testing FindBridges
UmbrellaLeaf5 91e1d44
fix FindBridges and update tests
UmbrellaLeaf5 a4bc2c6
Merge branch 'homework_2' into homeworks
UmbrellaLeaf5 c293910
add more tests
UmbrellaLeaf5 3fc41d0
primary complete FindCutVertices
UmbrellaLeaf5 61d327e
add tests for FindCutVertices
UmbrellaLeaf5 994e536
Merge branch 'homework_2' into homeworks
UmbrellaLeaf5 33fa735
fix cycles in graph
UmbrellaLeaf5 50e5591
Merge branch 'homework_1' into homeworks
UmbrellaLeaf5 f26af34
fix typos in README.md in task_06, task_05
UmbrellaLeaf5 c05cdd7
update comments in graph class and add move constructor
UmbrellaLeaf5 4e031da
primary complete Dijkstra algo
UmbrellaLeaf5 44ac5a4
Merge branch 'homeworks' into homework_4
UmbrellaLeaf5 cfde115
add exception throwing with negative weighted edges
UmbrellaLeaf5 5c97632
update graph class: allow negative weight and add more template types
UmbrellaLeaf5 7a67c73
Merge branch 'homeworks' into homework_4
UmbrellaLeaf5 6260ff0
fix bugs in methods in class graph connected with undirected graph
UmbrellaLeaf5 80d7900
update Dijkstra algo and add tests
UmbrellaLeaf5 b7c982f
update README.md
UmbrellaLeaf5 7fa2b09
Merge branch 'homework_4' into homeworks
UmbrellaLeaf5 56ac61e
code beautify
UmbrellaLeaf5 5d6ed7a
rename: GetWeightOfEdge -> GetEdgeWeight, ParseEdgeString -> ParseEdg…
UmbrellaLeaf5 1c4031a
add graph class methods: GetEdgeIter, SetEdgeWeight
UmbrellaLeaf5 f6e9b4e
move all methods in graph class to graph.hpp
UmbrellaLeaf5 050874c
move graph.hpp and utils.hpp to .. folder
UmbrellaLeaf5 4ad0080
update graph class (code simplify and beautify)
UmbrellaLeaf5 4e79689
complete Bellman-Ford algo with tests (for task_04)
UmbrellaLeaf5 d2f5ae8
complete task_04 with tests
UmbrellaLeaf5 0e20081
add extra inline and update doxygen comments
UmbrellaLeaf5 31562c9
update README.md in task_03 and task_02
UmbrellaLeaf5 1c35ba2
complete task_06 with tests
UmbrellaLeaf5 677089a
update README.md in task_06 and code beautify
UmbrellaLeaf5 d359aa9
update comments in task_06
UmbrellaLeaf5 36982bd
complete task_05 and code beautify in task_06
UmbrellaLeaf5 a9ab29a
update graph class (consts and integral->arithmetic)
UmbrellaLeaf5 7969ed2
code beautify in task_01 and task_03
UmbrellaLeaf5 246c0b0
CMake structure update and code beautify
UmbrellaLeaf5 ebe80e6
update comments format and fix logic issue in task_05
UmbrellaLeaf5 0c93835
add tests for task_05
UmbrellaLeaf5 9c921b0
update README.md and CMakeLists in tasks_05_06
UmbrellaLeaf5 4314609
hotfix missing include
UmbrellaLeaf5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at: | ||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.195.0/containers/cpp | ||
{ | ||
"name": "C++", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
// Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04 | ||
// Use Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon | ||
"args": { | ||
"VARIANT": "ubuntu-24.04" | ||
} | ||
}, | ||
"runArgs": [ | ||
"--cap-add=SYS_PTRACE", | ||
"--security-opt", | ||
"seccomp=unconfined" | ||
], | ||
// Configure tool-specific properties. | ||
"customizations": { | ||
// Configure properties specific to VS Code. | ||
"vscode": { | ||
// Set *default* container specific settings.json values on container create. | ||
"settings": { | ||
"C_Cpp.clang_format_fallbackStyle": "Google", | ||
"C_Cpp.clang_format_path": "clang-format", | ||
"C_Cpp.clang_format_style": "file", | ||
"C_Cpp.formatting": "clangFormat", | ||
"clang-format.executable": "clang-format", | ||
"clang-format.fallbackStyle": "Google", | ||
"clang-format.language.cpp.enable": true, | ||
"clang.executable": "clang", | ||
"editor.formatOnSave": true | ||
}, | ||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [ | ||
"llvm-vs-code-extensions.vscode-clangd", | ||
"ms-vscode.cpptools", | ||
"xaver.clang-format" | ||
] | ||
} | ||
}, | ||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "gcc -v", | ||
// Comment out this line to run as root instead. | ||
"remoteUser": "vscode" | ||
"name": "C++", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
// Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04 | ||
// Use Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon | ||
"args": { | ||
"VARIANT": "ubuntu-24.04" | ||
} | ||
}, | ||
"runArgs": [ | ||
"--cap-add=SYS_PTRACE", | ||
"--security-opt", | ||
"seccomp=unconfined" | ||
], | ||
// Configure tool-specific properties. | ||
"customizations": { | ||
// Configure properties specific to VS Code. | ||
"vscode": { | ||
// Set *default* container specific settings.json values on container create. | ||
"settings": { | ||
"C_Cpp.clang_format_fallbackStyle": "Google", | ||
"C_Cpp.clang_format_path": "clang-format", | ||
"C_Cpp.clang_format_style": "file", | ||
"C_Cpp.formatting": "clangFormat", | ||
"clang-format.executable": "clang-format", | ||
"clang-format.fallbackStyle": "Google", | ||
"clang-format.language.cpp.enable": true, | ||
"clang.executable": "clang", | ||
"editor.formatOnSave": true | ||
}, | ||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [ | ||
"llvm-vs-code-extensions.vscode-clangd", | ||
"ms-vscode.cpptools", | ||
"xaver.clang-format" | ||
] | ||
} | ||
}, | ||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "gcc -v", | ||
// Comment out this line to run as root instead. | ||
"remoteUser": "vscode" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
cmake_minimum_required(VERSION 3.20) | ||
|
||
project(homeworks) | ||
project(homeworks LANGUAGES CXX) | ||
|
||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib) | ||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -std=c++20 -O2") | ||
|
||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib) | ||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sandbox) | ||
|
||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/additional_tasks) | ||
|
||
file(GLOB_RECURSE tasks_dirs LIST_DIRECTORIES true ".") | ||
|
||
foreach(dir ${tasks_dirs}) | ||
IF(IS_DIRECTORY ${dir}) | ||
IF(${dir} MATCHES "task_0[0-9]$" AND NOT ${dir} MATCHES "build") | ||
add_subdirectory(${dir}) | ||
ENDIF() | ||
ELSE() | ||
CONTINUE() | ||
IF(IS_DIRECTORY ${dir}) | ||
IF(${dir} MATCHES "task_0[0-9]$" AND NOT ${dir} MATCHES "build") | ||
add_subdirectory(${dir}) | ||
ENDIF() | ||
ELSE() | ||
CONTINUE() | ||
ENDIF() | ||
endforeach() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# Домашнее задание для 2 семестра алгоритмов и структур данных | ||
## (Homework for second semester algorithms and data structures on MIPT DAFE/RSE) | ||
|
||
### Для удобства можно пользоваться папкой lib, все файлы из этой папки будут подключаться к любой задаче | ||
|
||
### Можно получить дополнительные баллы, если добавить интересные текстовые задачи. Необходимы текст задачи, решение и тесты. Каждая задача отдельный ПР, полчуть дополнительные баллы можно только если пулл реквест замержен в основную ветку. | ||
Можно получить дополнительные баллы, если добавить интересные текстовые задачи. Необходимы текст задачи, решение и тесты. Каждая задача отдельный - Pull Request, получить дополнительные баллы можно только если PR замерджен в основную ветку. | ||
|
||
### Можно получить дополнительные баллы, если добавить теорию в папку doc. Делается в отдельном ПР, полчуть дополнительные баллы можно только если пулл реквест замержен в основную ветку. | ||
Можно получить дополнительные баллы, если добавить теорию в папку doc. Делается в отдельном PR, только если PR замерджен в основную ветку. | ||
|
||
### Код должен быть отформатирован clang-format'ом со стилем Google | ||
Код должен быть отформатирован clang-format'ом со стилем Google. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "../graph.hpp" | ||
|
||
GRAPH_TEMPLATE_CONSTRUCT_FOR_INTEGRAL; | ||
|
||
template <AllowedVertType vert_t, AllowedWeightType weight_t> | ||
const std::string& Graph<vert_t, weight_t>::Edge::Name() const { | ||
static std::string name; | ||
|
||
if (IsWeighted()) | ||
name = "[" + std::to_string(StartVert()) + "->" + | ||
std::to_string(EndVert()) + ", w: " + std::to_string(Weight()) + "]"; | ||
else | ||
name = "[" + std::to_string(StartVert()) + "->" + | ||
std::to_string(EndVert()) + "]"; | ||
|
||
// example: "[4->5]" | ||
|
||
return name; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "../graph.hpp" | ||
|
||
GRAPH_TEMPLATE_CONSTRUCT_FOR_INTEGRAL; | ||
|
||
template <AllowedVertType vert_t, AllowedWeightType weight_t> | ||
Graph<vert_t, weight_t> Graph<vert_t, weight_t>::GraphFromAdjMatrix( | ||
const std::vector<std::vector<weight_t>>& adj_matrix, bool is_weighted) { | ||
if (adj_matrix.empty()) return Graph(); | ||
|
||
std::vector<Edge> edges{}; | ||
|
||
if (adj_matrix.size() != adj_matrix[0].size()) | ||
throw std::invalid_argument( | ||
"GraphFromAdjMatrix: AdjacencyMatrix is not squared."); | ||
|
||
for (size_t row = 0; row < adj_matrix.size(); row++) { | ||
if (row != 0) | ||
if (adj_matrix[row].size() != adj_matrix[row - 1].size()) | ||
throw std::invalid_argument( | ||
"GraphFromAdjMatrix: AdjacencyMatrix is not squared [row " | ||
"problem]."); | ||
|
||
for (size_t col = 0; col < adj_matrix[row].size(); col++) { | ||
if (adj_matrix[row][col] == 0) continue; | ||
|
||
if (is_weighted) | ||
edges.push_back(Edge(col, row, adj_matrix[col][row])); | ||
else | ||
edges.push_back(Edge(col, row)); | ||
} | ||
} | ||
|
||
return Graph(edges); | ||
} | ||
|
||
template <AllowedVertType vert_t, AllowedWeightType weight_t> | ||
Graph<vert_t, weight_t> Graph<vert_t, weight_t>::GraphFromAdjList( | ||
const std::vector<std::vector<vert_t>>& adj_list) { | ||
if (adj_list.empty()) return Graph(); | ||
|
||
std::vector<Edge> edges{}; | ||
|
||
for (size_t row = 0; row < adj_list.size(); row++) | ||
for (size_t col = 0; col < adj_list[row].size(); col++) | ||
edges.push_back(Edge(row, adj_list[row][col])); | ||
|
||
return Graph(edges); | ||
} | ||
|
||
template <AllowedVertType vert_t, AllowedWeightType weight_t> | ||
UmbrellaLeaf5 marked this conversation as resolved.
Show resolved
Hide resolved
UmbrellaLeaf5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Graph<vert_t, weight_t>::Graph(const std::vector<Edge>& edges) | ||
: edges_{edges}, verts_() { | ||
if (edges.empty()) return; | ||
|
||
// кол-во вершин = максимальная вершина среди ребер, т.е. в случае size_t | ||
// происходит заполнение вершин до наибольшей из них в списке ребер | ||
vert_t max_vert = 0; | ||
for (const auto& edge : edges_) { | ||
max_vert = std::max(max_vert, edge.StartVert()); | ||
max_vert = std::max(max_vert, edge.EndVert()); | ||
} | ||
|
||
verts_.resize(max_vert + 1); | ||
std::iota(verts_.begin(), verts_.end(), 0); | ||
|
||
if (!IsDirected()) MakeUndirected(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "../graph.hpp" | ||
|
||
GRAPH_TEMPLATE_CONSTRUCT_FOR_INTEGRAL; | ||
|
||
template <AllowedVertType vert_t, AllowedWeightType weight_t> | ||
std::vector<std::vector<vert_t>> | ||
Graph<vert_t, weight_t>::GetAdjListWithoutKeys() const { | ||
std::vector<std::vector<vert_t>> adj_list( | ||
*std::max_element(Verts().begin(), Verts().end()) + 1); | ||
|
||
for (const auto& edge : edges_) { | ||
adj_list[edge.StartVert()].push_back(edge.EndVert()); | ||
if (!IsDirected()) adj_list[edge.EndVert()].push_back(edge.StartVert()); | ||
} | ||
|
||
return adj_list; | ||
} | ||
|
||
template <AllowedVertType vert_t, AllowedWeightType weight_t> | ||
std::vector<std::vector<weight_t>> Graph<vert_t, weight_t>::GetAdjMatrix() | ||
const { | ||
std::vector<std::vector<weight_t>> adj_matrix( | ||
VertsAmount(), std::vector<weight_t>(VertsAmount(), 0)); | ||
|
||
for (const auto& edge : edges_) | ||
if (edge.IsWeighted()) { | ||
adj_matrix[edge.StartVert()][edge.EndVert()] = edge.Weight(); | ||
if (!IsDirected()) | ||
adj_matrix[edge.EndVert()][edge.StartVert()] = edge.Weight(); | ||
} else { | ||
adj_matrix[edge.StartVert()][edge.EndVert()] = 1; | ||
if (!IsDirected()) adj_matrix[edge.EndVert()][edge.StartVert()] = 1; | ||
} | ||
|
||
return adj_matrix; | ||
} | ||
|
||
template <AllowedVertType vert_t, AllowedWeightType weight_t> | ||
std::pair<vert_t, vert_t> Graph<vert_t, weight_t>::ParseEdgeString( | ||
const std::string& edge_str) { | ||
const vert_t pos = edge_str.find("->"); | ||
|
||
if (size_t(pos) == std::string::npos) | ||
throw std::invalid_argument("EdgeString: invalid edge string format: " + | ||
edge_str); | ||
|
||
try { | ||
vert_t start_vert = std::stoul(edge_str.substr(0, pos)); | ||
vert_t end_vert = std::stoul(edge_str.substr(pos + 2)); | ||
|
||
return {start_vert, end_vert}; | ||
} | ||
|
||
catch (...) { | ||
UmbrellaLeaf5 marked this conversation as resolved.
Show resolved
Hide resolved
UmbrellaLeaf5 marked this conversation as resolved.
Show resolved
Hide resolved
UmbrellaLeaf5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw std::invalid_argument( | ||
"EdgeString: invalid edge string format " | ||
"(vertices should be numbers): " + | ||
edge_str); | ||
} | ||
} | ||
|
||
template <AllowedVertType vert_t, AllowedWeightType weight_t> | ||
void Graph<vert_t, weight_t>::RemoveVert(vert_t vert) { | ||
if (!Contains(Verts(), vert)) | ||
throw std::invalid_argument("RemoveVert: there is no such vert in graph: " + | ||
std::to_string(vert)); | ||
|
||
verts_.erase(std::remove(verts_.begin(), verts_.end(), vert), verts_.end()); | ||
|
||
edges_.erase(std::remove_if(edges_.begin(), edges_.end(), | ||
[vert](const Edge& edge) { | ||
return edge.StartVert() == vert || | ||
edge.EndVert() == vert; | ||
}), | ||
edges_.end()); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "../graph.hpp" | ||
|
||
GRAPH_TEMPLATE_CONSTRUCT_FOR_STRING; | ||
|
||
template <AllowedVertType vert_t, AllowedWeightType weight_t> | ||
const std::string& Graph<vert_t, weight_t>::Edge::Name() const { | ||
static std::string name; | ||
|
||
if (IsWeighted()) | ||
name = "['" + StartVert() + "'->'" + EndVert() + | ||
"', w: " + std::to_string(Weight()) + "]"; | ||
else | ||
name = "['" + StartVert() + "'->'" + EndVert() + "']"; | ||
|
||
// example: "["Paris"->"Berlin"]" | ||
|
||
return name; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "../graph.hpp" | ||
|
||
GRAPH_TEMPLATE_CONSTRUCT_FOR_STRING; | ||
|
||
template <AllowedVertType vert_t, AllowedWeightType weight_t> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: constructor does not initialize these fields: edges_, verts_ [cppcoreguidelines-pro-type-member-init] ;
^
UmbrellaLeaf5 marked this conversation as resolved.
Show resolved
Hide resolved
UmbrellaLeaf5 marked this conversation as resolved.
Show resolved
Hide resolved
UmbrellaLeaf5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Graph<vert_t, weight_t>::Graph(const std::vector<Edge>& edges) | ||
: edges_{edges}, verts_() { | ||
if (edges.empty()) return; | ||
|
||
for (const auto& edge : edges_) { | ||
if (!Contains(Verts(), edge.StartVert())) | ||
verts_.push_back(edge.StartVert()); | ||
|
||
if (!Contains(Verts(), edge.EndVert())) verts_.push_back(edge.EndVert()); | ||
} | ||
|
||
if (!IsDirected()) MakeUndirected(); | ||
} | ||
|
||
// DELETED methods | ||
|
||
template <AllowedVertType vert_t, AllowedWeightType weight_t> | ||
Graph<vert_t, weight_t> Graph<vert_t, weight_t>::GraphFromAdjMatrix( | ||
[[maybe_unused]] const std::vector<std::vector<weight_t>>& adj_matrix, | ||
[[maybe_unused]] bool is_weighted) { | ||
throw std::logic_error( | ||
"GraphFromAdjMatrix: this method (constructor) " | ||
"is deleted for std::string."); | ||
} | ||
|
||
template <AllowedVertType vert_t, AllowedWeightType weight_t> | ||
Graph<vert_t, weight_t> Graph<vert_t, weight_t>::GraphFromAdjList( | ||
[[maybe_unused]] const std::vector<std::vector<vert_t>>& adj_list) { | ||
throw std::logic_error( | ||
"GraphFromAdjList: this method (constructor) " | ||
"is deleted for std::string."); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.