diff --git a/library/talipot-ogdf/CMakeLists.txt b/library/talipot-ogdf/CMakeLists.txt index 3a9042bc02..dbcf8d1acf 100644 --- a/library/talipot-ogdf/CMakeLists.txt +++ b/library/talipot-ogdf/CMakeLists.txt @@ -7,7 +7,8 @@ ENDIF(WIN32) DISABLE_COMPILER_WARNINGS() -SET(TalipotOGDF_SRCS src/TalipotToOGDF.cpp src/OGDFLayoutPluginBase.cpp) +SET(TalipotOGDF_SRCS src/TalipotToOGDF.cpp src/OGDFLayoutPluginBase.cpp + src/OGDFUtils.cpp) ADD_LIBRARY(${LibTalipotOGDFName} SHARED ${TalipotOGDF_SRCS}) @@ -21,7 +22,7 @@ INSTALL( ARCHIVE DESTINATION ${TalipotLibInstallDir}) INSTALL(FILES include/talipot/OGDFLayoutPluginBase.h - include/talipot/TalipotToOGDF.h + include/talipot/TalipotToOGDF.h include/talipot/OGDFUtils.h DESTINATION ${TalipotIncludeInstallDir}/talipot/) IF(TALIPOT_ACTIVATE_PYTHON_WHEEL_TARGET) diff --git a/library/talipot-ogdf/include/talipot/OGDFUtils.h b/library/talipot-ogdf/include/talipot/OGDFUtils.h new file mode 100644 index 0000000000..a1d5973244 --- /dev/null +++ b/library/talipot-ogdf/include/talipot/OGDFUtils.h @@ -0,0 +1,30 @@ +/** + * + * Copyright (C) 2023-2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#ifndef TALIPOT_OGDF_UTILS_H +#define TALIPOT_OGDF_UTILS_H + +#include +#include + +TLP_OGDF_SCOPE tlp::Graph *convertOGDFGraphToTalipotGraph(ogdf::Graph &graph, + tlp::Graph *tlpGraph = nullptr); + +template +ogdf::Array vectorToOGDFArray(const std::vector &v) { + auto a = ogdf::Array(v.size()); + std::copy(v.begin(), v.end(), a.begin()); + return a; +} + +#endif // TALIPOT_OGDF_UTILS_H diff --git a/library/talipot-ogdf/src/OGDFUtils.cpp b/library/talipot-ogdf/src/OGDFUtils.cpp new file mode 100644 index 0000000000..5c7857f80a --- /dev/null +++ b/library/talipot-ogdf/src/OGDFUtils.cpp @@ -0,0 +1,38 @@ +/** + * + * Copyright (C) 2023 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include + +using namespace std; + +tlp::Graph *convertOGDFGraphToTalipotGraph(ogdf::Graph &graph, tlp::Graph *tlpGraph) { + if (!tlpGraph) { + tlpGraph = tlp::newGraph(); + } else { + tlpGraph->clear(); + } + + unordered_map nodesMap; + + for (ogdf::node n : graph.nodes) { + nodesMap[n] = tlpGraph->addNode(); + } + + for (ogdf::edge e : graph.edges) { + tlpGraph->addEdge(nodesMap[e->source()], nodesMap[e->target()]); + } + + return tlpGraph; +} diff --git a/plugins/import/CMakeLists.txt b/plugins/import/CMakeLists.txt index a72982d6b5..26e46ed00f 100644 --- a/plugins/import/CMakeLists.txt +++ b/plugins/import/CMakeLists.txt @@ -2,6 +2,7 @@ ADD_SUBDIRECTORY(SocialNetwork) ADD_SUBDIRECTORY(BibTeX) ADD_SUBDIRECTORY(Graphviz) ADD_SUBDIRECTORY(Git) +ADD_SUBDIRECTORY(OGDF) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${TalipotCoreBuildInclude} ${TalipotCoreInclude} ${TalipotGUIInclude}) diff --git a/plugins/import/OGDF/CMakeLists.txt b/plugins/import/OGDF/CMakeLists.txt new file mode 100644 index 0000000000..5cbb9e8e51 --- /dev/null +++ b/plugins/import/OGDF/CMakeLists.txt @@ -0,0 +1,31 @@ +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${TalipotCoreBuildInclude} + ${TalipotCoreInclude} ${OGDFInclude} ${TalipotOGDFInclude}) + +SET(PLUGINS_SRCS + OGDFPetersenGraph.cpp + OGDFRandomGeographicalGraph.cpp + OGDFRandomHierarchy.cpp + OGDFGlobeGraph.cpp + OGDFRegularLatticeGraph.cpp + OGDFRegularTree.cpp + OGDFCompleteKPartiteGraph.cpp + OGDFCirculantGraph.cpp + OGDFRandomRegularGraph.cpp + OGDFRandomGraph.cpp + OGDFRandomSimpleGraph.cpp + OGDFRandomSimpleGraphByProbability.cpp + OGDFRandomChungLuGraph.cpp) + +DISABLE_COMPILER_WARNINGS() + +TALIPOT_ADD_PLUGIN( + NAME + OGDFGraphGenerators + SRCS + ${PLUGINS_SRCS} + LINKS + ${LibTalipotCoreName} + ${LibTalipotOGDFName} + ${OGDF_LIBRARY} + INSTALL_DIR + ${TalipotPluginsInstallDir}) diff --git a/plugins/import/OGDF/OGDFCirculantGraph.cpp b/plugins/import/OGDF/OGDFCirculantGraph.cpp new file mode 100644 index 0000000000..b901c14824 --- /dev/null +++ b/plugins/import/OGDF/OGDFCirculantGraph.cpp @@ -0,0 +1,56 @@ +/** + * + * Copyright (C) 2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // n + "the number of nodes of the generated graph", + + // jumps + "the array of distances for edges to be created", +}; + +//================================================================================= + +class OGDFCirculantGraph : public OGDFImportBase { +public: + PLUGININFORMATION( + "Circulant Graph (OGDF)", "Antoine Lambert", "05/2024", + "Generates a simple, undirected graph on n nodes V := v_0,v_1,...,v_{n-1} that contains " + "exactly the edges {v_iv_{i+d}; v_i ∈ V, d ∈ jumps} where node indices are to be understood " + "modulo n. The order of nodes induced by G is the sequence V previously given.", + "1.0", "OGDF") + + OGDFCirculantGraph(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter("n", paramHelp[0].data(), "100"); + addInParameter>("jumps", paramHelp[1].data(), "(10, 20, 30, 40)"); + } + + bool importOGDFGraph() override { + int n = 100; + vector jumps = {10, 20, 30, 40}; + if (dataSet != nullptr) { + dataSet->get("n", n); + dataSet->get("jumps", jumps); + } + ogdf::circulantGraph(G, n, vectorToOGDFArray(jumps)); + return true; + } +}; + +PLUGIN(OGDFCirculantGraph) diff --git a/plugins/import/OGDF/OGDFCompleteKPartiteGraph.cpp b/plugins/import/OGDF/OGDFCompleteKPartiteGraph.cpp new file mode 100644 index 0000000000..36562f0b00 --- /dev/null +++ b/plugins/import/OGDF/OGDFCompleteKPartiteGraph.cpp @@ -0,0 +1,46 @@ +/** + * + * Copyright (C) 2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // signature + "contains the positive values k1, k2, ..., kn.", +}; + +//================================================================================= + +class OGDFCompleteKPartiteGraph : public OGDFImportBase { +public: + PLUGININFORMATION("Complete K-partite Graph (OGDF)", "Antoine Lambert", "05/2024", + "Creates the complete k-partite graph K_{k1,k2,...,kn}.", "1.0", "OGDF") + + OGDFCompleteKPartiteGraph(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter>("signature", paramHelp[0].data(), "(10, 20, 30, 40)"); + } + + bool importOGDFGraph() override { + vector signature = {10, 20, 30, 40}; + if (dataSet != nullptr) { + dataSet->get("signature", signature); + } + ogdf::completeKPartiteGraph(G, vectorToOGDFArray(signature)); + return true; + } +}; + +PLUGIN(OGDFCompleteKPartiteGraph) diff --git a/plugins/import/OGDF/OGDFGlobeGraph.cpp b/plugins/import/OGDF/OGDFGlobeGraph.cpp new file mode 100644 index 0000000000..211bc53c5b --- /dev/null +++ b/plugins/import/OGDF/OGDFGlobeGraph.cpp @@ -0,0 +1,55 @@ +/** + * + * Copyright (C) 2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // meridians + "the number of meridians", + + // latitudes + "the number of latitudes", +}; + +//================================================================================= + +class OGDFGlobeGraph : public OGDFImportBase { +public: + PLUGININFORMATION("Globe Graph (OGDF)", "Antoine Lambert", "03/2024", + "Creates a globe graph with a given number of meridians and latitudes. " + "The graph will contain a node at each crossing of a meridian and a latitude, " + "and a node at each pole.", + "1.0", "OGDF") + + OGDFGlobeGraph(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter("meridians", paramHelp[0].data(), "30"); + addInParameter("latitudes", paramHelp[1].data(), "30"); + } + + bool importOGDFGraph() override { + int meridians = 30; + int latitudes = 30; + if (dataSet != nullptr) { + dataSet->get("meridians", meridians); + dataSet->get("latitudes", latitudes); + } + ogdf::globeGraph(G, meridians, latitudes); + return true; + } +}; + +PLUGIN(OGDFGlobeGraph) diff --git a/plugins/import/OGDF/OGDFImportBase.h b/plugins/import/OGDF/OGDFImportBase.h new file mode 100644 index 0000000000..3daccc1962 --- /dev/null +++ b/plugins/import/OGDF/OGDFImportBase.h @@ -0,0 +1,34 @@ +/** + * + * Copyright (C) 2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include + +class OGDFImportBase : public tlp::ImportModule { + +public: + OGDFImportBase(tlp::PluginContext *context) : tlp::ImportModule(context) {} + virtual bool importOGDFGraph() = 0; + + bool importGraph() override { + if (importOGDFGraph()) { + convertOGDFGraphToTalipotGraph(G, graph); + return true; + } + return false; + } + +protected: + ogdf::Graph G; +}; \ No newline at end of file diff --git a/plugins/import/OGDF/OGDFPetersenGraph.cpp b/plugins/import/OGDF/OGDFPetersenGraph.cpp new file mode 100644 index 0000000000..e1cd40b082 --- /dev/null +++ b/plugins/import/OGDF/OGDFPetersenGraph.cpp @@ -0,0 +1,58 @@ +/** + * + * Copyright (C) 2023-2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // n + "the number of nodes on the outer cycle", + + // m + "the length of jumps for the inner part", +}; + +//================================================================================= + +class OGDFPetersenGraph : public OGDFImportBase { +public: + PLUGININFORMATION( + "Petersen Graph (OGDF)", "Antoine Lambert", "11/2023", + "Creates an outer cycle of nodes 1, ..., n, each of which has a direct neighbor (a " + "corresponding inner node). For two outer nodes i, j, there is an edge between their " + "corresponding inner nodes if the absolute difference of i and j equals the jump length m.", + "1.0", "OGDF") + + OGDFPetersenGraph(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter("n", paramHelp[0].data(), "5"); + addInParameter("m", paramHelp[1].data(), "2"); + } + + bool importOGDFGraph() override { + int n = 5; + int m = 2; + + if (dataSet != nullptr) { + dataSet->get("n", n); + dataSet->get("m", m); + } + + petersenGraph(G, n, m); + return true; + } +}; + +PLUGIN(OGDFPetersenGraph) diff --git a/plugins/import/OGDF/OGDFRandomChungLuGraph.cpp b/plugins/import/OGDF/OGDFRandomChungLuGraph.cpp new file mode 100644 index 0000000000..f9b99fc5b0 --- /dev/null +++ b/plugins/import/OGDF/OGDFRandomChungLuGraph.cpp @@ -0,0 +1,72 @@ +/** + * + * Copyright (C) 2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // expectedDegreeDistribution + "a list of expected degrees, or weights, for the individual nodes. Its length defines the " + "number of nodes n.", +}; + +//================================================================================= + +class OGDFRandomChungLuGraph : public OGDFImportBase { +public: + PLUGININFORMATION( + "Random Chung Lu Graph (OGDF)", "Antoine Lambert", "06/2024", + "Creates a graph where edges are inserted based on given weights. Implements the algorithm " + "described in: \"The average distance in a random graph with given expected degrees, Fang " + "Chung and Linyuan Lu, https://www.math.ucsd.edu/~fan/wp/aveflong.pdf\". Given an expected " + "degree distribution of length n: (w_1, ..., w_n) with 0 < w_k < n. Let S be the sum over " + "all expected degrees. Consider each edge independently and insert it with probability " + "p_{ij} = (w_i * w_j) / S. Each degree must be strictly between 0 and n, and the square of " + "the maximal expected degree must be lower than the sum of all expected degrees.", + "1.0", "OGDF") + + OGDFRandomChungLuGraph(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter>("expectedDegreeDistribution", paramHelp[0].data(), + "(1, 2, 2, 3, 3, 3, 4)"); + } + + bool importOGDFGraph() override { + vector expectedDegreeDistribution = {1, 2, 2, 3, 3, 3, 4}; + + if (dataSet != nullptr) { + dataSet->get("expectedDegreeDistribution", expectedDegreeDistribution); + } + + int S = reduce(expectedDegreeDistribution.begin(), expectedDegreeDistribution.end()); + + for (auto w : expectedDegreeDistribution) { + if (w <= 0 || w >= expectedDegreeDistribution.size()) { + pluginProgress->setError("each degree must be strictly between 0 and n"); + return false; + } + if (w * w >= S) { + pluginProgress->setError("the square of the maximal expected degree must be lower than the " + "sum of all expected degrees"); + return false; + } + } + + ogdf::randomChungLuGraph(G, vectorToOGDFArray(expectedDegreeDistribution)); + return true; + } +}; + +PLUGIN(OGDFRandomChungLuGraph) diff --git a/plugins/import/OGDF/OGDFRandomGeographicalGraph.cpp b/plugins/import/OGDF/OGDFRandomGeographicalGraph.cpp new file mode 100644 index 0000000000..4e28dc6539 --- /dev/null +++ b/plugins/import/OGDF/OGDFRandomGeographicalGraph.cpp @@ -0,0 +1,63 @@ +/** + * + * Copyright (C) 2023-2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // n + "the number of nodes in the graph", + + // threshold + "threshold for edge insertion", +}; + +//================================================================================= + +class OGDFRandomGeographicalGraph : public OGDFImportBase { +public: + PLUGININFORMATION("Random Geographical Graph (OGDF)", "Antoine Lambert", "11/2023", + "Creates a random geometric graph where edges are created based on " + "their distance and the weight of nodes", + "1.0", "OGDF") + + OGDFRandomGeographicalGraph(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter("n", paramHelp[0].data(), "100"); + addInParameter("threshold", paramHelp[1].data(), "0.7"); + } + + bool importOGDFGraph() override { + int n = 100; + double threshold = 0.7; + + if (dataSet != nullptr) { + dataSet->get("n", n); + dataSet->get("threshold", threshold); + } + + ogdf::Array weights = ogdf::Array(n); + for (int &w : weights) { + w = tlp::randomNumber(n); + } + uniform_int_distribution dist(0, n); + ogdf::randomGeographicalThresholdGraph(G, weights, dist, 0.7); + return true; + } +}; + +PLUGIN(OGDFRandomGeographicalGraph) diff --git a/plugins/import/OGDF/OGDFRandomGraph.cpp b/plugins/import/OGDF/OGDFRandomGraph.cpp new file mode 100644 index 0000000000..48aff1dfbc --- /dev/null +++ b/plugins/import/OGDF/OGDFRandomGraph.cpp @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // n + "the number of nodes", + // m + "the mumber of edges", +}; + +//================================================================================= + +class OGDFRandomGraph : public OGDFImportBase { +public: + PLUGININFORMATION("Random Graph (OGDF)", "Antoine Lambert", "06/2024", "Creates a random graph", + "1.0", "OGDF") + + OGDFRandomGraph(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter("n", paramHelp[0].data(), "1000"); + addInParameter("m", paramHelp[1].data(), "2000"); + } + + bool importOGDFGraph() override { + int n = 1000; + int m = 2000; + + if (dataSet != nullptr) { + dataSet->get("n", n); + dataSet->get("m", m); + } + + ogdf::randomGraph(G, n, m); + return true; + } +}; + +PLUGIN(OGDFRandomGraph) diff --git a/plugins/import/OGDF/OGDFRandomHierarchy.cpp b/plugins/import/OGDF/OGDFRandomHierarchy.cpp new file mode 100644 index 0000000000..243193e4cc --- /dev/null +++ b/plugins/import/OGDF/OGDFRandomHierarchy.cpp @@ -0,0 +1,68 @@ +/** + * + * Copyright (C) 2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // n + "the number of nodes", + // m + "the number of edges", + // planar + "determines if the resulting graph is (level-)planar", + // singleSource + "determines if the graph is a single-source graph", + // longEdges + "determines if the graph has long edges (spanning 2 layers or more); " + "otherwise the graph is proper"}; + +//================================================================================= + +class OGDFRandomHierarchy : public OGDFImportBase { +public: + PLUGININFORMATION("Random Hierarchy (OGDF)", "Antoine Lambert", "02/2024", + "Creates a random hierarchical graph", "1.0", "OGDF") + + OGDFRandomHierarchy(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter("n", paramHelp[0].data(), "1000"); + addInParameter("m", paramHelp[1].data(), "2000"); + addInParameter("planar", paramHelp[2].data(), "true"); + addInParameter("singleSource", paramHelp[3].data(), "true"); + addInParameter("longEdges", paramHelp[4].data(), "false"); + } + + bool importOGDFGraph() override { + int n = 100; + int m = 100; + bool planar = false; + bool singleSource = false; + bool longEdges = true; + + if (dataSet != nullptr) { + dataSet->get("n", n); + dataSet->get("m", m); + dataSet->get("planar", planar); + dataSet->get("singleSource", singleSource); + dataSet->get("longEdges", longEdges); + } + + ogdf::randomHierarchy(G, n, m, planar, singleSource, longEdges); + return true; + } +}; + +PLUGIN(OGDFRandomHierarchy) diff --git a/plugins/import/OGDF/OGDFRandomRegularGraph.cpp b/plugins/import/OGDF/OGDFRandomRegularGraph.cpp new file mode 100644 index 0000000000..b163aa7ed0 --- /dev/null +++ b/plugins/import/OGDF/OGDFRandomRegularGraph.cpp @@ -0,0 +1,60 @@ +/** + * + * Copyright (C) 2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // n + "the number of nodes", + // d + "the degree of each node", +}; + +//================================================================================= + +class OGDFRandomRegularGraph : public OGDFImportBase { +public: + PLUGININFORMATION("Random Regular Graph (OGDF)", "Antoine Lambert", "06/2024", + "Creates a random regular graph", "1.0", "OGDF") + + OGDFRandomRegularGraph(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter("n", paramHelp[0].data(), "1000"); + addInParameter("d", paramHelp[1].data(), "4"); + } + + bool importOGDFGraph() override { + int n = 1000; + int d = 4; + + if (dataSet != nullptr) { + dataSet->get("n", n); + dataSet->get("d", d); + } + + if ((n * d) % 2 == 1) { + if (pluginProgress) { + pluginProgress->setError("(n * d) must be even"); + } + return false; + } + + ogdf::randomRegularGraph(G, n, d); + return true; + } +}; + +PLUGIN(OGDFRandomRegularGraph) diff --git a/plugins/import/OGDF/OGDFRandomSimpleGraph.cpp b/plugins/import/OGDF/OGDFRandomSimpleGraph.cpp new file mode 100644 index 0000000000..0e0f5a3489 --- /dev/null +++ b/plugins/import/OGDF/OGDFRandomSimpleGraph.cpp @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // n + "the number of nodes", + // m + "the mumber of edges", +}; + +//================================================================================= + +class OGDFRandomSimpleGraph : public OGDFImportBase { +public: + PLUGININFORMATION("Random Simple Graph (OGDF)", "Antoine Lambert", "06/2024", + "Creates a random simple graph", "1.0", "OGDF") + + OGDFRandomSimpleGraph(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter("n", paramHelp[0].data(), "500"); + addInParameter("m", paramHelp[1].data(), "1500"); + } + + bool importOGDFGraph() override { + int n = 500; + int m = 1500; + + if (dataSet != nullptr) { + dataSet->get("n", n); + dataSet->get("m", m); + } + + ogdf::randomSimpleGraph(G, n, m); + return true; + } +}; + +PLUGIN(OGDFRandomSimpleGraph) diff --git a/plugins/import/OGDF/OGDFRandomSimpleGraphByProbability.cpp b/plugins/import/OGDF/OGDFRandomSimpleGraphByProbability.cpp new file mode 100644 index 0000000000..3cbee45281 --- /dev/null +++ b/plugins/import/OGDF/OGDFRandomSimpleGraphByProbability.cpp @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // n + "the number of nodes", + // pEdge + "the probability for each edge to be added into the graph (must be in [0, 1])", +}; + +//================================================================================= + +class OGDFRandomSimpleGraphByProbability : public OGDFImportBase { +public: + PLUGININFORMATION( + "Random Simple Graph By Probability (OGDF)", "Antoine Lambert", "06/2024", + "Creates a random simple graph. Algorithm based on PreZER/LogZER from:" + "Sadegh Nobari, Xuesong Lu, Panagiotis Karras, and Stéphane Bressan. 2011. Fast random graph " + "generation. In Proceedings of the 14th International Conference on Extending Database " + "Technology (EDBT/ICDT '11),ACM, New York, NY, USA, 331-342. " + "DOI=http://dx.doi.org/10.1145/1951365.1951406", + "1.0", "OGDF") + + OGDFRandomSimpleGraphByProbability(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter("n", paramHelp[0].data(), "100"); + addInParameter("pEdge", paramHelp[1].data(), "0.25"); + } + + bool importOGDFGraph() override { + int n = 100; + double pEdge = 0.25; + + if (dataSet != nullptr) { + dataSet->get("n", n); + dataSet->get("pEdge", pEdge); + } + + if (pEdge < 0 || pEdge > 1) { + if (pluginProgress) { + pluginProgress->setError("pEdge must be in [0, 1]"); + } + return false; + } + + ogdf::randomSimpleGraphByProbability(G, n, pEdge); + return true; + } +}; + +PLUGIN(OGDFRandomSimpleGraphByProbability) diff --git a/plugins/import/OGDF/OGDFRegularLatticeGraph.cpp b/plugins/import/OGDF/OGDFRegularLatticeGraph.cpp new file mode 100644 index 0000000000..9adde4cb11 --- /dev/null +++ b/plugins/import/OGDF/OGDFRegularLatticeGraph.cpp @@ -0,0 +1,69 @@ +/** + * + * Copyright (C) 2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // n + "the number of nodes in the graph, must be at least 4", + + // k + "the degree of each node, must be an even number between 0 and n-2", +}; + +//================================================================================= + +class OGDFRegularLatticeGraph : public OGDFImportBase { +public: + PLUGININFORMATION("Regular Lattice Graph (OGDF)", "Antoine Lambert", "03/2024", + "Generates a cycle on n sequential nodes, where any two nodes whose" + " distance is at most k / 2 are connected by an additional edge.", + "1.0", "OGDF") + + OGDFRegularLatticeGraph(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter("n", paramHelp[0].data(), "50"); + addInParameter("k", paramHelp[1].data(), "6"); + } + + bool importOGDFGraph() override { + int n = 50; + int k = 6; + if (dataSet != nullptr) { + dataSet->get("n", n); + dataSet->get("k", k); + } + + if (n < 4) { + if (pluginProgress) { + pluginProgress->setError("n must be at least 4"); + } + return false; + } + if (k < 0 || k > n - 2 || k % 2 == 1) { + if (pluginProgress) { + pluginProgress->setError("k must be an even number between 0 and " + to_string(k)); + } + return false; + } + ogdf::regularLatticeGraph(G, n, k); + return true; + } + +private: +}; + +PLUGIN(OGDFRegularLatticeGraph) diff --git a/plugins/import/OGDF/OGDFRegularTree.cpp b/plugins/import/OGDF/OGDFRegularTree.cpp new file mode 100644 index 0000000000..677ddf417d --- /dev/null +++ b/plugins/import/OGDF/OGDFRegularTree.cpp @@ -0,0 +1,56 @@ +/** + * + * Copyright (C) 2024 The Talipot developers + * + * Talipot is a fork of Tulip, created by David Auber + * and the Tulip development Team from LaBRI, University of Bordeaux + * + * See the AUTHORS file at the top-level directory of this distribution + * License: GNU General Public License version 3, or any later version + * See top-level LICENSE file for more information + * + */ + +#include + +#include "OGDFImportBase.h" + +using namespace std; + +static constexpr string_view paramHelp[] = { + // n + "the number of nodes of the tree", + + // children + "the number of children per node, if number of nodes does not allow a regular node, the last " + "node will have fewer children", +}; + +//================================================================================= + +class OGDFRegularTree : public OGDFImportBase { +public: + PLUGININFORMATION("Regular Tree (OGDF)", "Antoine Lambert", "03/2024", + "Generates a regular tree where each node has the same number of children.", + "1.0", "OGDF") + + OGDFRegularTree(tlp::PluginContext *context) : OGDFImportBase(context) { + addInParameter("n", paramHelp[0].data(), "106"); + addInParameter("children", paramHelp[1].data(), "5"); + } + + bool importOGDFGraph() override { + int n = 106; + int children = 5; + if (dataSet != nullptr) { + dataSet->get("n", n); + dataSet->get("children", children); + } + ogdf::regularTree(G, n, children); + return true; + } + +private: +}; + +PLUGIN(OGDFRegularTree)