-
Notifications
You must be signed in to change notification settings - Fork 4
refactor(orderGraphValidator): Isolate OrderGraphValidator and use vda5050_types
#13
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
Open
shawnkchan
wants to merge
38
commits into
develop
Choose a base branch
from
feat/dev-orderGraphValidator
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+928
−2
Open
Changes from 7 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
1a3e15b
initial commit
shawnkchan 5abe26f
feat: add header file for order_graph_validator
shawnkchan 7ddb89c
feat: add unit tests for order_graph_validator
shawnkchan 803a323
fix: use vda5050_types
shawnkchan 12fd3a1
fix: use vda5050_types in tests
shawnkchan cae3c3b
chore: add package and tests to cmake
shawnkchan becce38
fix: fix linting errors
shawnkchan 2e9ca5b
refactor: place order_graph_validator in order directort
shawnkchan ef4bccc
refactor: place order_graph_validator in client directory
shawnkchan 135c0c3
refactor: move order_graph_manager into client/order directory
shawnkchan 6179f8c
refactor: move order_graph_validator into vda5050_core::client::order…
shawnkchan 0c8a8f0
refactor: update order_graph_validator to use VDA5050 logging macros …
shawnkchan a771210
feat: crete validation_result struct for more detailed error reporting
shawnkchan 6061e79
fix: reimplement is_in_traversal_order function
shawnkchan acb2a96
refactor: update tests according to new order_graph_validator
shawnkchan 2d69c21
feat: add equality and inequality operators for testing purposes
shawnkchan 5647d38
chore: update CMakeLists
shawnkchan 77aee79
style: apply clang-format
shawnkchan b8ac8d5
style: apply clang-format to order_graph_validator test
shawnkchan 29e1e43
chore: disable if else style check for cpplint during testing
shawnkchan fd04ac0
style: add space before comment
shawnkchan 58be0ae
refactor: remove equality and inequality checks as tests do not requi…
shawnkchan d5a6b38
test: make test cases more detailed
shawnkchan 42d6a64
refactor: change Error Level of graph validation errors to WARNING in…
shawnkchan ce90e6f
feat: add function checking for valid sequenceIds
shawnkchan fb2f40d
feat: create graph_element struct for easier management of nodes and …
shawnkchan 553ecdc
refactor: refactor order_graph_manager to do additional checks for gr…
shawnkchan bce7af2
chore: remove line to find gtest package in CMakeLists
shawnkchan 5cc4b70
chore: make classes explicit
shawnkchan 04c011f
chore: move fmt header to top of file
shawnkchan a451f90
chore: temporary change to use "" instead of <> for vda5050_types to …
shawnkchan 8eb611c
fix: change include back to use <> for vda5050_types
shawnkchan e009b26
feat: update test cases
shawnkchan 8e5f90f
chore: update description of in_traversal_order()
shawnkchan c7faa4b
refactor: revised graph validator and test cases
Johnarman1398 1b3d073
chore: lint
Johnarman1398 ee9200c
chore: lint
Johnarman1398 1f87a73
chore: merged changes from develop
Johnarman1398 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ endif() | |
| find_package(ament_cmake REQUIRED) | ||
| find_package(PahoMqttCpp REQUIRED) | ||
| find_package(fmt REQUIRED) | ||
| find_package(vda5050_types REQUIRED) | ||
|
|
||
| include(GNUInstallDirs) | ||
|
|
||
|
|
@@ -33,11 +34,23 @@ target_include_directories(logger | |
| $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
| ) | ||
|
|
||
| add_library(order_graph_validator src/vda5050_core/order_graph_validator/order_graph_validator.cpp) | ||
| target_link_libraries(order_graph_validator | ||
| PRIVATE | ||
| vda5050_types::vda5050_types | ||
| ) | ||
| target_include_directories(order_graph_validator | ||
| PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | ||
| ) | ||
|
|
||
| add_library(vda5050_core INTERFACE) | ||
| target_link_libraries(vda5050_core | ||
| INTERFACE | ||
| mqtt_client | ||
| logger | ||
| order_graph_validator | ||
| ) | ||
| target_include_directories(vda5050_core | ||
| INTERFACE | ||
|
|
@@ -54,6 +67,7 @@ install( | |
| TARGETS | ||
| mqtt_client | ||
| logger | ||
| order_graph_validator | ||
| vda5050_core | ||
| EXPORT export_vda5050_core | ||
| LIBRARY DESTINATION lib | ||
|
|
@@ -69,7 +83,7 @@ install( | |
| ) | ||
|
|
||
| ament_export_targets(export_vda5050_core HAS_LIBRARY_TARGET) | ||
| ament_export_dependencies(PahoMqttCpp fmt) | ||
| ament_export_dependencies(PahoMqttCpp fmt vda5050_types) | ||
|
|
||
| if(BUILD_TESTING) | ||
| find_package(ament_cmake_cppcheck REQUIRED) | ||
|
|
@@ -94,6 +108,19 @@ if(BUILD_TESTING) | |
| test/integration/mqtt_client/test_paho_mqtt_client.cpp | ||
| ) | ||
| target_link_libraries(test_mqtt_client mqtt_client logger) | ||
|
|
||
| find_package(ament_cmake_gtest REQUIRED) | ||
|
||
| ament_add_gtest(order_graph_validator_test | ||
| test/unit/order_graph_validator/test_order_graph_validator.cpp | ||
| src/vda5050_core/order_graph_validator/order_graph_validator.cpp | ||
| ) | ||
| target_link_libraries(order_graph_validator_test | ||
| vda5050_types::vda5050_types | ||
| order_graph_validator | ||
| ) | ||
| target_include_directories(order_graph_validator_test | ||
| PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) | ||
| endif() | ||
|
|
||
| ament_package() | ||
65 changes: 65 additions & 0 deletions
65
vda5050_core/include/vda5050_core/order_graph_validator/order_graph_validator.hpp
This file contains hidden or 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,65 @@ | ||
| /** | ||
| * Copyright (C) 2025 ROS-Industrial Consortium Asia Pacific | ||
| * Advanced Remanufacturing and Technology Centre | ||
| * A*STAR Research Entities (Co. Registration No. 199702110H) | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #ifndef VDA5050_CORE__ORDER_EXECUTION__ORDER_GRAPH_VALIDATOR_HPP_ | ||
| #define VDA5050_CORE__ORDER_EXECUTION__ORDER_GRAPH_VALIDATOR_HPP_ | ||
|
|
||
| #include <vector> | ||
|
|
||
| #include "vda5050_types/edge.hpp" | ||
| #include "vda5050_types/node.hpp" | ||
|
|
||
| namespace vda5050_core { | ||
| namespace order_graph_validator { | ||
shawnkchan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// \brief Utility class with functions to perform validity checks on the graph contained in a VDA5050 Order message | ||
shawnkchan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| class OrderGraphValidator | ||
| { | ||
| public: | ||
| OrderGraphValidator(); | ||
shawnkchan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// \brief Checks that the nodes and edges in a VDA5050 Order form a valid graph according to the VDA5050 specification sheet. | ||
| /// | ||
| /// \return True if nodes and edges create a valid graph, false otherwise | ||
| bool is_valid_graph( | ||
| std::vector<vda5050_types::Node>& nodes, | ||
| std::vector<vda5050_types::Edge>& edges); | ||
shawnkchan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private: | ||
| // std::vector<vda5050_types::Node>& nodes; | ||
| // std::vector<vda5050_types::Edge>& edges; | ||
|
|
||
| std::string start_node_id; | ||
| std::string end_node_id; | ||
shawnkchan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// \brief Checks that the nodes and edges contained in a VDA5050 Order are arranged according to their sequenceId | ||
| /// | ||
| /// \return True if nodes and edges are arranged according to their sequenceId, false otherwise | ||
| bool is_in_traversal_order( | ||
| std::vector<vda5050_types::Node>& nodes, | ||
| std::vector<vda5050_types::Edge>& edges); | ||
|
|
||
| /// \brief Checks that startNodeId and endNodeId of all edges in a VDA5050 Order match with its the start and end nodeIds | ||
| /// | ||
| /// \return True if all edges' startNodeId and endNodId match, false otherwise | ||
| bool is_valid_edges(std::vector<vda5050_types::Edge>& edges); | ||
| }; | ||
|
|
||
| } // namespace order_graph_validator | ||
| } // namespace vda5050_core | ||
| #endif // VDA5050_CORE__ORDER_EXECUTION__ORDER_GRAPH_VALIDATOR_HPP_ | ||
This file contains hidden or 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
152 changes: 152 additions & 0 deletions
152
vda5050_core/src/vda5050_core/order_graph_validator/order_graph_validator.cpp
This file contains hidden or 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,152 @@ | ||
| /** | ||
| * Copyright (C) 2025 ROS-Industrial Consortium Asia Pacific | ||
| * Advanced Remanufacturing and Technology Centre | ||
| * A*STAR Research Entities (Co. Registration No. 199702110H) | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include <iostream> | ||
| #include <queue> | ||
| #include <vector> | ||
|
|
||
| #include "vda5050_core/order_graph_validator/order_graph_validator.hpp" | ||
| #include "vda5050_types/edge.hpp" | ||
| #include "vda5050_types/node.hpp" | ||
|
|
||
| namespace vda5050_core { | ||
| namespace order_graph_validator { | ||
|
|
||
| /// TODO (shawnkchan) maybe this should take in an Order object instead so that we can specify which orderId is errornous if something goes wrong | ||
| /// TODO Refactor this to take in an Order object instead, will make validation logic easier | ||
| OrderGraphValidator::OrderGraphValidator() {} | ||
|
|
||
| bool OrderGraphValidator::is_valid_graph( | ||
| std::vector<vda5050_types::Node>& nodes, | ||
| std::vector<vda5050_types::Edge>& edges) | ||
| { | ||
| /// TODO: (shawnkchan) Check if it is even possible to send an Order with zero nodes (should Order class just protect against this?). If not possible, get rid of this. | ||
shawnkchan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// Does not seem to be any guarantee that this list is not empty, so will leave this check here. | ||
| if (nodes.empty()) | ||
| { | ||
| std::cerr << "Graph Validation Error: nodes vector is empty."; | ||
shawnkchan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return false; | ||
| } | ||
| else | ||
| { | ||
| start_node_id = nodes.front().node_id; | ||
| end_node_id = nodes.back().node_id; | ||
| } | ||
|
|
||
| if (nodes.size() == 1) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| /// check for validity based on vector sizes | ||
| if (!(nodes.size() - 1 == edges.size())) | ||
| { | ||
| std::cerr << "Graph Validation Error: Difference in number of nodes and " | ||
| "edges is not 1." | ||
| << '\n'; | ||
| return false; | ||
| } | ||
|
|
||
| if (!is_in_traversal_order(nodes, edges)) | ||
| { | ||
| std::cerr << "Nodes and edges are not in traversal order." << '\n'; | ||
| return false; | ||
| } | ||
|
|
||
| if (!is_valid_edges(edges)) | ||
| { | ||
| std::cerr << "Graph Validation Error: startNodeId and endNodeId of an edge " | ||
| "does not match the startNodeId and endNodeId of this order." | ||
| << '\n'; | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| bool OrderGraphValidator::is_in_traversal_order( | ||
| std::vector<vda5050_types::Node>& nodes, | ||
| std::vector<vda5050_types::Edge>& edges) | ||
| { | ||
| std::queue<vda5050_types::Node> node_queue; | ||
| std::queue<vda5050_types::Edge> edge_queue; | ||
|
|
||
| for (vda5050_types::Node n : nodes) | ||
| { | ||
| node_queue.push(n); | ||
| } | ||
|
|
||
| for (vda5050_types::Edge e : edges) | ||
| { | ||
| edge_queue.push(e); | ||
| } | ||
|
|
||
| vda5050_types::Node first_node{node_queue.front()}; | ||
| node_queue.pop(); | ||
| uint32_t latest_sequence_id{first_node.sequence_id}; | ||
| while (node_queue.size() != 0 && edge_queue.size() != 0) | ||
| { | ||
| if (node_queue.size() > edge_queue.size()) | ||
| { | ||
| vda5050_types::Node n{node_queue.front()}; | ||
| if (latest_sequence_id == n.sequence_id - 1) | ||
| { | ||
| node_queue.pop(); | ||
| latest_sequence_id = n.sequence_id; | ||
| } | ||
|
|
||
| else | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /// if there are an equal number of edges and nodes, then check the next edge in the queue | ||
| else if (node_queue.size() == edge_queue.size()) | ||
| { | ||
| vda5050_types::Edge e{edge_queue.front()}; | ||
| if (latest_sequence_id == e.sequence_id - 1) | ||
| { | ||
| edge_queue.pop(); | ||
| latest_sequence_id = e.sequence_id; | ||
| } | ||
|
|
||
| else | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| bool OrderGraphValidator::is_valid_edges( | ||
| std::vector<vda5050_types::Edge>& edges) | ||
| { | ||
| for (vda5050_types::Edge e : edges) | ||
| { | ||
| if (e.start_node_id != start_node_id && e.end_node_id != end_node_id) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| } // namespace order_graph_validator | ||
| } // namespace vda5050_core | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.