Skip to content

Commit

Permalink
plugins/import: Wrap OGDF graph generators (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
anlambert committed Jun 5, 2024
1 parent 3829e39 commit f6fb34e
Show file tree
Hide file tree
Showing 19 changed files with 912 additions and 2 deletions.
5 changes: 3 additions & 2 deletions library/talipot-ogdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions library/talipot-ogdf/include/talipot/OGDFUtils.h
Original file line number Diff line number Diff line change
@@ -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 <ogdf/basic/Graph.h>
#include <talipot/Graph.h>

TLP_OGDF_SCOPE tlp::Graph *convertOGDFGraphToTalipotGraph(ogdf::Graph &graph,
tlp::Graph *tlpGraph = nullptr);

template <typename T>
ogdf::Array<T> vectorToOGDFArray(const std::vector<T> &v) {
auto a = ogdf::Array<T>(v.size());
std::copy(v.begin(), v.end(), a.begin());
return a;
}

#endif // TALIPOT_OGDF_UTILS_H
38 changes: 38 additions & 0 deletions library/talipot-ogdf/src/OGDFUtils.cpp
Original file line number Diff line number Diff line change
@@ -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 <unordered_map>

#include <talipot/OGDFUtils.h>

using namespace std;

tlp::Graph *convertOGDFGraphToTalipotGraph(ogdf::Graph &graph, tlp::Graph *tlpGraph) {
if (!tlpGraph) {
tlpGraph = tlp::newGraph();
} else {
tlpGraph->clear();
}

unordered_map<ogdf::node, tlp::node> 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;
}
1 change: 1 addition & 0 deletions plugins/import/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
31 changes: 31 additions & 0 deletions plugins/import/OGDF/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
56 changes: 56 additions & 0 deletions plugins/import/OGDF/OGDFCirculantGraph.cpp
Original file line number Diff line number Diff line change
@@ -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 <ogdf/basic/graph_generators/deterministic.h>

#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<int>("n", paramHelp[0].data(), "100");
addInParameter<vector<int>>("jumps", paramHelp[1].data(), "(10, 20, 30, 40)");
}

bool importOGDFGraph() override {
int n = 100;
vector<int> 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)
46 changes: 46 additions & 0 deletions plugins/import/OGDF/OGDFCompleteKPartiteGraph.cpp
Original file line number Diff line number Diff line change
@@ -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 <ogdf/basic/graph_generators/deterministic.h>

#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<vector<int>>("signature", paramHelp[0].data(), "(10, 20, 30, 40)");
}

bool importOGDFGraph() override {
vector<int> signature = {10, 20, 30, 40};
if (dataSet != nullptr) {
dataSet->get("signature", signature);
}
ogdf::completeKPartiteGraph(G, vectorToOGDFArray(signature));
return true;
}
};

PLUGIN(OGDFCompleteKPartiteGraph)
55 changes: 55 additions & 0 deletions plugins/import/OGDF/OGDFGlobeGraph.cpp
Original file line number Diff line number Diff line change
@@ -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 <ogdf/basic/graph_generators/deterministic.h>

#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<int>("meridians", paramHelp[0].data(), "30");
addInParameter<int>("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)
34 changes: 34 additions & 0 deletions plugins/import/OGDF/OGDFImportBase.h
Original file line number Diff line number Diff line change
@@ -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 <talipot/ImportModule.h>

#include <talipot/OGDFUtils.h>

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;
};
58 changes: 58 additions & 0 deletions plugins/import/OGDF/OGDFPetersenGraph.cpp
Original file line number Diff line number Diff line change
@@ -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 <ogdf/basic/graph_generators/deterministic.h>

#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<int>("n", paramHelp[0].data(), "5");
addInParameter<int>("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)
Loading

0 comments on commit f6fb34e

Please sign in to comment.