diff --git a/alib2graph_algo/src/generate/FixedUndirectedGraph.cpp b/alib2graph_algo/src/generate/FixedUndirectedGraph.cpp new file mode 100644 index 0000000000000000000000000000000000000000..64c8a8a68db51b4dafc712f3a47ba0d62daff77c --- /dev/null +++ b/alib2graph_algo/src/generate/FixedUndirectedGraph.cpp @@ -0,0 +1,41 @@ +// FixedUndirectedGraph.cpp +// +// Created on: 07. 03. 2018 +// Author: Jan Uhlik +// Modified by: +// +// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved. +// Git repository: https://gitlab.fit.cvut.cz/algorithms-library-toolkit/automata-library + +#include "FixedUndirectedGraph.hpp" +#include <registration/AlgoRegistration.hpp> + +graph::UndirectedGraph<int, ext::pair<int, int> > generate::FixedUndirectedGraph::undirected() { + graph::UndirectedGraph<int, ext::pair<int, int> > graph; + + graph.addNode(1); + graph.addNode(2); + graph.addNode(3); + graph.addNode(4); + graph.addNode(5); + graph.addNode(6); + + graph.addEdge(ext::make_pair(1, 2)); + graph.addEdge(2, 3); + graph.addEdge(3, 4); + graph.addEdge(5, 1); + + return graph; +} + +// --------------------------------------------------------------------------------------------------------------------- + +namespace { + +auto FixedUndirectedGraph = + registration::AbstractRegister<generate::FixedUndirectedGraph, graph::UndirectedGraph<int, ext::pair<int, int> > >( + generate::FixedUndirectedGraph::undirected); + +} + +// --------------------------------------------------------------------------------------------------------------------- diff --git a/alib2graph_algo/src/generate/FixedUndirectedGraph.hpp b/alib2graph_algo/src/generate/FixedUndirectedGraph.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d6f37fd0fc4ab3d3b2e23ade7a7ddea164f26a5a --- /dev/null +++ b/alib2graph_algo/src/generate/FixedUndirectedGraph.hpp @@ -0,0 +1,34 @@ +// FixedUndirectedGraph.cpp +// +// Created on: 07. 03. 2018 +// Author: Jan Uhlik +// Modified by: +// +// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved. +// Git repository: https://gitlab.fit.cvut.cz/algorithms-library-toolkit/automata-library + +#ifndef _FIXED_UNDIRECTED_GRAPH_H_ +#define _FIXED_UNDIRECTED_GRAPH_H_ + +#include <graph/GraphClasses.hpp> + +namespace generate { + +class FixedUndirectedGraph { +// --------------------------------------------------------------------------------------------------------------------- + + public: + static graph::UndirectedGraph<int, ext::pair<int, int> > undirected(); + +// --------------------------------------------------------------------------------------------------------------------- + +}; + +// ===================================================================================================================== + + +// --------------------------------------------------------------------------------------------------------------------- + +} // namespace generate + +#endif /* _FIXED_UNDIRECTED_GRAPH_H_ */ diff --git a/alib2graph_algo/src/generate/FixedWeightedSquareGrid8.cpp b/alib2graph_algo/src/generate/FixedWeightedSquareGrid8.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a73985f87f82f41028333f875fa514cc8ea5c236 --- /dev/null +++ b/alib2graph_algo/src/generate/FixedWeightedSquareGrid8.cpp @@ -0,0 +1,49 @@ +// FixedWeightedSquareGrid8.cpp +// +// Created on: 07. 03. 2018 +// Author: Jan Uhlik +// Modified by: +// +// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved. +// Git repository: https://gitlab.fit.cvut.cz/algorithms-library-toolkit/automata-library + +#include "FixedWeightedSquareGrid8.hpp" +#include <registration/AlgoRegistration.hpp> + +// --------------------------------------------------------------------------------------------------------------------- + +grid::WeightedSquareGrid8<int, + edge::WeightedEdge<ext::pair<int, int>, + double> > generate::FixedWeightedSquareGrid8::weighted_grid() { + + grid::WeightedSquareGrid8<int, edge::WeightedEdge<ext::pair<int, int>, double>> graph(11, 11); + + graph.addObstacle(2, 5); + graph.addObstacle(3, 5); + graph.addObstacle(4, 5); + graph.addObstacle(5, 5); + graph.addObstacle(6, 5); + graph.addObstacle(7, 5); + graph.addObstacle(5, 3); + graph.addObstacle(5, 4); + graph.addObstacle(5, 6); + graph.addObstacle(5, 7); + graph.addObstacle(5, 8); + + return graph; +} + +// --------------------------------------------------------------------------------------------------------------------- + +namespace { + +auto FixedWeightedSquareGrid = + registration::AbstractRegister<generate::FixedWeightedSquareGrid8, + grid::WeightedSquareGrid8<int, + edge::WeightedEdge<ext::pair<int, int>, + double>>>( + generate::FixedWeightedSquareGrid8::weighted_grid); + +} + +// --------------------------------------------------------------------------------------------------------------------- diff --git a/alib2graph_algo/src/generate/FixedWeightedSquareGrid8.hpp b/alib2graph_algo/src/generate/FixedWeightedSquareGrid8.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5dde922d659cf7730c94f554642bd464a5726ac4 --- /dev/null +++ b/alib2graph_algo/src/generate/FixedWeightedSquareGrid8.hpp @@ -0,0 +1,34 @@ +// FixedWeightedSquareGrid8.hpp +// +// Created on: 07. 03. 2018 +// Author: Jan Uhlik +// Modified by: +// +// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved. +// Git repository: https://gitlab.fit.cvut.cz/algorithms-library-toolkit/automata-library + +#ifndef ALIB2_FIXEDWEIGHTEDSQUAREGRID8_HPP +#define ALIB2_FIXEDWEIGHTEDSQUAREGRID8_HPP + +#include <grid/GridClasses.hpp> + +namespace generate { + +class FixedWeightedSquareGrid8 { +// --------------------------------------------------------------------------------------------------------------------- + + public: + static grid::WeightedSquareGrid8<int, edge::WeightedEdge<ext::pair<int, int>, double> > weighted_grid(); + +// --------------------------------------------------------------------------------------------------------------------- + +}; + +// ===================================================================================================================== + + +// --------------------------------------------------------------------------------------------------------------------- + +} // namespace generate + +#endif //ALIB2_FIXEDWEIGHTEDSQUAREGRID8_HPP diff --git a/alib2graph_algo/src/generate/FixedWeightedUndirectedGraph.cpp b/alib2graph_algo/src/generate/FixedWeightedUndirectedGraph.cpp new file mode 100644 index 0000000000000000000000000000000000000000..61e3ee018021413fc6fad7a00ec5fab4bd976a2a --- /dev/null +++ b/alib2graph_algo/src/generate/FixedWeightedUndirectedGraph.cpp @@ -0,0 +1,44 @@ +// FixedWeightedUndirectedGraph.cpp +// +// Created on: 07. 03. 2018 +// Author: Jan Uhlik +// Modified by: +// +// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved. +// Git repository: https://gitlab.fit.cvut.cz/algorithms-library-toolkit/automata-library + +#include "FixedWeightedUndirectedGraph.hpp" +#include <registration/AlgoRegistration.hpp> + +graph::WeightedUndirectedGraph<int, + edge::WeightedEdge<int, + double> > generate::FixedWeightedUndirectedGraph::weighted_undirected() { + graph::WeightedUndirectedGraph<int, edge::WeightedEdge<int, double> > graph; + + graph.addNode(1); + graph.addNode(2); + graph.addNode(3); + graph.addNode(4); + graph.addNode(5); + graph.addNode(6); + + graph.addEdge(1, 2, 1); + graph.addEdge(2, 3, 1.5); + graph.addEdge(3, 4, 5); + graph.addEdge(5, 1, 6); + + return graph; +} + + +// --------------------------------------------------------------------------------------------------------------------- + +namespace { + +auto FixedWeightedUndirectedGraph = + registration::AbstractRegister<generate::FixedWeightedUndirectedGraph, + graph::WeightedUndirectedGraph<int, edge::WeightedEdge<int, double> > > + (generate::FixedWeightedUndirectedGraph::weighted_undirected); +} + +// --------------------------------------------------------------------------------------------------------------------- diff --git a/alib2graph_algo/src/generate/FixedWeightedUndirectedGraph.hpp b/alib2graph_algo/src/generate/FixedWeightedUndirectedGraph.hpp new file mode 100644 index 0000000000000000000000000000000000000000..583b8e17210ed316cfbe6525af2c01d2784ac799 --- /dev/null +++ b/alib2graph_algo/src/generate/FixedWeightedUndirectedGraph.hpp @@ -0,0 +1,32 @@ +// FixedWeightedUndirectedGraph.hpp +// +// Created on: 07. 03. 2018 +// Author: Jan Uhlik +// Modified by: +// +// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved. +// Git repository: https://gitlab.fit.cvut.cz/algorithms-library-toolkit/automata-library + +#ifndef ALIB2_FIXEDWEIGHTEDUNDIRECTEDGRAPH_HPP +#define ALIB2_FIXEDWEIGHTEDUNDIRECTEDGRAPH_HPP + +#include <graph/GraphClasses.hpp> + +namespace generate { + +class FixedWeightedUndirectedGraph { +// --------------------------------------------------------------------------------------------------------------------- + + public: + static graph::WeightedUndirectedGraph<int, edge::WeightedEdge<int, double> > weighted_undirected(); + +// --------------------------------------------------------------------------------------------------------------------- + +}; + +// ===================================================================================================================== + + +} // namespace generate + +#endif //ALIB2_FIXEDWEIGHTEDUNDIRECTEDGRAPH_HPP diff --git a/alib2graph_algo/src/generate/RandomGraphFactory.cpp b/alib2graph_algo/src/generate/RandomGraphFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7643ac785bc15f8f77bfff3e065b05238f2da809 --- /dev/null +++ b/alib2graph_algo/src/generate/RandomGraphFactory.cpp @@ -0,0 +1,13 @@ +// GraphGenerator.cpp +// +// Created on: 19. 03. 2018 +// Author: Jan Uhlik +// Modified by: +// +// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved. +// Git repository: https://gitlab.fit.cvut.cz/algorithms-library-toolkit/automata-library + +namespace { + +} + diff --git a/alib2graph_algo/src/generate/RandomGraphFactory.hpp b/alib2graph_algo/src/generate/RandomGraphFactory.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d7e02b59e116f6cff597c684f3c10aa7e18888fe --- /dev/null +++ b/alib2graph_algo/src/generate/RandomGraphFactory.hpp @@ -0,0 +1,155 @@ +// GraphGenerator.hpp +// +// Created on: 19. 03. 2018 +// Author: Jan Uhlik +// Modified by: +// +// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved. +// Git repository: https://gitlab.fit.cvut.cz/algorithms-library-toolkit/automata-library + +#ifndef ALIB2_GRAPHGENERATOR_HPP +#define ALIB2_GRAPHGENERATOR_HPP + +#include <alib/pair> +#include <alib/vector> +#include <alib/tuple> +#include <random> + +namespace generate { + +class RandomGraphFactory { +// --------------------------------------------------------------------------------------------------------------------- + public: + template<typename TGraph> + static + ext::tuple<TGraph, typename TGraph::node_type, typename TGraph::node_type> + randomGraph(unsigned long max_nodes, unsigned long branching_factor); + +// --------------------------------------------------------------------------------------------------------------------- + + template<typename TGraph> + static + ext::tuple<TGraph, typename TGraph::node_type, typename TGraph::node_type> + randomWeightedGraph(unsigned long max_nodes, + unsigned long branching_factor, + long max_weight); + +// --------------------------------------------------------------------------------------------------------------------- + +}; + +// ===================================================================================================================== + +template<typename TGraph> +ext::tuple<TGraph, typename TGraph::node_type, typename TGraph::node_type> +RandomGraphFactory::randomGraph(unsigned long max_nodes, + unsigned long branching_factor) { + using node_type = typename TGraph::node_type; + + // Seed with a real random value, if available + std::random_device r; + std::default_random_engine e1(r()); + + // Create distribution + std::uniform_int_distribution<unsigned long> number_of_nodes(1, max_nodes); // Generate number of nodes + std::uniform_int_distribution<unsigned long> + number_of_edges(1, branching_factor); // Generate number of edges for each node + + unsigned long node_cnt = number_of_nodes(e1); + + std::uniform_int_distribution<node_type> node_id(0, node_cnt * 10); // Generate indexes of nodes + std::uniform_int_distribution<long> random_node(0, node_cnt - 1); // Generate random index in vector of nodes + + TGraph graph; + + // Add nodes + ext::vector<node_type> nodes; + + // Generate start and goal node + node_type start(node_id(e1)); + node_type goal(node_id(e1)); + nodes.push_back(start); + graph.addNode(start); + nodes.push_back(goal); + graph.addNode(goal); + + // Generate nodes + for (unsigned long i = 0; i < node_cnt; ++i) { + node_type node(node_id(e1)); + graph.addNode(node); + nodes.push_back(node); + } + + // Generate edges + for (const auto &v : nodes) { + unsigned long cnt = number_of_edges(e1); // Generate number of edges for current v + for (unsigned long i = 0; i < cnt; ++i) { + long w = random_node(e1); // Get target v + graph.addEdge(v, nodes.at(w)); + } + } + + return ext::make_tuple(graph, start, goal); +} + +// --------------------------------------------------------------------------------------------------------------------- + +template<typename TGraph> +ext::tuple<TGraph, typename TGraph::node_type, typename TGraph::node_type> +RandomGraphFactory::randomWeightedGraph( + unsigned long max_nodes, + unsigned long branching_factor, + long max_weight) { + using node_type = typename TGraph::node_type; + using weight_type = typename TGraph::edge_type::weight_type; + + // Seed with a real random value, if available + std::random_device r; + std::default_random_engine e1(r()); + + // Create distribution + std::uniform_int_distribution<unsigned long> number_of_nodes(1, max_nodes); // Generate number of nodes + std::uniform_int_distribution<unsigned long> + number_of_edges(1, branching_factor); // Generate number of edges for each node + std::uniform_real_distribution<weight_type> edge_weight(1, max_weight); // Generate edge weight + + unsigned long node_cnt = number_of_nodes(e1); + + std::uniform_int_distribution<node_type> node_id(0, node_cnt * 10); // Generate indexes of nodes + std::uniform_int_distribution<long> random_node(0, node_cnt - 1); // Generate random index in vector of nodes + + TGraph graph; + + // Add nodes + ext::vector<node_type> nodes; + + // Generate start and goal node + node_type start(node_id(e1)); + node_type goal(node_id(e1)); + nodes.push_back(start); + graph.addNode(start); + nodes.push_back(goal); + graph.addNode(goal); + + // Generate nodes + for (unsigned long i = 0; i < node_cnt; ++i) { + node_type node(node_id(e1)); + graph.addNode(node); + nodes.push_back(node); + } + + // Generate edges + for (const auto &v : nodes) { + unsigned long cnt = number_of_edges(e1); // Generate number of edges for current v + for (unsigned long i = 0; i < cnt; ++i) { + long w = random_node(e1); // Get target v + graph.addEdge(v, nodes.at(w), edge_weight(e1)); + } + } + + return ext::make_tuple(graph, start, goal); +} + +// --------------------------------------------------------------------------------------------------------------------- +} // namespace generate +#endif //ALIB2_GRAPHGENERATOR_HPP diff --git a/alib2graph_algo/src/generate/RandomGridFactory.cpp b/alib2graph_algo/src/generate/RandomGridFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e097333161fdb39e6c6cf51843077b04320e5cd2 --- /dev/null +++ b/alib2graph_algo/src/generate/RandomGridFactory.cpp @@ -0,0 +1,12 @@ +// RandomGridFactory.cpp +// +// Created on: 29. 03. 2018 +// Author: Jan Uhlik +// Modified by: +// +// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved. +// Git repository: https://gitlab.fit.cvut.cz/algorithms-library-toolkit/automata-library + +namespace { + +} diff --git a/alib2graph_algo/src/generate/RandomGridFactory.hpp b/alib2graph_algo/src/generate/RandomGridFactory.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4efc4182873edc37052b22a0b06e862ba790b506 --- /dev/null +++ b/alib2graph_algo/src/generate/RandomGridFactory.hpp @@ -0,0 +1,77 @@ +// RandomGridFactory.hpp +// +// Created on: 29. 03. 2018 +// Author: Jan Uhlik +// Modified by: +// +// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved. +// Git repository: https://gitlab.fit.cvut.cz/algorithms-library-toolkit/automata-library + +#ifndef ALIB2_RANDOMGRIDFACTORY_HPP +#define ALIB2_RANDOMGRIDFACTORY_HPP + +#include <alib/pair> +#include <alib/tuple> +#include <alib/vector> +#include <random> + +namespace generate { + +class RandomGridFactory { +// --------------------------------------------------------------------------------------------------------------------- + public: + + template<typename TGrid> + static + ext::tuple<TGrid, typename TGrid::node_type, typename TGrid::node_type> + randomGrid(unsigned long height, unsigned long widht, unsigned long max_obstacles); + +// --------------------------------------------------------------------------------------------------------------------- + +}; + +// ===================================================================================================================== + +template<typename TGrid> +ext::tuple<TGrid, typename TGrid::node_type, typename TGrid::node_type> +RandomGridFactory::randomGrid(unsigned long height, + unsigned long width, + unsigned long max_obstacles) { + using coordinate_type = typename TGrid::coordinate_type; + using node_type = typename TGrid::node_type; + + // Seed with a real random value, if available + std::random_device r; + std::default_random_engine e1(r()); + + // Create distribution + std::uniform_int_distribution<unsigned long> number_of_obstacles(0, max_obstacles); // Generate number of nodes + std::uniform_int_distribution<coordinate_type> random_height(0, height - 1); // Generate height coordinate + std::uniform_int_distribution<coordinate_type> random_width(0, width - 1); // Generate width coordinate + unsigned long obstacle_cnt = number_of_obstacles(e1); + + TGrid grid(height, width); + + // Add nodes + ext::vector<node_type> obstacles; + + // Generate start and goal node + node_type start(random_height(e1), random_width(e1)); + node_type goal(random_height(e1), random_width(e1)); + obstacles.push_back(start); + obstacles.push_back(goal); + + // Generate obstacles + for (unsigned long i = 0; i < obstacle_cnt; ++i) { + node_type obstacle(random_height(e1), random_width(e1)); + obstacles.push_back(obstacle); + grid.addObstacle(std::move(obstacle)); + } + + return ext::make_tuple(grid, start, goal); +} + +// --------------------------------------------------------------------------------------------------------------------- + +} // namespace generate +#endif //ALIB2_RANDOMGRIDFACTORY_HPP