Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/boost

This file was deleted.

8 changes: 6 additions & 2 deletions src/translator/graph_planar/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ANTLR(GraphPlanar.g4)

find_package(Boost COMPONENTS graph)

add_library(translator_graph_planar STATIC
GraphPlanarLexer.cpp
GraphPlanarParser.cpp
Expand All @@ -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)
14 changes: 7 additions & 7 deletions src/translator/sequence/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -22,25 +22,25 @@ 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)
return false;
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;
bool work_to_do = true;
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;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/translator/sequence/Graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/translator/sequence/Sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down