refactor: change sequence/graph vertex name to edge (#31)

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
David
2022-02-13 17:33:55 +08:00
committed by GitHub
parent 0d4a89e513
commit fffa39bbbe
5 changed files with 19 additions and 16 deletions
-1
View File
@@ -1 +0,0 @@
/usr/include/boost
+6 -2
View File
@@ -1,5 +1,7 @@
ANTLR(GraphPlanar.g4)
find_package(Boost COMPONENTS graph)
add_library(translator_graph_planar STATIC
GraphPlanarLexer.cpp
GraphPlanarParser.cpp
@@ -10,6 +12,8 @@ else()
target_compile_options(translator_graph_planar PRIVATE "-Wno-attributes")
endif()
target_link_libraries(translator_graph_planar PRIVATE diagon_base)
target_link_libraries(translator_graph_planar PRIVATE antlr4_static)
target_link_libraries(translator_graph_planar
PRIVATE diagon_base
PRIVATE antlr4_static
PRIVATE Boost::graph)
target_set_common(translator_graph_planar)
+7 -7
View File
@@ -10,8 +10,8 @@
namespace graph {
Vertex::Vertex(const Node& from, const Node& to) : from(from), to(to) {}
Vertex::Vertex(const Message& message)
Edge::Edge(const Node& from, const Node& to) : from(from), to(to) {}
Edge::Edge(const Message& message)
: from({message.from, message.id}), to({message.to, message.id}) {}
bool operator<(const Node& a, const Node& b) {
@@ -22,7 +22,7 @@ bool operator<(const Node& a, const Node& b) {
return a.message < b.message;
}
bool operator<(const Vertex& a, const Vertex& b) {
bool operator<(const Edge& a, const Edge& b) {
if (a.from < b.from)
return true;
if (b.from < a.from)
@@ -30,7 +30,7 @@ bool operator<(const Vertex& a, const Vertex& b) {
return a.to < b.to;
}
using Graph = std::set<Vertex>;
using Graph = std::set<Edge>;
std::vector<Node> FindTopologicalOrder(const Graph& graph) {
std::map<Node, int> weight;
@@ -38,9 +38,9 @@ std::vector<Node> FindTopologicalOrder(const Graph& graph) {
int iteration = 0;
while (work_to_do) {
work_to_do = false;
for (const auto& vertex : graph) {
if (weight[vertex.to] <= weight[vertex.from]) {
weight[vertex.to] = weight[vertex.from] + 1;
for (const auto& edge : graph) {
if (weight[edge.to] <= weight[edge.from]) {
weight[edge.to] = weight[edge.from] + 1;
work_to_do = true;
}
}
+5 -5
View File
@@ -19,18 +19,18 @@ struct Node {
int message;
};
struct Vertex {
struct Edge {
Node from;
Node to;
Vertex(const Node& from, const Node& to);
Vertex(const Message& message);
Edge(const Node& from, const Node& to);
Edge(const Message& message);
};
using Graph = std::set<Vertex>;
using Graph = std::set<Edge>;
bool operator<(const Node& a, const Node& b);
bool operator<(const Vertex& a, const Vertex& b);
bool operator<(const Edge& a, const Edge& b);
std::vector<Node> FindTopologicalOrder(const Graph& graph);
} // namespace graph
+1 -1
View File
@@ -591,7 +591,7 @@ void Sequence::LayoutComputeMessagesPositions() {
if (cut.count(message.id)) {
graph::Node from = {actor_index[message.from], message.id};
graph::Node to = {actor_index[message.to], message.id};
graph.insert(graph::Vertex(from, to));
graph.insert(graph::Edge(from, to));
}
}
std::set<int> started_message;