forked from Tulip-Dev/tulip
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins/import: Wrap OGDF graph generators (WIP)
- Loading branch information
Showing
12 changed files
with
489 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,23 @@ | ||
/** | ||
* | ||
* 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 | ||
* | ||
*/ | ||
|
||
#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); | ||
|
||
#endif // TALIPOT_OGDF_UTILS_H |
This file contains 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,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; | ||
} |
This file contains 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 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,21 @@ | ||
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) | ||
|
||
DISABLE_COMPILER_WARNINGS() | ||
|
||
TALIPOT_ADD_PLUGIN( | ||
NAME | ||
OGDFGraphGenerators | ||
SRCS | ||
${PLUGINS_SRCS} | ||
LINKS | ||
${LibTalipotCoreName} | ||
${LibTalipotOGDFName} | ||
${OGDF_LIBRARY} | ||
INSTALL_DIR | ||
${TalipotPluginsInstallDir}) |
This file contains 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,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/2023", | ||
"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) |
This file contains 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,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; | ||
}; |
This file contains 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,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) |
This file contains 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,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 <ogdf/basic/graph_generators/randomGeographicalThresholdGraph.h> | ||
|
||
#include <random> | ||
|
||
#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<int>("n", paramHelp[0].data(), "100"); | ||
addInParameter<double>("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<int> weights = ogdf::Array<int>(n); | ||
for (int &w : weights) { | ||
w = tlp::randomNumber(n); | ||
} | ||
uniform_int_distribution<int> dist(0, n); | ||
ogdf::randomGeographicalThresholdGraph(G, weights, dist, 0.7); | ||
return true; | ||
} | ||
}; | ||
|
||
PLUGIN(OGDFRandomGeographicalGraph) |
This file contains 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,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 <ogdf/basic/graph_generators/randomHierarchy.h> | ||
|
||
#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<int>("n", paramHelp[0].data(), "1000"); | ||
addInParameter<int>("m", paramHelp[1].data(), "2000"); | ||
addInParameter<bool>("planar", paramHelp[2].data(), "true"); | ||
addInParameter<bool>("singleSource", paramHelp[3].data(), "true"); | ||
addInParameter<bool>("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) |
Oops, something went wrong.