Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1a3e15b
initial commit
shawnkchan Nov 24, 2025
5abe26f
feat: add header file for order_graph_validator
shawnkchan Nov 24, 2025
7ddb89c
feat: add unit tests for order_graph_validator
shawnkchan Nov 24, 2025
803a323
fix: use vda5050_types
shawnkchan Nov 24, 2025
12fd3a1
fix: use vda5050_types in tests
shawnkchan Nov 24, 2025
cae3c3b
chore: add package and tests to cmake
shawnkchan Nov 24, 2025
becce38
fix: fix linting errors
shawnkchan Nov 24, 2025
2e9ca5b
refactor: place order_graph_validator in order directort
shawnkchan Nov 28, 2025
ef4bccc
refactor: place order_graph_validator in client directory
shawnkchan Nov 28, 2025
135c0c3
refactor: move order_graph_manager into client/order directory
shawnkchan Nov 28, 2025
6179f8c
refactor: move order_graph_validator into vda5050_core::client::order…
shawnkchan Nov 28, 2025
0c8a8f0
refactor: update order_graph_validator to use VDA5050 logging macros …
shawnkchan Nov 28, 2025
a771210
feat: crete validation_result struct for more detailed error reporting
shawnkchan Nov 28, 2025
6061e79
fix: reimplement is_in_traversal_order function
shawnkchan Nov 28, 2025
acb2a96
refactor: update tests according to new order_graph_validator
shawnkchan Nov 28, 2025
2d69c21
feat: add equality and inequality operators for testing purposes
shawnkchan Nov 28, 2025
5647d38
chore: update CMakeLists
shawnkchan Nov 28, 2025
77aee79
style: apply clang-format
shawnkchan Nov 30, 2025
b8ac8d5
style: apply clang-format to order_graph_validator test
shawnkchan Nov 30, 2025
29e1e43
chore: disable if else style check for cpplint during testing
shawnkchan Dec 1, 2025
fd04ac0
style: add space before comment
shawnkchan Dec 1, 2025
58be0ae
refactor: remove equality and inequality checks as tests do not requi…
shawnkchan Dec 1, 2025
d5a6b38
test: make test cases more detailed
shawnkchan Dec 1, 2025
42d6a64
refactor: change Error Level of graph validation errors to WARNING in…
shawnkchan Dec 1, 2025
ce90e6f
feat: add function checking for valid sequenceIds
shawnkchan Dec 3, 2025
fb2f40d
feat: create graph_element struct for easier management of nodes and …
shawnkchan Dec 3, 2025
553ecdc
refactor: refactor order_graph_manager to do additional checks for gr…
shawnkchan Dec 3, 2025
bce7af2
chore: remove line to find gtest package in CMakeLists
shawnkchan Dec 4, 2025
5cc4b70
chore: make classes explicit
shawnkchan Dec 4, 2025
04c011f
chore: move fmt header to top of file
shawnkchan Dec 4, 2025
a451f90
chore: temporary change to use "" instead of <> for vda5050_types to …
shawnkchan Dec 5, 2025
8eb611c
fix: change include back to use <> for vda5050_types
shawnkchan Dec 5, 2025
e009b26
feat: update test cases
shawnkchan Dec 5, 2025
8e5f90f
chore: update description of in_traversal_order()
shawnkchan Dec 5, 2025
c7faa4b
refactor: revised graph validator and test cases
Johnarman1398 Dec 13, 2025
1b3d073
chore: lint
Johnarman1398 Dec 13, 2025
ee9200c
chore: lint
Johnarman1398 Dec 13, 2025
1f87a73
chore: merged changes from develop
Johnarman1398 Dec 13, 2025
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
29 changes: 28 additions & 1 deletion vda5050_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -54,6 +67,7 @@ install(
TARGETS
mqtt_client
logger
order_graph_validator
vda5050_core
EXPORT export_vda5050_core
LIBRARY DESTINATION lib
Expand All @@ -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)
Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to bring in ament_cmake_gtest separately. The previous ament_cmake_gmock most probably does that

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()
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 {

/// \brief Utility class with functions to perform validity checks on the graph contained in a VDA5050 Order message
class OrderGraphValidator
{
public:
OrderGraphValidator();

/// \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);

private:
// std::vector<vda5050_types::Node>& nodes;
// std::vector<vda5050_types::Edge>& edges;

std::string start_node_id;
std::string end_node_id;

/// \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_
3 changes: 3 additions & 0 deletions vda5050_core/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@

<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>vda5050_types</build_depend>

<test_depend>ament_cmake_cppcheck</test_depend>
<test_depend>ament_cmake_cpplint</test_depend>
<test_depend>ament_cmake_clang_format</test_depend>
<test_depend>ament_cmake_copyright</test_depend>
<test_depend>ament_cmake_gmock</test_depend>
<test_depend>vda5050_types</test_depend>

<export>
<build_type>ament_cmake</build_type>
Expand Down
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.
/// 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.";
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
Loading