From f37de58c57a64853cb6d9e12fc8de4d37f1991ea Mon Sep 17 00:00:00 2001 From: surynek Date: Tue, 18 Feb 2025 16:38:48 +0100 Subject: [PATCH] Revisited all test modules for sequential printing library. --- src/libseqarrange/CMakeLists.txt | 3 +- src/libseqarrange/src/seq_sequential.cpp | 4 +- src/libseqarrange/test/seq_test_interface.cpp | 582 ++++++++--- src/libseqarrange/test/seq_test_interface.hpp | 2 +- src/libseqarrange/test/seq_test_polygon.cpp | 130 +-- src/libseqarrange/test/seq_test_polygon.hpp | 2 +- .../test/seq_test_preprocess.cpp | 363 ++++--- .../test/seq_test_preprocess.hpp | 2 +- .../test/seq_test_sequential.cpp | 932 ++++++++++++------ .../test/seq_test_sequential.hpp | 2 +- 10 files changed, 1336 insertions(+), 686 deletions(-) diff --git a/src/libseqarrange/CMakeLists.txt b/src/libseqarrange/CMakeLists.txt index 9c7416f107..2e14ceca48 100644 --- a/src/libseqarrange/CMakeLists.txt +++ b/src/libseqarrange/CMakeLists.txt @@ -18,8 +18,7 @@ target_link_libraries(sequential_decimator PRIVATE libseqarrange) if (SLIC3R_BUILD_TESTS) find_package(Catch2 3.8 REQUIRED) - add_executable(libseqarrange_tests test/prusaparts.cpp test/seq_test_polygon.cpp) -# test/seq_test_sequential.cpp test/seq_test_preprocess.cpp test/seq_test_interface.cpp + add_executable(libseqarrange_tests test/prusaparts.cpp test/seq_test_polygon.cpp test/seq_test_sequential.cpp test/seq_test_preprocess.cpp test/seq_test_interface.cpp) target_include_directories(libseqarrange_tests PRIVATE src ) target_link_libraries(libseqarrange_tests PRIVATE Catch2::Catch2WithMain libseqarrange) diff --git a/src/libseqarrange/src/seq_sequential.cpp b/src/libseqarrange/src/seq_sequential.cpp index 7a104378b6..5826d857c8 100644 --- a/src/libseqarrange/src/seq_sequential.cpp +++ b/src/libseqarrange/src/seq_sequential.cpp @@ -11006,12 +11006,12 @@ bool optimize_SubglobalSequentialPolygonNonoverlappingBinaryCentered(const Solve if (!optimized) { if (curr_polygon <= 0) - { + { return false; } else { - if (curr_polygon + solver_configuration.object_group_size < polygons.size()) + if (curr_polygon + solver_configuration.object_group_size < polygons.size()) { curr_polygon += solver_configuration.object_group_size; diff --git a/src/libseqarrange/test/seq_test_interface.cpp b/src/libseqarrange/test/seq_test_interface.cpp index 15d9eff2de..3719ff5703 100644 --- a/src/libseqarrange/test/seq_test_interface.cpp +++ b/src/libseqarrange/test/seq_test_interface.cpp @@ -1,6 +1,6 @@ /*================================================================*/ /* - * Author: Pavel Surynek, 2023 - 2024 + * Author: Pavel Surynek, 2023 - 2025 * Company: Prusa Research * * File: seq_test_interface.cpp @@ -40,8 +40,8 @@ using namespace Sequential; /*----------------------------------------------------------------*/ -const int SEQ_PRUSA_MK3S_X_SIZE = 2500; -const int SEQ_PRUSA_MK3S_Y_SIZE = 2100; +const coord_t SEQ_PRUSA_MK3S_X_SIZE = 250000000; +const coord_t SEQ_PRUSA_MK3S_Y_SIZE = 210000000; /*----------------------------------------------------------------*/ @@ -502,25 +502,43 @@ void save_import_data(const std::string &filename, /*----------------------------------------------------------------*/ TEST_CASE("Interface test 1", "[Sequential Arrangement Interface]") -{ +//void interface_test_1(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing interface 1 ...\n"); + INFO("Testing interface 1 ..."); + #ifdef DEBUG start = clock(); + #endif SolverConfiguration solver_configuration; solver_configuration.decimation_precision = SEQ_DECIMATION_PRECISION_HIGH; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); - - printf("Loading objects ...\n"); + #ifdef DEBUG + { + printf("Loading objects ...\n"); + } + #endif + std::vector objects_to_print = load_exported_data_from_text(arrange_data_export_text); REQUIRE(objects_to_print.size() > 0); - printf("Loading objects ... finished\n"); + + #ifdef DEBUG + { + printf("Loading objects ... finished\n"); + } + #endif std::vector scheduled_plates; - printf("Scheduling objects for sequential print ...\n"); + #ifdef DEBUG + { + printf("Scheduling objects for sequential print ...\n"); + } + #endif int result = schedule_ObjectsForSequentialPrint(solver_configuration, objects_to_print, @@ -529,19 +547,35 @@ TEST_CASE("Interface test 1", "[Sequential Arrangement Interface]") REQUIRE(result == 0); if (result == 0) { - printf("Object scheduling for sequential print SUCCESSFUL !\n"); + #ifdef DEBUG + { + printf("Object scheduling for sequential print SUCCESSFUL !\n"); + } + #endif - printf("Number of plates: %ld\n", scheduled_plates.size()); + #ifdef DEBUG + { + printf("Number of plates: %ld\n", scheduled_plates.size()); + } + #endif REQUIRE(scheduled_plates.size() > 0); for (unsigned int plate = 0; plate < scheduled_plates.size(); ++plate) { - printf(" Number of objects on plate: %ld\n", scheduled_plates[plate].scheduled_objects.size()); + #ifdef DEBUG + { + printf(" Number of objects on plate: %ld\n", scheduled_plates[plate].scheduled_objects.size()); + } + #endif REQUIRE(scheduled_plates[plate].scheduled_objects.size() > 0); for (const auto& scheduled_object: scheduled_plates[plate].scheduled_objects) { - cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; + #ifdef DEBUG + { + cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; + } + #endif REQUIRE(scheduled_object.x >= solver_configuration.plate_bounding_box.min.x() * SEQ_SLICER_SCALE_FACTOR); REQUIRE(scheduled_object.x <= solver_configuration.plate_bounding_box.max.x() * SEQ_SLICER_SCALE_FACTOR); REQUIRE(scheduled_object.y >= solver_configuration.plate_bounding_box.min.y() * SEQ_SLICER_SCALE_FACTOR); @@ -551,39 +585,66 @@ TEST_CASE("Interface test 1", "[Sequential Arrangement Interface]") } else { - printf("Something went WRONG during sequential scheduling (code: %d)\n", result); + #ifdef DEBUG + { + printf("Something went WRONG during sequential scheduling (code: %d)\n", result); + } + #endif } - + + #ifdef DEBUG finish = clock(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing interface 1 ... finished\n"); + #endif + + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing interface 1 ... finished"); } TEST_CASE("Interface test 2", "[Sequential Arrangement Interface]") -{ +//void interface_test_2(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing interface 2 ...\n"); + INFO("Testing interface 2 ..."); + #ifdef DEBUG start = clock(); + #endif SolverConfiguration solver_configuration; solver_configuration.decimation_precision = SEQ_DECIMATION_PRECISION_HIGH; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); - printf("Loading objects ...\n"); + #ifdef DEBUG + { + printf("Loading objects ...\n"); + } + #endif std::vector objects_to_print = load_exported_data_from_text(arrange_data_export_text); std::vector > convex_unreachable_zones; std::vector > box_unreachable_zones; - printf("Preparing extruder unreachable zones ...\n"); + #ifdef DEBUG + { + printf("Preparing extruder unreachable zones ...\n"); + } + #endif setup_ExtruderUnreachableZones(solver_configuration, convex_unreachable_zones, box_unreachable_zones); std::vector scheduled_plates; - printf("Scheduling objects for sequential print ...\n"); + #ifdef DEBUG + { + printf("Scheduling objects for sequential print ...\n"); + } + #endif int result = schedule_ObjectsForSequentialPrint(solver_configuration, objects_to_print, @@ -594,20 +655,30 @@ TEST_CASE("Interface test 2", "[Sequential Arrangement Interface]") REQUIRE(result == 0); if (result == 0) { - printf("Object scheduling for sequential print SUCCESSFUL !\n"); - - printf("Number of plates: %ld\n", scheduled_plates.size()); + #ifdef DEBUG + { + printf("Object scheduling for sequential print SUCCESSFUL !\n"); + printf("Number of plates: %ld\n", scheduled_plates.size()); + } + #endif REQUIRE(scheduled_plates.size() > 0); for (unsigned int plate = 0; plate < scheduled_plates.size(); ++plate) { - printf(" Number of objects on plate: %ld\n", scheduled_plates[plate].scheduled_objects.size()); + #ifdef DEBUG + { + printf(" Number of objects on plate: %ld\n", scheduled_plates[plate].scheduled_objects.size()); + } + #endif REQUIRE(scheduled_plates[plate].scheduled_objects.size() > 0); for (const auto& scheduled_object: scheduled_plates[plate].scheduled_objects) { - cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; - + #ifdef DEBUG + { + cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; + } + #endif REQUIRE(scheduled_object.x >= solver_configuration.plate_bounding_box.min.x() * SEQ_SLICER_SCALE_FACTOR); REQUIRE(scheduled_object.x <= solver_configuration.plate_bounding_box.max.x() * SEQ_SLICER_SCALE_FACTOR); REQUIRE(scheduled_object.y >= solver_configuration.plate_bounding_box.min.y() * SEQ_SLICER_SCALE_FACTOR); @@ -617,119 +688,224 @@ TEST_CASE("Interface test 2", "[Sequential Arrangement Interface]") } else { - printf("Something went WRONG during sequential scheduling (code: %d)\n", result); + #ifdef DEBUG + { + printf("Something went WRONG during sequential scheduling (code: %d)\n", result); + } + #endif } - + + #ifdef DEBUG finish = clock(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing interface 2 ... finished\n"); + #endif + + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing interface 2 ... finished"); } TEST_CASE("Interface test 3", "[Sequential Arrangement Interface]") -{ +//void interface_test_3(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing interface 3 ...\n"); + INFO("Testing interface 3 ..."); + #ifdef DEBUG start = clock(); + #endif - PrinterGeometry printer_geometry; + PrinterGeometry printer_geometry = + { + { {0, 0}, {250000000, 0}, {250000000, 210000000}, {0, 210000000} }, + { 0, 3000000, 22000000}, + { 11000000, 13000000 }, + { + {0, { { {-500000, -500000}, {500000, -500000}, {500000, 500000}, {-500000, 500000} } } }, + {3000000, { { {-9000000, -17000000}, {40000000, -17000000}, {40000000, 44000000}, {-9000000, 44000000} }, + { {-36000000, -44000000}, {40000000, -44000000}, {40000000, -13000000}, {-36000000, -13000000} } } }, + {22000000, { { {-41000000, -45000000}, {16000000, -45000000}, {16000000, 22000000}, {-41000000, 22000000} }, + { {11000000, -45000000}, {39000000, -45000000}, {39000000, 45000000}, {11000000 , 45000000} } } }, + {11000000, { { {-300000000, -4000000}, {300000000, -4000000}, {300000000, -14000000}, {-300000000, -14000000} } } }, + {13000000, { { {-13000000, -84000000}, {11000000, -84000000}, {11000000, -38000000}, {-13000000, -38000000} }, + { {11000000, -300000000}, {300000000, -300000000}, {300000000, -84000000}, {11000000, -84000000} } } } + + } + }; + + /* int result = load_printer_geometry_from_text(printer_geometry_mk4_text, printer_geometry); REQUIRE(result == 0); - + if (result != 0) { - printf("Printer geometry load error.\n"); + #ifdef DEBUG + { + printf("Printer geometry load error.\n"); + } + #endif return; } + */ REQUIRE(printer_geometry.plate.points.size() == 4); - for (const auto& convex_height: printer_geometry.convex_heights) + #ifdef DEBUG { - cout << "convex_height:" << convex_height << endl; - } - - for (const auto& box_height: printer_geometry.box_heights) - { - cout << "box_height:" << box_height << endl; - } - printf("extruder slices:\n"); - REQUIRE(printer_geometry.extruder_slices.size() > 0); - - for (std::map >::const_iterator extruder_slice = printer_geometry.extruder_slices.begin(); extruder_slice != printer_geometry.extruder_slices.end(); ++extruder_slice) - { - for (const auto &polygon: extruder_slice->second) + for (const auto& convex_height: printer_geometry.convex_heights) { - printf(" polygon height: %d\n", extruder_slice->first); - - for (const auto &point: polygon.points) - { - cout << " " << point.x() << " " << point.y() << endl; - } + cout << "convex_height:" << convex_height << endl; } } + #endif + #ifdef DEBUG + { + for (const auto& box_height: printer_geometry.box_heights) + { + cout << "box_height:" << box_height << endl; + } + } + #endif + + #ifdef DEBUG + { + printf("extruder slices:\n"); + } + #endif + REQUIRE(printer_geometry.extruder_slices.size() > 0); + + #ifdef DEBUG + { + for (std::map >::const_iterator extruder_slice = printer_geometry.extruder_slices.begin(); extruder_slice != printer_geometry.extruder_slices.end(); ++extruder_slice) + { + for (const auto &polygon: extruder_slice->second) + { + printf(" polygon height: %d\n", extruder_slice->first); + + for (const auto &point: polygon.points) + { + cout << " " << point.x() << " " << point.y() << endl; + } + } + } + + } + #endif + + #ifdef DEBUG finish = clock(); - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing interface 3 ... finished\n"); + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing interface 3 ... finished"); } TEST_CASE("Interface test 4", "[Sequential Arrangement Interface]") +//void interface_test_4(void) { + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing interface 4 ...\n"); + INFO("Testing interface 4 ..."); + #ifdef DEBUG start = clock(); + #endif SolverConfiguration solver_configuration; solver_configuration.decimation_precision = SEQ_DECIMATION_PRECISION_HIGH; solver_configuration.object_group_size = 4; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); - printf("Loading objects ...\n"); + #ifdef DEBUG + { + printf("Loading objects ...\n"); + } + #endif std::vector objects_to_print = load_exported_data_from_text(arrange_data_export_text); - printf("Loading objects ... finished\n"); + #ifdef DEBUG + { + printf("Loading objects ... finished\n"); + } + #endif PrinterGeometry printer_geometry; - printf("Loading printer geometry ...\n"); + #ifdef DEBUG + { + printf("Loading printer geometry ...\n"); + } + #endif int result = load_printer_geometry_from_text(printer_geometry_mk4_compatibility_text, printer_geometry); REQUIRE(result == 0); if (result != 0) { - printf("Cannot load printer geometry (code: %d).\n", result); + #ifdef DEBUG + { + printf("Cannot load printer geometry (code: %d).\n", result); + } + #endif return; } solver_configuration.setup(printer_geometry); - printf("Loading printer geometry ... finished\n"); + #ifdef DEBUG + { + printf("Loading printer geometry ... finished\n"); + } + #endif std::vector scheduled_plates; - printf("Scheduling objects for sequential print ...\n"); + #ifdef DEBUG + { + printf("Scheduling objects for sequential print ...\n"); + } + #endif scheduled_plates = schedule_ObjectsForSequentialPrint(solver_configuration, printer_geometry, objects_to_print); - printf("Object scheduling for sequential print SUCCESSFUL !\n"); - - printf("Number of plates: %ld\n", scheduled_plates.size()); + #ifdef DEBUG + { + printf("Object scheduling for sequential print SUCCESSFUL !\n"); + } + #endif + + #ifdef DEBUG + { + printf("Number of plates: %ld\n", scheduled_plates.size()); + } + #endif REQUIRE(scheduled_plates.size() > 0); for (unsigned int plate = 0; plate < scheduled_plates.size(); ++plate) { - printf(" Number of objects on plate: %ld\n", scheduled_plates[plate].scheduled_objects.size()); + #ifdef DEBUG + { + printf(" Number of objects on plate: %ld\n", scheduled_plates[plate].scheduled_objects.size()); + } + #endif REQUIRE(scheduled_plates[plate].scheduled_objects.size() > 0); for (const auto& scheduled_object: scheduled_plates[plate].scheduled_objects) { - cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; + #ifdef DEBUG + { + cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; + } + #endif BoundingBox plate_box = get_extents(printer_geometry.plate); @@ -739,68 +915,122 @@ TEST_CASE("Interface test 4", "[Sequential Arrangement Interface]") REQUIRE(scheduled_object.y <= plate_box.max.y()); } } - + + #ifdef DEBUG finish = clock(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing interface 4 ... finished\n"); + #endif + + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing interface 4 ... finished"); } TEST_CASE("Interface test 5", "[Sequential Arrangement Interface]") +//void interface_test_5(void) { + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing interface 5 ...\n"); + INFO("Testing interface 5 ..."); + #ifdef DEBUG start = clock(); + #endif SolverConfiguration solver_configuration; solver_configuration.decimation_precision = SEQ_DECIMATION_PRECISION_LOW; solver_configuration.object_group_size = 4; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); - printf("Loading objects ...\n"); + #ifdef DEBUG + { + printf("Loading objects ...\n"); + } + #endif std::vector objects_to_print = load_exported_data_from_text(arrange_data_export_text); - printf("Loading objects ... finished\n"); + #ifdef DEBUG + { + printf("Loading objects ... finished\n"); + } + #endif PrinterGeometry printer_geometry; - printf("Loading printer geometry ...\n"); + #ifdef DEBUG + { + printf("Loading printer geometry ...\n"); + } + #endif int result = load_printer_geometry_from_text(printer_geometry_mk4_compatibility_text, printer_geometry); REQUIRE(result == 0); if (result != 0) { - printf("Cannot load printer geometry (code: %d).\n", result); + #ifdef DEBUG + { + printf("Cannot load printer geometry (code: %d).\n", result); + } + #endif return; } solver_configuration.setup(printer_geometry); - printf("Loading printer geometry ... finished\n"); + #ifdef DEBUG + { + printf("Loading printer geometry ... finished\n"); + } + #endif std::vector scheduled_plates; - printf("Scheduling objects for sequential print ...\n"); + #ifdef DEBUG + { + printf("Scheduling objects for sequential print ...\n"); + } + #endif scheduled_plates = schedule_ObjectsForSequentialPrint(solver_configuration, printer_geometry, objects_to_print, - [](int progress) { printf("Progress: %d\n", progress); - REQUIRE(progress >= 0); + [](int progress) { + #ifdef DEBUG + { printf("Progress: %d\n", progress); } + #endif + REQUIRE(progress >= 0); REQUIRE(progress <= 100); }); - printf("Object scheduling for sequential print SUCCESSFUL !\n"); - - printf("Number of plates: %ld\n", scheduled_plates.size()); + #ifdef DEBUG + { + printf("Object scheduling for sequential print SUCCESSFUL !\n"); + } + #endif + + #ifdef DEBUG + { + printf("Number of plates: %ld\n", scheduled_plates.size()); + } + #endif REQUIRE(scheduled_plates.size() > 0); for (unsigned int plate = 0; plate < scheduled_plates.size(); ++plate) { - printf(" Number of objects on plate: %ld\n", scheduled_plates[plate].scheduled_objects.size()); + #ifdef DEBUG + { + printf("Number of objects on plate: %ld\n", scheduled_plates[plate].scheduled_objects.size()); + } + #endif REQUIRE(scheduled_plates[plate].scheduled_objects.size() > 0); for (const auto& scheduled_object: scheduled_plates[plate].scheduled_objects) { - cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; + #ifdef DEBUG + { + cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; + } + #endif BoundingBox plate_box = get_extents(printer_geometry.plate); @@ -811,46 +1041,81 @@ TEST_CASE("Interface test 5", "[Sequential Arrangement Interface]") } } + #ifdef DEBUG finish = clock(); - printf("Solving time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + { + printf("Solving time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + start = clock(); + #endif - start = clock(); - - printf("Checking sequential printability ...\n"); + + #ifdef DEBUG + { + printf("Checking sequential printability ...\n"); + } + #endif bool printable = check_ScheduledObjectsForSequentialPrintability(solver_configuration, printer_geometry, objects_to_print, - scheduled_plates); - printf(" Scheduled/arranged objects are sequentially printable: %s\n", (printable ? "YES" : "NO")); + scheduled_plates); + + #ifdef DEBUG + { + printf(" Scheduled/arranged objects are sequentially printable: %s\n", (printable ? "YES" : "NO")); + } + #endif REQUIRE(printable); - printf("Checking sequential printability ... finished\n"); + #ifdef DEBUG + { + printf("Checking sequential printability ... finished\n"); + } + #endif - finish = clock(); - printf("Checking time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + #ifdef DEBUG + finish = clock(); + { + printf("Checking time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif - printf("Testing interface 5 ... finished\n"); + INFO("Testing interface 5 ... finished"); } TEST_CASE("Interface test 6", "[Sequential Arrangement Interface]") +//void interface_test_6(void) { + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing interface 6 ...\n"); + INFO("Testing interface 6 ..."); + #ifdef DEBUG start = clock(); + #endif SolverConfiguration solver_configuration; solver_configuration.decimation_precision = SEQ_DECIMATION_PRECISION_LOW; solver_configuration.object_group_size = 4; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); - printf("Loading objects ...\n"); + #ifdef DEBUG + { + printf("Loading objects ...\n"); + } + #endif std::vector objects_to_print = load_exported_data_from_text(arrange_data_export_text); - REQUIRE(objects_to_print.size() > 0); - printf("Loading objects ... finished\n"); + REQUIRE(objects_to_print.size() > 0); + + #ifdef DEBUG + { + printf("Loading objects ... finished\n"); + } + #endif for (auto& object_to_print: objects_to_print) { @@ -859,41 +1124,77 @@ TEST_CASE("Interface test 6", "[Sequential Arrangement Interface]") PrinterGeometry printer_geometry; - printf("Loading printer geometry ...\n"); + #ifdef DEBUG + { + printf("Loading printer geometry ...\n"); + } + #endif int result = load_printer_geometry_from_text(printer_geometry_mk4_compatibility_text, printer_geometry); + REQUIRE(result == 0); if (result != 0) { - printf("Cannot load printer geometry (code: %d).\n", result); + #ifdef DEBUG + { + printf("Cannot load printer geometry (code: %d).\n", result); + } + #endif return; } solver_configuration.setup(printer_geometry); - printf("Loading printer geometry ... finished\n"); + #ifdef DEBUG + { + printf("Loading printer geometry ... finished\n"); + } + #endif std::vector scheduled_plates; - printf("Scheduling objects for sequential print ...\n"); + #ifdef DEBUG + { + printf("Scheduling objects for sequential print ...\n"); + } + #endif scheduled_plates = schedule_ObjectsForSequentialPrint(solver_configuration, printer_geometry, objects_to_print, - [](int progress) { printf("Progress: %d\n", progress); + [](int progress) { + #ifdef DEBUG + { printf("Progress: %d\n", progress); } + #endif REQUIRE(progress >= 0); REQUIRE(progress <= 100); }); - printf("Object scheduling for sequential print SUCCESSFUL !\n"); - - printf("Number of plates: %ld\n", scheduled_plates.size()); + #ifdef DEBUG + { + printf("Object scheduling for sequential print SUCCESSFUL !\n"); + } + #endif + + #ifdef DEBUG + { + printf("Number of plates: %ld\n", scheduled_plates.size()); + } + #endif REQUIRE(scheduled_plates.size() > 0); for (unsigned int plate = 0; plate < scheduled_plates.size(); ++plate) { - printf(" Number of objects on plate: %ld\n", scheduled_plates[plate].scheduled_objects.size()); + #ifdef DEBUG + { + printf(" Number of objects on plate: %ld\n", scheduled_plates[plate].scheduled_objects.size()); + } + #endif + REQUIRE(scheduled_plates[plate].scheduled_objects.size() > 0); for (const auto& scheduled_object: scheduled_plates[plate].scheduled_objects) { - cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; - + #ifdef DEBUG + { + cout << " ID: " << scheduled_object.id << " X: " << scheduled_object.x << " Y: " << scheduled_object.y << endl; + } + #endif BoundingBox plate_box = get_extents(printer_geometry.plate); REQUIRE(scheduled_object.x >= plate_box.min.x()); @@ -903,27 +1204,46 @@ TEST_CASE("Interface test 6", "[Sequential Arrangement Interface]") } } + #ifdef DEBUG finish = clock(); - printf("Solving time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + { + printf("Solving time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + start = clock(); + #endif - start = clock(); - - printf("Checking sequential printability ...\n"); + #ifdef DEBUG + { + printf("Checking sequential printability ...\n"); + } + #endif bool printable = check_ScheduledObjectsForSequentialPrintability(solver_configuration, printer_geometry, objects_to_print, scheduled_plates); - - printf(" Scheduled/arranged objects are sequentially printable: %s\n", (printable ? "YES" : "NO")); + + #ifdef DEBUG + { + printf(" Scheduled/arranged objects are sequentially printable: %s\n", (printable ? "YES" : "NO")); + } + #endif REQUIRE(printable); - printf("Checking sequential printability ... finished\n"); + #ifdef DEBUG + { + printf("Checking sequential printability ... finished\n"); + } + finish = clock(); + #endif - finish = clock(); - printf("Checking time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + #ifdef DEBUG + { + printf("Checking time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif - printf("Testing interface 6 ... finished\n"); + INFO("Testing interface 6 ... finished"); } diff --git a/src/libseqarrange/test/seq_test_interface.hpp b/src/libseqarrange/test/seq_test_interface.hpp index 5292a70f2a..c622a20741 100644 --- a/src/libseqarrange/test/seq_test_interface.hpp +++ b/src/libseqarrange/test/seq_test_interface.hpp @@ -1,6 +1,6 @@ /*================================================================*/ /* - * Author: Pavel Surynek, 2023 - 2024 + * Author: Pavel Surynek, 2023 - 2025 * Company: Prusa Research * * File: seq_test_interface.hpp diff --git a/src/libseqarrange/test/seq_test_polygon.cpp b/src/libseqarrange/test/seq_test_polygon.cpp index 6715aa7045..c8ce17c7ab 100644 --- a/src/libseqarrange/test/seq_test_polygon.cpp +++ b/src/libseqarrange/test/seq_test_polygon.cpp @@ -1,6 +1,6 @@ /*================================================================*/ /* - * Author: Pavel Surynek, 2023 - 2024 + * Author: Pavel Surynek, 2023 - 2025 * Company: Prusa Research * * File: seq_test_polygon.cpp @@ -878,8 +878,6 @@ void polygon_test_6(void) z3::expr deco_1 = expr(z_context.real_const("deco_1")); z3::expr lino_1 = (valo_1 * deco_1 == 0); - - printf("value: %.3f\n", value); cout << float(z_model[i]) << "\n"; @@ -1139,7 +1137,7 @@ TEST_CASE("Polygon test 7", "[Polygon]") double value = X_positions[i].as_double(); printf("Orig X: %.3f\n", value); - value = Y_positi ons[i].as_double(); + value = Y_positions[i].as_double(); printf("Orig Y: %.3f\n", value); } } @@ -1446,37 +1444,7 @@ void polygon_test_8(void) else { break; - } - - #ifdef DEBUG - { - cout << float(z_model[i]) << "\n"; - - switch (z_model.get_const_interp(z_model[i]).bool_value()) - { - case Z3_L_FALSE: - { - printf(" value: FALSE\n"); - break; - } - case Z3_L_TRUE: - { - printf(" value: TRUE\n"); - break; - } - case Z3_L_UNDEF: - { - printf(" value: UNDEF\n"); - break; - } - default: - { - break; - } - } - } - #endif - + } } #ifdef DEBUG finish = clock(); @@ -1499,7 +1467,8 @@ void polygon_test_8(void) printf("Orig X: %.3f\n", value); value = Y_positions[i].as_double(); - printf("Orig Y: %.3f\n", value); + printf("Orig Y: %.3f\n", value); + } } #endif @@ -1508,7 +1477,7 @@ void polygon_test_8(void) Polygon display_polygon_1 = scale_UP(polygon_1, poly_1_pos_x, poly_1_pos_y); Polygon display_polygon_2 = scale_UP(polygon_2, poly_2_pos_x, poly_2_pos_y); Polygon display_polygon_3 = scale_UP(polygon_3, poly_3_pos_x, poly_3_pos_y); - + preview_svg.draw(display_polygon_1, "green"); preview_svg.draw(display_polygon_2, "blue"); preview_svg.draw(display_polygon_3, "red"); @@ -1777,35 +1746,6 @@ TEST_CASE("Polygon test 9", "[Polygon]") { break; } - - #ifdef DEBUG - { - cout << float(z_model[i]) << "\n"; - - switch (z_model.get_const_interp(z_model[i]).bool_value()) - { - case Z3_L_FALSE: - { - printf(" value: FALSE\n"); - break; - } - case Z3_L_TRUE: - { - printf(" value: TRUE\n"); - break; - } - case Z3_L_UNDEF: - { - printf(" value: UNDEF\n"); - break; - } - default: - { - break; - } - } - } - #endif } #ifdef DEBUG finish = clock(); @@ -2088,35 +2028,6 @@ void polygon_test_10(void) { break; } - - #ifdef DEBUG - { - cout << float(z_model[i]) << "\n"; - - switch (z_model.get_const_interp(z_model[i]).bool_value()) - { - case Z3_L_FALSE: - { - printf(" value: FALSE\n"); - break; - } - case Z3_L_TRUE: - { - printf(" value: TRUE\n"); - break; - } - case Z3_L_UNDEF: - { - printf(" value: UNDEF\n"); - break; - } - default: - { - break; - } - } - } - #endif } #ifdef DEBUG finish = clock(); @@ -2558,35 +2469,6 @@ TEST_CASE("Polygon test 11", "[Polygon]") { break; } - - #ifdef DEBUG - { - cout << float(z_model[i]) << "\n"; - - switch (z_model.get_const_interp(z_model[i]).bool_value()) - { - case Z3_L_FALSE: - { - printf(" value: FALSE\n"); - break; - } - case Z3_L_TRUE: - { - printf(" value: TRUE\n"); - break; - } - case Z3_L_UNDEF: - { - printf(" value: UNDEF\n"); - break; - } - default: - { - break; - } - } - } - #endif } #ifdef DEBUG finish = clock(); diff --git a/src/libseqarrange/test/seq_test_polygon.hpp b/src/libseqarrange/test/seq_test_polygon.hpp index a4badc72da..152790a0eb 100644 --- a/src/libseqarrange/test/seq_test_polygon.hpp +++ b/src/libseqarrange/test/seq_test_polygon.hpp @@ -1,6 +1,6 @@ /*================================================================*/ /* - * Author: Pavel Surynek, 2023 - 2024 + * Author: Pavel Surynek, 2023 - 2025 * Company: Prusa Research * * File: seq_test_polygon.hpp diff --git a/src/libseqarrange/test/seq_test_preprocess.cpp b/src/libseqarrange/test/seq_test_preprocess.cpp index ba3ba902c1..0f0534546b 100644 --- a/src/libseqarrange/test/seq_test_preprocess.cpp +++ b/src/libseqarrange/test/seq_test_preprocess.cpp @@ -1,6 +1,6 @@ /*================================================================*/ /* - * Author: Pavel Surynek, 2023 - 2024 + * Author: Pavel Surynek, 2023 - 2025 * Company: Prusa Research * * File: seq_test_preprocess.cpp @@ -50,13 +50,12 @@ using namespace Sequential; /*----------------------------------------------------------------*/ -const int SEQ_PRUSA_MK3S_X_SIZE = 2500; -const int SEQ_PRUSA_MK3S_Y_SIZE = 2100; - +const coord_t SEQ_PRUSA_MK3S_X_SIZE = 250000000; +const coord_t SEQ_PRUSA_MK3S_Y_SIZE = 210000000; /*----------------------------------------------------------------*/ - +/* static Polygon scale_UP(const Polygon &polygon) { Polygon poly = polygon; @@ -68,7 +67,7 @@ static Polygon scale_UP(const Polygon &polygon) return poly; } - +*/ static Polygon scale_UP(const Polygon &polygon, double x_pos, double y_pos) { @@ -88,14 +87,17 @@ std::vector test_polygons; TEST_CASE("Preprocessing test 1", "[Sequential Arrangement Preprocessing]") { + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing preprocessing 1 ...\n"); + INFO("Testing preprocessing 1 ..."); SolverConfiguration solver_configuration; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); - + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); + #ifdef DEBUG start = clock(); + #endif for (unsigned int i = 0; i < PRUSA_PART_POLYGONS.size(); ++i) { Polygon scale_down_polygon; @@ -110,29 +112,40 @@ TEST_CASE("Preprocessing test 1", "[Sequential Arrangement Preprocessing]") Polygon display_polygon = scale_UP(test_polygons[i], 1000, 1000); preview_svg.draw(display_polygon, "blue"); preview_svg.Close(); - } + } + #ifdef DEBUG finish = clock(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing preprocessing 1 ... finished\n"); + #endif + + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing preprocessing 1 ... finished"); } -TEST_CASE("Preprocessing test 2", "[Sequential Arrangement Preprocessing]") -{ +//TEST_CASE("Preprocessing test 2", "[Sequential Arrangement Preprocessing]") +void preprocessing_test_2(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing preprocess 2 ...\n"); + INFO("Testing preprocess 2 ..."); + #ifdef DEBUG start = clock(); + #endif SolverConfiguration solver_configuration; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); vector polygons; vector unreachable_polygons; - for (unsigned int i = 0; i < PRUSA_PART_POLYGONS.size(); ++i) + for (unsigned int i = 0; i < 8 /*PRUSA_PART_POLYGONS.size()*/; ++i) { Polygon scale_down_polygon; scaleDown_PolygonForSequentialSolver(PRUSA_PART_POLYGONS[i], scale_down_polygon); @@ -169,21 +182,29 @@ TEST_CASE("Preprocessing test 2", "[Sequential Arrangement Preprocessing]") decided_polygons, remaining_polygons); - printf("----> Optimization finished <----\n"); + #ifdef DEBUG + { + printf("----> Optimization finished <----\n"); + } + #endif REQUIRE(optimized); if (optimized) { - printf("Polygon positions:\n"); - for (unsigned int i = 0; i < decided_polygons.size(); ++i) + #ifdef DEBUG { - printf(" [%d] %.3f, %.3f (%.3f)\n", decided_polygons[i], poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double(), times_T[decided_polygons[i]].as_double()); - } - printf("Remaining polygons: %ld\n", remaining_polygons.size()); - for (unsigned int i = 0; i < remaining_polygons.size(); ++i) - { - printf(" %d\n", remaining_polygons[i]); + printf("Polygon positions:\n"); + for (unsigned int i = 0; i < decided_polygons.size(); ++i) + { + printf(" [%d] %.3f, %.3f (%.3f)\n", decided_polygons[i], poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double(), times_T[decided_polygons[i]].as_double()); + } + printf("Remaining polygons: %ld\n", remaining_polygons.size()); + for (unsigned int i = 0; i < remaining_polygons.size(); ++i) + { + printf(" %d\n", remaining_polygons[i]); + } } + #endif SVG preview_svg("preprocess_test_2.svg"); @@ -194,29 +215,26 @@ TEST_CASE("Preprocessing test 2", "[Sequential Arrangement Preprocessing]") #ifdef DEBUG { printf("----> %.3f,%.3f\n", poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double()); - for (int k = 0; k < polygons[decided_polygons[i]].points.size(); ++k) + for (unsigned int k = 0; k < polygons[decided_polygons[i]].points.size(); ++k) { printf(" xy: %d, %d\n", polygons[decided_polygons[i]].points[k].x(), polygons[decided_polygons[i]].points[k].y()); } } #endif - for (unsigned int j = 0; j < unreachable_polygons[decided_polygons[i]].size(); ++j) + #ifdef DEBUG { - #ifdef DEBUG + for (unsigned int k = 0; k < unreachable_polygons[decided_polygons[i]].points.size(); ++k) { - for (int k = 0; k < unreachable_polygons[decided_polygons[i]][j].points.size(); ++k) - { - printf(" Pxy: %d, %d\n", unreachable_polygons[decided_polygons[i]][j].points[k].x(), unreachable_polygons[decided_polygons[i]][j].points[k].y()); - } + printf(" Pxy: %d, %d\n", unreachable_polygons[decided_polygons[i]].points[k].x(), unreachable_polygons[decided_polygons[i]].points[k].y()); } - #endif - - Polygon display_unreachable_polygon = scale_UP(unreachable_polygons[decided_polygons[i]], - poly_positions_X[decided_polygons[i]].as_double(), - poly_positions_Y[decided_polygons[i]].as_double()); - preview_svg.draw(display_unreachable_polygon, "lightgrey"); } + #endif + + Polygon display_unreachable_polygon = scale_UP(unreachable_polygons[decided_polygons[i]], + poly_positions_X[decided_polygons[i]].as_double(), + poly_positions_Y[decided_polygons[i]].as_double()); + preview_svg.draw(display_unreachable_polygon, "lightgrey"); } } @@ -303,19 +321,33 @@ TEST_CASE("Preprocessing test 2", "[Sequential Arrangement Preprocessing]") } else { - printf("Polygon optimization FAILED.\n"); - } + #ifdef DEBUG + { + printf("Polygon optimization FAILED.\n"); + } + #endif + } + #ifdef DEBUG finish = clock(); + #endif - printf("Intermediate time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + #ifdef DEBUG + { + printf("Intermediate time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif vector next_polygons; vector next_unreachable_polygons; - for (unsigned int i = 0; i < polygon_index_map.size(); ++i) + #ifdef DEBUG { - printf(" %d\n", polygon_index_map[i]); + for (unsigned int i = 0; i < polygon_index_map.size(); ++i) + { + printf(" %d\n", polygon_index_map[i]); + } } + #endif for (unsigned int i = 0; i < remaining_polygons.size(); ++i) { next_polygons.push_back(polygons[remaining_polygons[i]]); @@ -336,23 +368,33 @@ TEST_CASE("Preprocessing test 2", "[Sequential Arrangement Preprocessing]") } while (!remaining_polygons.empty()); + #ifdef DEBUG finish = clock(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing preprocess 2 ... finished\n"); + #endif + + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing preprocess 2 ... finished"); } TEST_CASE("Preprocessing test 3", "[Sequential Arrangement Preprocessing]") { + #ifdef DEBUG clock_t start, finish; + #endif SolverConfiguration solver_configuration; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); - printf("Testing preprocessing 3 ...\n"); + INFO("Testing preprocessing 3 ..."); + #ifdef DEBUG start = clock(); + #endif std::vector nozzle_unreachable_polygons; std::vector extruder_unreachable_polygons; @@ -585,28 +627,38 @@ TEST_CASE("Preprocessing test 3", "[Sequential Arrangement Preprocessing]") preview_svg.Close(); } } - + #ifdef DEBUG finish = clock(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing preprocess 3 ... finished\n"); + #endif + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing preprocess 3 ... finished"); } -TEST_CASE("Preprocessing test 4", "[Sequential Arrangement Preprocessing]") -{ +//TEST_CASE("Preprocessing test 4", "[Sequential Arrangement Preprocessing]") +void preprocessing_test_4(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing preprocess 4 ...\n"); + INFO("Testing preprocess 4 ..."); + #ifdef DEBUG start = clock(); + #endif SolverConfiguration solver_configuration; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); std::vector polygons; std::vector > unreachable_polygons; + for (int i = 0; i < 12; ++i) { Polygon scale_down_polygon; @@ -658,21 +710,29 @@ TEST_CASE("Preprocessing test 4", "[Sequential Arrangement Preprocessing]") decided_polygons, remaining_polygons); - printf("----> Optimization finished <----\n"); + #ifdef DEBUG + { + printf("----> Optimization finished <----\n"); + } + #endif REQUIRE(optimized); if (optimized) { - printf("Polygon positions:\n"); - for (unsigned int i = 0; i < decided_polygons.size(); ++i) + #ifdef DEBUG { - printf(" [%d] %.3f, %.3f (%.3f)\n", decided_polygons[i], poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double(), times_T[decided_polygons[i]].as_double()); - } - printf("Remaining polygons: %ld\n", remaining_polygons.size()); - for (unsigned int i = 0; i < remaining_polygons.size(); ++i) - { - printf(" %d\n", remaining_polygons[i]); + printf("Polygon positions:\n"); + for (unsigned int i = 0; i < decided_polygons.size(); ++i) + { + printf(" [%d] %.3f, %.3f (%.3f)\n", decided_polygons[i], poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double(), times_T[decided_polygons[i]].as_double()); + } + printf("Remaining polygons: %ld\n", remaining_polygons.size()); + for (unsigned int i = 0; i < remaining_polygons.size(); ++i) + { + printf(" %d\n", remaining_polygons[i]); + } } + #endif SVG preview_svg("preprocess_test_4.svg"); @@ -682,27 +742,29 @@ TEST_CASE("Preprocessing test 4", "[Sequential Arrangement Preprocessing]") { #ifdef DEBUG { - printf("----> %.3f,%.3f\n", poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double()); - for (int k = 0; k < polygons[decided_polygons[i]].points.size(); ++k) - { - printf(" xy: %d, %d\n", polygons[decided_polygons[i]].points[k].x(), polygons[decided_polygons[i]].points[k].y()); + printf("----> %.3f,%.3f\n", poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double()); + for (unsigned int k = 0; k < polygons[decided_polygons[i]].points.size(); ++k) + { + printf(" xy: %d, %d\n", polygons[decided_polygons[i]].points[k].x(), polygons[decided_polygons[i]].points[k].y()); + } } -} #endif + for (unsigned int j = 0; j < unreachable_polygons[decided_polygons[i]].size(); ++j) { #ifdef DEBUG - { - for (int k = 0; k < unreachable_polygons[decided_polygons[i]][j].points.size(); ++k) { - printf(" Pxy: %d, %d\n", unreachable_polygons[decided_polygons[i]][j].points[k].x(), unreachable_polygons[decided_polygons[i]][j].points[k].y()); + for (unsigned int k = 0; k < unreachable_polygons[decided_polygons[i]][j].points.size(); ++k) + { + printf(" Pxy: %d, %d\n", unreachable_polygons[decided_polygons[i]][j].points[k].x(), unreachable_polygons[decided_polygons[i]][j].points[k].y()); + } } #endif - + Polygon display_unreachable_polygon = scale_UP(unreachable_polygons[decided_polygons[i]][j], - poly_positions_X[decided_polygons[i]].as_double(), - poly_positions_Y[decided_polygons[i]].as_double()); - preview_svg.draw(display_unreachable_polygon, "lightgrey"); + poly_positions_X[decided_polygons[i]].as_double(), + poly_positions_Y[decided_polygons[i]].as_double()); + preview_svg.draw(display_unreachable_polygon, "lightgrey"); } } } @@ -712,7 +774,6 @@ TEST_CASE("Preprocessing test 4", "[Sequential Arrangement Preprocessing]") Polygon display_polygon = scale_UP(polygons[decided_polygons[i]], poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double()); - string color; switch(i) @@ -785,23 +846,37 @@ TEST_CASE("Preprocessing test 4", "[Sequential Arrangement Preprocessing]") preview_svg.draw(display_polygon, color); } - preview_svg.Close(); } else { - printf("Polygon optimization FAILED.\n"); + #ifdef DEBUG + { + printf("Polygon optimization FAILED.\n"); + } + #endif } - finish = clock(); - printf("Intermediate time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + #ifdef DEBUG + finish = clock(); + #endif + + #ifdef DEBUG + { + printf("Intermediate time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif vector next_polygons; vector > next_unreachable_polygons; - for (unsigned int i = 0; i < polygon_index_map.size(); ++i) + #ifdef DEBUG { - printf(" %d\n", polygon_index_map[i]); + for (unsigned int i = 0; i < polygon_index_map.size(); ++i) + { + printf(" %d\n", polygon_index_map[i]); + } } + #endif for (unsigned int i = 0; i < remaining_polygons.size(); ++i) { next_polygons.push_back(polygons[remaining_polygons[i]]); @@ -822,23 +897,33 @@ TEST_CASE("Preprocessing test 4", "[Sequential Arrangement Preprocessing]") } while (!remaining_polygons.empty()); + #ifdef DEBUG finish = clock(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing preprocess 4 ... finished\n"); + #endif + + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing preprocess 4 ... finished"); } TEST_CASE("Preprocessing test 5", "[Sequential Arrangement Preprocessing]") -{ +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing preprocess 5 ...\n"); + INFO("Testing preprocess 5 ..."); + #ifdef DEBUG start = clock(); + #endif SolverConfiguration solver_configuration; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); std::vector polygons; std::vector > unreachable_polygons; @@ -878,27 +963,38 @@ TEST_CASE("Preprocessing test 5", "[Sequential Arrangement Preprocessing]") preview_svg.Close(); } + #ifdef DEBUG finish = clock(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing preprocess 5 ... finished\n"); + #endif + + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing preprocess 5 ... finished"); } -TEST_CASE("Preprocessing test 6", "[Sequential Arrangement Preprocessing]") -{ +//TEST_CASE("Preprocessing test 6", "[Sequential Arrangement Preprocessing]") +void preprocessing_test_6(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing preprocess 6 ...\n"); + INFO("Testing preprocess 6 ..."); + #ifdef DEBUG start = clock(); + #endif SolverConfiguration solver_configuration; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); std::vector polygons; std::vector > unreachable_polygons; - for (unsigned int i = 0; i < PRUSA_PART_POLYGONS.size(); ++i) + for (unsigned int i = 0; i < 12 /*PRUSA_PART_POLYGONS.size()*/; ++i) { Polygon decimated_polygon; decimate_PolygonForSequentialSolver(solver_configuration, @@ -955,21 +1051,29 @@ TEST_CASE("Preprocessing test 6", "[Sequential Arrangement Preprocessing]") decided_polygons, remaining_polygons); - printf("----> Optimization finished <----\n"); + #ifdef DEBUG + { + printf("----> Optimization finished <----\n"); + } + #endif REQUIRE(optimized); if (optimized) { - printf("Polygon positions:\n"); - for (unsigned int i = 0; i < decided_polygons.size(); ++i) + #ifdef DEBUG { - printf(" [%d] %.3f, %.3f (%.3f)\n", decided_polygons[i], poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double(), times_T[decided_polygons[i]].as_double()); - } - printf("Remaining polygons: %ld\n", remaining_polygons.size()); - for (unsigned int i = 0; i < remaining_polygons.size(); ++i) - { - printf(" %d\n", remaining_polygons[i]); + printf("Polygon positions:\n"); + for (unsigned int i = 0; i < decided_polygons.size(); ++i) + { + printf(" [%d] %.3f, %.3f (%.3f)\n", decided_polygons[i], poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double(), times_T[decided_polygons[i]].as_double()); + } + printf("Remaining polygons: %ld\n", remaining_polygons.size()); + for (unsigned int i = 0; i < remaining_polygons.size(); ++i) + { + printf(" %d\n", remaining_polygons[i]); + } } + #endif SVG preview_svg("preprocess_test_6.svg"); @@ -980,7 +1084,7 @@ TEST_CASE("Preprocessing test 6", "[Sequential Arrangement Preprocessing]") #ifdef DEBUG { printf("----> %.3f,%.3f\n", poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double()); - for (int k = 0; k < polygons[decided_polygons[i]].points.size(); ++k) + for (unsigned int k = 0; k < polygons[decided_polygons[i]].points.size(); ++k) { printf(" xy: %d, %d\n", polygons[decided_polygons[i]].points[k].x(), polygons[decided_polygons[i]].points[k].y()); } @@ -990,7 +1094,7 @@ TEST_CASE("Preprocessing test 6", "[Sequential Arrangement Preprocessing]") { #ifdef DEBUG { - for (int k = 0; k < unreachable_polygons[decided_polygons[i]][j].points.size(); ++k) + for (unsigned int k = 0; k < unreachable_polygons[decided_polygons[i]][j].points.size(); ++k) { printf(" Pxy: %d, %d\n", unreachable_polygons[decided_polygons[i]][j].points[k].x(), unreachable_polygons[decided_polygons[i]][j].points[k].y()); } @@ -1087,18 +1191,33 @@ TEST_CASE("Preprocessing test 6", "[Sequential Arrangement Preprocessing]") } else { - printf("Polygon optimization FAILED.\n"); + #ifdef DEBUG + { + printf("Polygon optimization FAILED.\n"); + } + #endif } - finish = clock(); - printf("Intermediate time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + #ifdef DEBUG + finish = clock(); + #endif + + #ifdef DEBUG + { + printf("Intermediate time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif vector next_polygons; vector > next_unreachable_polygons; - for (unsigned int i = 0; i < polygon_index_map.size(); ++i) + #ifdef DEBUG { - printf(" %d\n", polygon_index_map[i]); + for (unsigned int i = 0; i < polygon_index_map.size(); ++i) + { + printf(" %d\n", polygon_index_map[i]); + } } + #endif for (unsigned int i = 0; i < remaining_polygons.size(); ++i) { next_polygons.push_back(polygons[remaining_polygons[i]]); @@ -1119,10 +1238,16 @@ TEST_CASE("Preprocessing test 6", "[Sequential Arrangement Preprocessing]") } while (!remaining_polygons.empty()); + #ifdef DEBUG finish = clock(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing preprocess 6 ... finished\n"); + #endif + + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing preprocess 6 ... finished"); } diff --git a/src/libseqarrange/test/seq_test_preprocess.hpp b/src/libseqarrange/test/seq_test_preprocess.hpp index 789b4afed2..08aeac8b8b 100644 --- a/src/libseqarrange/test/seq_test_preprocess.hpp +++ b/src/libseqarrange/test/seq_test_preprocess.hpp @@ -1,6 +1,6 @@ /*================================================================*/ /* - * Author: Pavel Surynek, 2023 - 2024 + * Author: Pavel Surynek, 2023 - 2025 * Company: Prusa Research * * File: seq_test_preprocess.hpp diff --git a/src/libseqarrange/test/seq_test_sequential.cpp b/src/libseqarrange/test/seq_test_sequential.cpp index da1f562420..0985182c8a 100644 --- a/src/libseqarrange/test/seq_test_sequential.cpp +++ b/src/libseqarrange/test/seq_test_sequential.cpp @@ -1,6 +1,6 @@ /*================================================================*/ /* - * Author: Pavel Surynek, 2023 - 2024 + * Author: Pavel Surynek, 2023 - 2025 * Company: Prusa Research * * File: seq_test_sequential.cpp @@ -26,6 +26,7 @@ #include #include "seq_defs.hpp" +#include "seq_preprocess.hpp" #include "seq_sequential.hpp" #include "seq_test_sequential.hpp" @@ -43,16 +44,15 @@ using namespace Sequential; #define SCALE_FACTOR 100000.0 - /*----------------------------------------------------------------*/ -const int SEQ_PRUSA_MK3S_X_SIZE = 2500; -const int SEQ_PRUSA_MK3S_Y_SIZE = 2100; +const int SEQ_PRUSA_MK3S_X_SIZE = 250000000; +const int SEQ_PRUSA_MK3S_Y_SIZE = 210000000; /*----------------------------------------------------------------*/ - +/* static Polygon scale_UP(const Polygon &polygon) { Polygon poly = polygon; @@ -64,7 +64,7 @@ static Polygon scale_UP(const Polygon &polygon) return poly; } - +*/ static Polygon scale_UP(const Polygon &polygon, double x_pos, double y_pos) { @@ -82,7 +82,7 @@ static Polygon scale_UP(const Polygon &polygon, double x_pos, double y_pos) TEST_CASE("Sequential test 1", "[Sequential Arrangement Core]") { - printf("Testing sequential scheduling 1 ...\n"); + INFO("Testing sequential scheduling 1 ..."); z3::context z_context; @@ -118,11 +118,15 @@ TEST_CASE("Sequential test 1", "[Sequential Arrangement Core]") z_solver.add(final5); z_solver.add(ef1); - printf("Printing solver status:\n"); - cout << z_solver << "\n"; + #ifdef DEBUG + { + printf("Printing solver status:\n"); + cout << z_solver << "\n"; - printf("Printing smt status:\n"); - cout << z_solver.to_smt2() << "\n"; + printf("Printing smt status:\n"); + cout << z_solver.to_smt2() << "\n"; + } + #endif bool sat = false; switch (z_solver.check()) @@ -130,17 +134,29 @@ TEST_CASE("Sequential test 1", "[Sequential Arrangement Core]") case z3::sat: { sat = true; - printf(" SATISFIABLE\n"); + #ifdef DEBUG + { + printf(" SATISFIABLE\n"); + } + #endif break; } case z3::unsat: { - printf(" UNSATISFIABLE\n"); + #ifdef DEBUG + { + printf(" UNSATISFIABLE\n"); + } + #endif break; } case z3::unknown: { - printf(" UNKNOWN\n"); + #ifdef DEBUG + { + printf(" UNKNOWN\n"); + } + #endif break; } default: @@ -151,27 +167,40 @@ TEST_CASE("Sequential test 1", "[Sequential Arrangement Core]") REQUIRE(sat); z3::model z_model(z_solver.get_model()); - printf("Printing model:\n"); - cout << z_model << "\n"; + + #ifdef DEBUG + { + printf("Printing model:\n"); + cout << z_model << "\n"; + } + #endif for (unsigned int i = 0; i < z_model.size(); ++i) { - printf("Variable:%s\n", z_model[i].name().str().c_str()); - printf("Printing interpretation:\n"); + #ifdef DEBUG + { + printf("Variable:%s\n", z_model[i].name().str().c_str()); + printf("Printing interpretation:\n"); - cout << z_model.get_const_interp(z_model[i]) << "\n"; + cout << z_model.get_const_interp(z_model[i]) << "\n"; + } + #endif - if (z_model.get_const_interp(z_model[i]).is_bool()) + #ifdef DEBUG { - printf(" value: TRUE\n"); - } - else - { - printf(" value: FALSE\n"); + if (z_model.get_const_interp(z_model[i]).is_bool()) + { + printf(" value: TRUE\n"); + } + else + { + printf(" value: FALSE\n"); + } } + #endif } - printf("Testing sequential scheduling 1 ... finished\n"); + INFO("Testing sequential scheduling 1 ... finished"); } @@ -216,13 +245,21 @@ void generate_random_complex_objects(void) for (int i = 0; i < complex_Obj_count; ++i) { - printf("Generating random object %d ...\n", i); + #ifdef DEBUG + { + printf("Generating random object %d ...\n", i); + } + #endif complex_Obj_widths[i] = min_width + rand() % width_span; complex_Obj_heights[i] = min_height + rand() % height_span; complex_Obj_durations[i] = min_duration + rand() % duration_span; - printf("O %d: w:%d h:%d d:%d\n", i, complex_Obj_widths[i], complex_Obj_heights[i], complex_Obj_durations[i]); + #ifdef DEBUG + { + printf("O %d: w:%d h:%d d:%d\n", i, complex_Obj_widths[i], complex_Obj_heights[i], complex_Obj_durations[i]); + } + #endif } } @@ -231,12 +268,16 @@ typedef std::basic_string sString; TEST_CASE("Sequential test 2", "[Sequential Arrangement Core]") { + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing sequential scheduling 2 ...\n"); + INFO("Testing sequential scheduling 2 ..."); generate_random_complex_objects(); + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -249,35 +290,50 @@ TEST_CASE("Sequential test 2", "[Sequential Arrangement Core]") for (int i = 0; i < complex_Obj_count; ++i) { sString name = "x_pos-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif X_positions.push_back(expr(z_context.real_const(name.c_str()))); } for (int i = 0; i < complex_Obj_count; ++i) { sString name = "y_pos-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif Y_positions.push_back(expr(z_context.real_const(name.c_str()))); } for (int i = 0; i < complex_Obj_count; ++i) { sString name = "time-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T_schedules.push_back(expr(z_context.real_const(name.c_str()))); } for (int i = 0; i < complex_Obj_count; ++i) { sString name_L = "gantry_L-" + to_string(i); - printf("name_L: %s\n", name_L.c_str()); - + #ifdef DEBUG + { + printf("name_L: %s\n", name_L.c_str()); + } + #endif sString name_R = "gantry_R-" + to_string(i); - printf("name_R: %s\n", name_R.c_str()); - + #ifdef DEBUG + { + printf("name_R: %s\n", name_R.c_str()); + } + #endif gantry_lefts.push_back(expr(z_context.real_const(name_L.c_str()))); gantry_rights.push_back(expr(z_context.real_const(name_R.c_str()))); } @@ -362,17 +418,29 @@ TEST_CASE("Sequential test 2", "[Sequential Arrangement Core]") case z3::sat: { sat = true; - printf(" SATISFIABLE\n"); + #ifdef DEBUG + { + printf(" SATISFIABLE\n"); + } + #endif break; } case z3::unsat: { - printf(" UNSATISFIABLE\n"); + #ifdef DEBUG + { + printf(" UNSATISFIABLE\n"); + } + #endif break; } case z3::unknown: { - printf(" UNKNOWN\n"); + #ifdef DEBUG + { + printf(" UNKNOWN\n"); + } + #endif break; } default: @@ -383,14 +451,14 @@ TEST_CASE("Sequential test 2", "[Sequential Arrangement Core]") REQUIRE(!sat); #ifdef DEBUG - { - z3::model z_model(z_solver.get_model()); - printf("Printing model:\n"); - cout << z_model << "\n"; - } + z3::model z_model(z_solver.get_model()); + printf("Printing model:\n"); + cout << z_model << "\n"; #endif - finish = clock(); + #ifdef DEBUG + finish = clock(); + #endif #ifdef DEBUG { @@ -433,14 +501,14 @@ TEST_CASE("Sequential test 2", "[Sequential Arrangement Core]") { for (int i = 0; i < complex_Obj_count; ++i) { - double val; printf("%s\n", z_model.get_const_interp(z_model[i]).get_string().c_str()); } + + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); } #endif - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing sequential scheduling 2 ... finished\n"); + + INFO("Testing sequential scheduling 2 ... finished"); } @@ -457,7 +525,11 @@ void generate_random_rotated_complex_objects(void) for (int i = 0; i < complex_Obj_count; ++i) { - printf("Generating random object %d ...\n", i); + #ifdef DEBUG + { + printf("Generating random object %d ...\n", i); + } + #endif int base_width = min_width + rand() % width_span; int base_height = min_height + rand() % height_span; @@ -470,14 +542,22 @@ void generate_random_rotated_complex_objects(void) int width = cos(angle) * base_width + min_width; int height = sin(angle) * base_height + min_height; - printf("w: %d, h: %d\n", width, height); + #ifdef DEBUG + { + printf("w: %d, h: %d\n", width, height); + } + #endif rotated_Obj_widths[i][r] = width; rotated_Obj_heights[i][r] = height; angle += angle_step; - printf("O %d: w:%d h:%d d:%d\n", i, rotated_Obj_widths[i][r], rotated_Obj_heights[i][r], complex_Obj_durations[i]); + #ifdef DEBUG + { + printf("O %d: w:%d h:%d d:%d\n", i, rotated_Obj_widths[i][r], rotated_Obj_heights[i][r], complex_Obj_durations[i]); + } + #endif } complex_Obj_durations[i] = min_duration + rand() % duration_span; @@ -485,14 +565,19 @@ void generate_random_rotated_complex_objects(void) } -TEST_CASE("Sequential test 3", "[Sequential Arrangement Core]") +//TEST_CASE("Sequential test 3", "[Sequential Arrangement Core]") +void sequential_test_3(void) { + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing sequential scheduling 3 ...\n"); + INFO("Testing sequential scheduling 3 ..."); generate_random_rotated_complex_objects(); + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -509,59 +594,83 @@ TEST_CASE("Sequential test 3", "[Sequential Arrangement Core]") for (int i = 0; i < complex_Obj_count; ++i) { sString name = "x_pos-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif X_positions.push_back(expr(z_context.real_const(name.c_str()))); } for (int i = 0; i < complex_Obj_count; ++i) { sString name = "y_pos-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif Y_positions.push_back(expr(z_context.real_const(name.c_str()))); } for (int i = 0; i < complex_Obj_count; ++i) { sString name = "time-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T_schedules.push_back(expr(z_context.real_const(name.c_str()))); } for (int i = 0; i < complex_Obj_count; ++i) { sString name = "width-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif widths.push_back(expr(z_context.real_const(name.c_str()))); } for (int i = 0; i < complex_Obj_count; ++i) { sString name = "height-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif heights.push_back(expr(z_context.real_const(name.c_str()))); } for (int i = 0; i < complex_Obj_count; ++i) { sString name = "rot-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif rotations.push_back(expr(z_context.int_const(name.c_str()))); } for (int i = 0; i < complex_Obj_count; ++i) { sString name_L = "gantry_L-" + to_string(i); - printf("name_L: %s\n", name_L.c_str()); - + #ifdef DEBUG + { + printf("name_L: %s\n", name_L.c_str()); + } + #endif sString name_R = "gantry_R-" + to_string(i); - printf("name_R: %s\n", name_R.c_str()); - + #ifdef DEBUG + { + printf("name_R: %s\n", name_R.c_str()); + } + #endif gantry_lefts.push_back(expr(z_context.real_const(name_L.c_str()))); gantry_rights.push_back(expr(z_context.real_const(name_R.c_str()))); } @@ -656,17 +765,29 @@ TEST_CASE("Sequential test 3", "[Sequential Arrangement Core]") case z3::sat: { sat = true; - printf(" SATISFIABLE\n"); + #ifdef DEBUG + { + printf(" SATISFIABLE\n"); + } + #endif break; } case z3::unsat: { - printf(" UNSATISFIABLE\n"); + #ifdef DEBUG + { + printf(" UNSATISFIABLE\n"); + } + #endif break; } case z3::unknown: { - printf(" UNKNOWN\n"); + #ifdef DEBUG + { + printf(" UNKNOWN\n"); + } + #endif break; } default: @@ -677,14 +798,14 @@ TEST_CASE("Sequential test 3", "[Sequential Arrangement Core]") REQUIRE(sat); #ifdef DEBUG - { - z3::model z_model(z_solver.get_model()); - printf("Printing model:\n"); - cout << z_model << "\n"; - } + z3::model z_model(z_solver.get_model()); + printf("Printing model:\n"); + cout << z_model << "\n"; #endif - finish = clock(); + #ifdef DEBUG + finish = clock(); + #endif #ifdef DEBUG { @@ -727,14 +848,14 @@ TEST_CASE("Sequential test 3", "[Sequential Arrangement Core]") { for (int i = 0; i < complex_Obj_count; ++i) { - double val; printf("%s\n", z_model.get_const_interp(z_model[i]).get_string().c_str()); } + + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); } #endif - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing sequential scheduling 3 ... finished\n"); + + INFO("Testing sequential scheduling 3 ... finished"); } namespace { @@ -781,13 +902,18 @@ namespace { } -TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") -{ +//TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") +void sequential_test_4(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing sequential 4 ...\n"); + INFO("Testing sequential 4 ..."); + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -796,26 +922,35 @@ TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") for (int i = 0; i < 4; ++i) { - printf("i:%d\n", i); string name = "x_pos-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("i:%d\n", i); + printf("name: %s\n", name.c_str()); + } + #endif X_positions.push_back(expr(z_context.real_const(name.c_str()))); } for (int i = 0; i < 4; ++i) { string name = "y_pos-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif Y_positions.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_1.points.size(); ++i) { string name = "t_time-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T_times.push_back(expr(z_context.real_const(name.c_str()))); } @@ -861,13 +996,20 @@ TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") time_1_t = time_2_t = time_3_t = time_4_t = -1.0; double _poly_1_pos_x, _poly_1_pos_y, _poly_2_pos_x, _poly_2_pos_y, _poly_3_pos_x, _poly_3_pos_y, _poly_4_pos_x, _poly_4_pos_y; - _poly_1_pos_x = _poly_1_pos_y = _poly_2_pos_x = _poly_2_pos_y = _poly_3_pos_x = _poly_3_pos_y = _poly_4_pos_x = _poly_4_pos_y = 0.0; + _poly_1_pos_x = _poly_1_pos_y = _poly_2_pos_x = _poly_2_pos_y = _poly_3_pos_x = _poly_3_pos_y = _poly_4_pos_x = _poly_4_pos_y = 0.0; + + #ifdef DEBUG double _time_1_t, _time_2_t, _time_3_t, _time_4_t; _time_1_t = _time_2_t = _time_3_t = _time_4_t = -1.0; + #endif for (int bounding_box_size = 200; bounding_box_size > 10; bounding_box_size -= 4) { - printf("BB: %d\n", bounding_box_size); + #ifdef DEBUG + { + printf("BB: %d\n", bounding_box_size); + } + #endif z3::expr_vector bounding_box_assumptions(z_context); assume_BedBoundingBox(X_positions[0], Y_positions[0], polygons[0], bounding_box_size, bounding_box_size, bounding_box_assumptions); @@ -880,20 +1022,32 @@ TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") switch (z_solver.check(bounding_box_assumptions)) { case z3::sat: - { - printf(" SATISFIABLE\n"); + { + #ifdef DEBUG + { + printf(" SATISFIABLE\n"); + } + #endif sat = true; break; } case z3::unsat: { - printf(" UNSATISFIABLE\n"); + #ifdef DEBUG + { + printf(" UNSATISFIABLE\n"); + } + #endif sat = false; break; } case z3::unknown: { - printf(" UNKNOWN\n"); + #ifdef DEBUG + { + printf(" UNKNOWN\n"); + } + #endif break; } default: @@ -912,15 +1066,23 @@ TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") cout << z_model << "\n"; } #endif - - printf("Printing interpretation:\n"); + + #ifdef DEBUG + { + printf("Printing interpretation:\n"); + } + #endif for (unsigned int i = 0; i < z_model.size(); ++i) { - printf("Variable:%s ", z_model[i].name().str().c_str()); - - cout << z_model.get_const_interp(z_model[i]).as_double() << "\n"; double value = z_model.get_const_interp(z_model[i]).as_double(); - printf("value: %.3f\n", value); + + #ifdef DEBUG + { + printf("Variable:%s ", z_model[i].name().str().c_str()); + cout << z_model.get_const_interp(z_model[i]).as_double() << "\n"; + printf("value: %.3f\n", value); + } + #endif if (z_model[i].name().str() == "x_pos-0") { @@ -972,25 +1134,29 @@ TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") } } - printf("Times: %.3f, %.3f, %.3f, %3f\n", - time_1_t, - time_2_t, - time_3_t, - time_4_t); + #ifdef DEBUG + { + printf("Times: %.3f, %.3f, %.3f, %3f\n", + time_1_t, + time_2_t, + time_3_t, + time_4_t); - printf("preRefined positions: %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f]\n", - poly_1_pos_x, - poly_1_pos_y, - time_1_t, - poly_2_pos_x, - poly_2_pos_y, - time_2_t, - poly_3_pos_x, - poly_3_pos_y, - time_3_t, - poly_4_pos_x, - poly_4_pos_y, - time_4_t); + printf("preRefined positions: %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f]\n", + poly_1_pos_x, + poly_1_pos_y, + time_1_t, + poly_2_pos_x, + poly_2_pos_y, + time_2_t, + poly_3_pos_x, + poly_3_pos_y, + time_3_t, + poly_4_pos_x, + poly_4_pos_y, + time_4_t); + } + #endif while (true) { @@ -1030,20 +1196,32 @@ TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") switch (z_solver.check(bounding_box_assumptions)) { case z3::sat: - { - printf(" sat\n"); + { + #ifdef DEBUG + { + printf(" sat\n"); + } + #endif refined_sat = true; break; } case z3::unsat: { - printf(" unsat\n"); + #ifdef DEBUG + { + printf(" unsat\n"); + } + #endif refined_sat = false; break; } case z3::unknown: { - printf(" unknown\n"); + #ifdef DEBUG + { + printf(" unknown\n"); + } + #endif break; } default: @@ -1070,6 +1248,7 @@ TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") printf("Variable:%s ", z_model[i].name().str().c_str()); } #endif + double value = z_model.get_const_interp(z_model[i]).as_double(); if (z_model[i].name().str() == "x_pos-0") @@ -1121,19 +1300,23 @@ TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") time_4_t = value; } } - printf("Refined positions: %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f]\n", - poly_1_pos_x, - poly_1_pos_y, - time_1_t, - poly_2_pos_x, - poly_2_pos_y, - time_2_t, - poly_3_pos_x, - poly_3_pos_y, - time_3_t, - poly_4_pos_x, - poly_4_pos_y, - time_4_t); + #ifdef DEBUG + { + printf("Refined positions: %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f]\n", + poly_1_pos_x, + poly_1_pos_y, + time_1_t, + poly_2_pos_x, + poly_2_pos_y, + time_2_t, + poly_3_pos_x, + poly_3_pos_y, + time_3_t, + poly_4_pos_x, + poly_4_pos_y, + time_4_t); + } + #endif } else { @@ -1142,21 +1325,25 @@ TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") } else { - printf("-------------------------------------------------------------------\n"); + #ifdef DEBUG + { + printf("-------------------------------------------------------------------\n"); + + _poly_1_pos_x = poly_1_pos_x; + _poly_1_pos_y = poly_1_pos_y; + _time_1_t = time_1_t; + _poly_2_pos_x = poly_2_pos_x; + _poly_2_pos_y = poly_2_pos_y; + _time_2_t = time_2_t; + _poly_3_pos_x = poly_3_pos_x; + _poly_3_pos_y = poly_3_pos_y; + _time_3_t = time_3_t; + _poly_4_pos_x = poly_4_pos_x; + _poly_4_pos_y = poly_4_pos_y; + _time_4_t = time_4_t; + } + #endif - _poly_1_pos_x = poly_1_pos_x; - _poly_1_pos_y = poly_1_pos_y; - _time_1_t = time_1_t; - _poly_2_pos_x = poly_2_pos_x; - _poly_2_pos_y = poly_2_pos_y; - _time_2_t = time_2_t; - _poly_3_pos_x = poly_3_pos_x; - _poly_3_pos_y = poly_3_pos_y; - _time_3_t = time_3_t; - _poly_4_pos_x = poly_4_pos_x; - _poly_4_pos_y = poly_4_pos_y; - _time_4_t = time_4_t; - last_solvable_bounding_box_size = bounding_box_size; break; } @@ -1167,25 +1354,31 @@ TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") break; } } + #ifdef DEBUG finish = clock(); + #endif REQUIRE(last_solvable_bounding_box_size > 0); - printf("Solvable bounding box: %d\n", last_solvable_bounding_box_size); + #ifdef DEBUG + { + printf("Solvable bounding box: %d\n", last_solvable_bounding_box_size); - printf("Final spatio-temporal positions: %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f]\n", - _poly_1_pos_x, - _poly_1_pos_y, - _time_1_t, - _poly_2_pos_x, - _poly_2_pos_y, - _time_2_t, - _poly_3_pos_x, - _poly_3_pos_y, - _time_3_t, - _poly_4_pos_x, - _poly_4_pos_y, - _time_4_t); + printf("Final spatio-temporal positions: %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f]\n", + _poly_1_pos_x, + _poly_1_pos_y, + _time_1_t, + _poly_2_pos_x, + _poly_2_pos_y, + _time_2_t, + _poly_3_pos_x, + _poly_3_pos_y, + _time_3_t, + _poly_4_pos_x, + _poly_4_pos_y, + _time_4_t); + } + #endif #ifdef DEBUG { @@ -1222,20 +1415,29 @@ TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]") preview_svg.draw(display_polygon_3, "red"); preview_svg.draw(display_polygon_4, "grey"); - preview_svg.Close(); + preview_svg.Close(); - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing sequential 4 ... finished\n"); + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing sequential 4 ... finished"); } -TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") -{ +//TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") +void sequential_test_5(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing sequential 5 ...\n"); + INFO("Testing sequential 5 ..."); + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -1244,26 +1446,35 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") for (int i = 0; i < 4; ++i) { - printf("i:%d\n", i); string name = "x_pos-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("i:%d\n", i); + printf("name: %s\n", name.c_str()); + } + #endif X_positions.push_back(expr(z_context.real_const(name.c_str()))); } for (int i = 0; i < 4; ++i) { string name = "y_pos-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif Y_positions.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_1.points.size(); ++i) { string name = "t_time-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T_times.push_back(expr(z_context.real_const(name.c_str()))); } @@ -1282,11 +1493,15 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") unreachable_polygons.push_back(unreachable_polygons_3); unreachable_polygons.push_back(unreachable_polygons_4); - printf("pp: %ld\n", unreachable_polygons[0].size()); - printf("pp: %ld\n", unreachable_polygons[1].size()); - printf("pp: %ld\n", unreachable_polygons[2].size()); - printf("pp: %ld\n", unreachable_polygons[3].size()); - + #ifdef DEBUG + { + printf("pp: %ld\n", unreachable_polygons[0].size()); + printf("pp: %ld\n", unreachable_polygons[1].size()); + printf("pp: %ld\n", unreachable_polygons[2].size()); + printf("pp: %ld\n", unreachable_polygons[3].size()); + } + #endif + introduce_SequentialPolygonWeakNonoverlapping(z_solver, z_context, X_positions, @@ -1296,11 +1511,11 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") unreachable_polygons); introduce_TemporalOrdering(z_solver, z_context, T_times, 16, polygons); - printf("Printing solver status:\n"); - cout << z_solver << "\n"; - #ifdef DEBUG { + printf("Printing solver status:\n"); + cout << z_solver << "\n"; + printf("Printing smt status:\n"); cout << z_solver.to_smt2() << "\n"; } @@ -1315,7 +1530,11 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") for (int bounding_box_size = 200; bounding_box_size > 10; bounding_box_size -= 4) { - printf("BB: %d\n", bounding_box_size); + #ifdef DEBUG + { + printf("BB: %d\n", bounding_box_size); + } + #endif z3::expr_vector bounding_box_assumptions(z_context); assume_BedBoundingBox(X_positions[0], Y_positions[0], polygons[0], bounding_box_size, bounding_box_size, bounding_box_assumptions); @@ -1328,20 +1547,32 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") switch (z_solver.check(bounding_box_assumptions)) { case z3::sat: - { - printf(" SATISFIABLE\n"); + { + #ifdef DEBUG + { + printf(" SATISFIABLE\n"); + } + #endif sat = true; break; } case z3::unsat: { - printf(" UNSATISFIABLE\n"); + #ifdef DEBUG + { + printf(" UNSATISFIABLE\n"); + } + #endif sat = false; break; } case z3::unknown: { - printf(" UNKNOWN\n"); + #ifdef DEBUG + { + printf(" UNKNOWN\n"); + } + #endif break; } default: @@ -1358,17 +1589,22 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") { printf("Printing model:\n"); cout << z_model << "\n"; + + printf("Printing interpretation:\n"); } #endif - printf("Printing interpretation:\n"); for (unsigned int i = 0; i < z_model.size(); ++i) { - printf("Variable:%s ", z_model[i].name().str().c_str()); - - cout << z_model.get_const_interp(z_model[i]).as_double() << "\n"; - double value = z_model.get_const_interp(z_model[i]).as_double(); - printf("value: %.3f\n", value); + #ifdef DEBUG + { + double value = z_model.get_const_interp(z_model[i]).as_double(); + + printf("Variable:%s ", z_model[i].name().str().c_str()); + cout << z_model.get_const_interp(z_model[i]).as_double() << "\n"; + printf("value: %.3f\n", value); + } + #endif Rational rational(z_model.get_const_interp(z_model[i]).numerator().as_int64(), z_model.get_const_interp(z_model[i]).denominator().as_int64()); @@ -1422,25 +1658,29 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") } } - printf("Times: %.3f, %.3f, %.3f, %3f\n", - time_1_t.as_double(), - time_2_t.as_double(), - time_3_t.as_double(), - time_4_t.as_double()); + #ifdef DEBUG + { + printf("Times: %.3f, %.3f, %.3f, %3f\n", + time_1_t.as_double(), + time_2_t.as_double(), + time_3_t.as_double(), + time_4_t.as_double()); - printf("preRefined positions: %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f]\n", - poly_1_pos_x.as_double(), - poly_1_pos_y.as_double(), - time_1_t.as_double(), - poly_2_pos_x.as_double(), - poly_2_pos_y.as_double(), - time_2_t.as_double(), - poly_3_pos_x.as_double(), - poly_3_pos_y.as_double(), - time_3_t.as_double(), - poly_4_pos_x.as_double(), - poly_4_pos_y.as_double(), - time_4_t.as_double()); + printf("preRefined positions: %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f]\n", + poly_1_pos_x.as_double(), + poly_1_pos_y.as_double(), + time_1_t.as_double(), + poly_2_pos_x.as_double(), + poly_2_pos_y.as_double(), + time_2_t.as_double(), + poly_3_pos_x.as_double(), + poly_3_pos_y.as_double(), + time_3_t.as_double(), + poly_4_pos_x.as_double(), + poly_4_pos_y.as_double(), + time_4_t.as_double()); + } + #endif while (true) { @@ -1480,20 +1720,32 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") switch (z_solver.check(bounding_box_assumptions)) { case z3::sat: - { - printf(" sat\n"); + { + #ifdef DEBUG + { + printf(" sat\n"); + } + #endif refined_sat = true; break; } case z3::unsat: { - printf(" unsat\n"); + #ifdef DEBUG + { + printf(" unsat\n"); + } + #endif refined_sat = false; break; } case z3::unknown: { - printf(" unknown\n"); + #ifdef DEBUG + { + printf(" unknown\n"); + } + #endif break; } default: @@ -1515,9 +1767,13 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") for (unsigned int i = 0; i < z_model.size(); ++i) { - printf("Variable:%s ", z_model[i].name().str().c_str()); - double value = z_model.get_const_interp(z_model[i]).as_double(); - printf("value: %.3f\n", value); + #ifdef DEBUG + { + double value = z_model.get_const_interp(z_model[i]).as_double(); + printf("Variable:%s ", z_model[i].name().str().c_str()); + printf("value: %.3f\n", value); + } + #endif Rational rational(z_model.get_const_interp(z_model[i]).numerator().as_int64(), z_model.get_const_interp(z_model[i]).denominator().as_int64()); @@ -1570,19 +1826,23 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") time_4_t = rational; } } - printf("Refined positions: %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f]\n", - poly_1_pos_x.as_double(), - poly_1_pos_y.as_double(), - time_1_t.as_double(), - poly_2_pos_x.as_double(), - poly_2_pos_y.as_double(), - time_2_t.as_double(), - poly_3_pos_x.as_double(), - poly_3_pos_y.as_double(), - time_3_t.as_double(), - poly_4_pos_x.as_double(), - poly_4_pos_y.as_double(), - time_4_t.as_double()); + #ifdef DEBUG + { + printf("Refined positions: %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f]\n", + poly_1_pos_x.as_double(), + poly_1_pos_y.as_double(), + time_1_t.as_double(), + poly_2_pos_x.as_double(), + poly_2_pos_y.as_double(), + time_2_t.as_double(), + poly_3_pos_x.as_double(), + poly_3_pos_y.as_double(), + time_3_t.as_double(), + poly_4_pos_x.as_double(), + poly_4_pos_y.as_double(), + time_4_t.as_double()); + } + #endif } else { @@ -1591,8 +1851,11 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") } else { - printf("-------------------------------------------------------------------\n"); - + #ifdef DEBUG + { + printf("-------------------------------------------------------------------\n"); + } + #endif _poly_1_pos_x = poly_1_pos_x; _poly_1_pos_y = poly_1_pos_y; _time_1_t = time_1_t; @@ -1616,25 +1879,30 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") break; } } + #ifdef DEBUG finish = clock(); + #endif REQUIRE(last_solvable_bounding_box_size > 0); - - printf("Solvable bounding box: %d\n", last_solvable_bounding_box_size); - printf("Final spatio-temporal positions: %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f]\n", - _poly_1_pos_x.as_double(), - _poly_1_pos_y.as_double(), - _time_1_t.as_double(), - _poly_2_pos_x.as_double(), - _poly_2_pos_y.as_double(), - _time_2_t.as_double(), - _poly_3_pos_x.as_double(), - _poly_3_pos_y.as_double(), - _time_3_t.as_double(), - _poly_4_pos_x.as_double(), - _poly_4_pos_y.as_double(), - _time_4_t.as_double()); - + #ifdef DEBUG + { + printf("Solvable bounding box: %d\n", last_solvable_bounding_box_size); + + printf("Final spatio-temporal positions: %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f], %.3f, %.3f [%.3f]\n", + _poly_1_pos_x.as_double(), + _poly_1_pos_y.as_double(), + _time_1_t.as_double(), + _poly_2_pos_x.as_double(), + _poly_2_pos_y.as_double(), + _time_2_t.as_double(), + _poly_3_pos_x.as_double(), + _poly_3_pos_y.as_double(), + _time_3_t.as_double(), + _poly_4_pos_x.as_double(), + _poly_4_pos_y.as_double(), + _time_4_t.as_double()); + } + #endif #ifdef DEBUG { @@ -1688,21 +1956,29 @@ TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]") preview_svg.Close(); - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing sequential 5 ... finished\n"); + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing sequential 5 ... finished"); } TEST_CASE("Sequential test 6", "[Sequential Arrangement Core]") -{ +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 6 ...\n"); + INFO("Testing polygon 6 ..."); + #ifdef DEBUG start = clock(); + #endif SolverConfiguration solver_configuration; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); vector polygons; vector unreachable_polygons; @@ -1758,9 +2034,9 @@ TEST_CASE("Sequential test 6", "[Sequential Arrangement Core]") #ifdef DEBUG { - for (int j = 0; j < unreachable_polygons_1.size(); ++j) + for (unsigned int j = 0; j < unreachable_polygons_1.size(); ++j) { - for (int k = 0; k < unreachable_polygons_1[j].points.size(); ++k) + for (unsigned int k = 0; k < unreachable_polygons_1[j].points.size(); ++k) { printf(" Ppxy: %d, %d\n", unreachable_polygons_1[j].points[k].x(), unreachable_polygons_1[j].points[k].y()); } @@ -1793,20 +2069,28 @@ TEST_CASE("Sequential test 6", "[Sequential Arrangement Core]") remaining_polygons); REQUIRE(optimized); - printf("----> Optimization finished <----\n"); + #ifdef DEBUG + { + printf("----> Optimization finished <----\n"); + } + #endif if (optimized) { - printf("Polygon positions:\n"); - for (unsigned int i = 0; i < decided_polygons.size(); ++i) + #ifdef DEBUG { - printf(" [%d] %.3f, %.3f (%.3f)\n", decided_polygons[i], poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double(), times_T[decided_polygons[i]].as_double()); - } - printf("Remaining polygons: %ld\n", remaining_polygons.size()); - for (unsigned int i = 0; i < remaining_polygons.size(); ++i) - { - printf(" %d\n", remaining_polygons[i]); + printf("Polygon positions:\n"); + for (unsigned int i = 0; i < decided_polygons.size(); ++i) + { + printf(" [%d] %.3f, %.3f (%.3f)\n", decided_polygons[i], poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double(), times_T[decided_polygons[i]].as_double()); + } + printf("Remaining polygons: %ld\n", remaining_polygons.size()); + for (unsigned int i = 0; i < remaining_polygons.size(); ++i) + { + printf(" %d\n", remaining_polygons[i]); + } } + #endif SVG preview_svg("sequential_test_6.svg"); @@ -1817,7 +2101,7 @@ TEST_CASE("Sequential test 6", "[Sequential Arrangement Core]") #ifdef DEBUG { printf("----> %.3f,%.3f\n", poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double()); - for (int k = 0; k < polygons[decided_polygons[i]].points.size(); ++k) + for (unsigned int k = 0; k < polygons[decided_polygons[i]].points.size(); ++k) { printf(" xy: %d, %d\n", polygons[decided_polygons[i]].points[k].x(), polygons[decided_polygons[i]].points[k].y()); } @@ -1916,16 +2200,24 @@ TEST_CASE("Sequential test 6", "[Sequential Arrangement Core]") } else { - printf("Polygon optimization FAILED.\n"); + #ifdef DEBUG + { + printf("Polygon optimization FAILED.\n"); + } + #endif } vector next_polygons; vector next_unreachable_polygons; - for (unsigned int i = 0; i < polygon_index_map.size(); ++i) + #ifdef DEBUG { - printf(" %d\n", polygon_index_map[i]); + for (unsigned int i = 0; i < polygon_index_map.size(); ++i) + { + printf(" %d\n", polygon_index_map[i]); + } } + #endif for (unsigned int i = 0; i < remaining_polygons.size(); ++i) { next_polygons.push_back(polygons[remaining_polygons[i]]); @@ -1946,23 +2238,33 @@ TEST_CASE("Sequential test 6", "[Sequential Arrangement Core]") } while (!remaining_polygons.empty()); + #ifdef DEBUG finish = clock(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing sequential 6 ... finished\n"); + #endif + + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing sequential 6 ... finished"); } TEST_CASE("Sequential test 7", "[Sequential Arrangement Core]") -{ +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 7 ...\n"); + INFO("Testing polygon 7 ..."); + #ifdef DEBUG start = clock(); + #endif SolverConfiguration solver_configuration; - solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE, SEQ_PRUSA_MK3S_Y_SIZE}); + solver_configuration.plate_bounding_box = BoundingBox({0,0}, {SEQ_PRUSA_MK3S_X_SIZE / SEQ_SLICER_SCALE_FACTOR, SEQ_PRUSA_MK3S_Y_SIZE / SEQ_SLICER_SCALE_FACTOR}); vector polygons; vector > unreachable_polygons; @@ -1998,9 +2300,9 @@ TEST_CASE("Sequential test 7", "[Sequential Arrangement Core]") #ifdef DEBUG { - for (int j = 0; j < unreachable_polygons_1.size(); ++j) + for (unsigned int j = 0; j < unreachable_polygons_1.size(); ++j) { - for (int k = 0; k < unreachable_polygons_1[j].points.size(); ++k) + for (unsigned int k = 0; k < unreachable_polygons_1[j].points.size(); ++k) { printf(" Ppxy: %d, %d\n", unreachable_polygons_1[j].points[k].x(), unreachable_polygons_1[j].points[k].y()); } @@ -2033,20 +2335,28 @@ TEST_CASE("Sequential test 7", "[Sequential Arrangement Core]") remaining_polygons); REQUIRE(optimized); - printf("----> Optimization finished <----\n"); + #ifdef DEBUG + { + printf("----> Optimization finished <----\n"); + } + #endif if (optimized) { - printf("Polygon positions:\n"); - for (unsigned int i = 0; i < decided_polygons.size(); ++i) + #ifdef DEBUG { - printf(" [%d] %.3f, %.3f (%.3f)\n", decided_polygons[i], poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double(), times_T[decided_polygons[i]].as_double()); - } - printf("Remaining polygons: %ld\n", remaining_polygons.size()); - for (unsigned int i = 0; i < remaining_polygons.size(); ++i) - { - printf(" %d\n", remaining_polygons[i]); + printf("Polygon positions:\n"); + for (unsigned int i = 0; i < decided_polygons.size(); ++i) + { + printf(" [%d] %.3f, %.3f (%.3f)\n", decided_polygons[i], poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double(), times_T[decided_polygons[i]].as_double()); + } + printf("Remaining polygons: %ld\n", remaining_polygons.size()); + for (unsigned int i = 0; i < remaining_polygons.size(); ++i) + { + printf(" %d\n", remaining_polygons[i]); + } } + #endif SVG preview_svg("sequential_test_7.svg"); @@ -2057,7 +2367,7 @@ TEST_CASE("Sequential test 7", "[Sequential Arrangement Core]") #ifdef DEBUG { printf("----> %.3f,%.3f\n", poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[decided_polygons[i]].as_double()); - for (int k = 0; k < polygons[decided_polygons[i]].points.size(); ++k) + for (unsigned int k = 0; k < polygons[decided_polygons[i]].points.size(); ++k) { printf(" xy: %d, %d\n", polygons[decided_polygons[i]].points[k].x(), polygons[decided_polygons[i]].points[k].y()); } @@ -2068,7 +2378,7 @@ TEST_CASE("Sequential test 7", "[Sequential Arrangement Core]") { #ifdef DEBUG { - for (int k = 0; k < unreachable_polygons[decided_polygons[i]][j].points.size(); ++k) + for (unsigned int k = 0; k < unreachable_polygons[decided_polygons[i]][j].points.size(); ++k) { printf(" Pxy: %d, %d\n", unreachable_polygons[decided_polygons[i]][j].points[k].x(), unreachable_polygons[decided_polygons[i]][j].points[k].y()); } @@ -2166,16 +2476,24 @@ TEST_CASE("Sequential test 7", "[Sequential Arrangement Core]") } else { - printf("Polygon optimization FAILED.\n"); + #ifdef DEBUG + { + printf("Polygon optimization FAILED.\n"); + } + #endif } vector next_polygons; vector > next_unreachable_polygons; - for (unsigned int i = 0; i < polygon_index_map.size(); ++i) + #ifdef DEBUG { - printf(" %d\n", polygon_index_map[i]); + for (unsigned int i = 0; i < polygon_index_map.size(); ++i) + { + printf(" %d\n", polygon_index_map[i]); + } } + #endif for (unsigned int i = 0; i < remaining_polygons.size(); ++i) { next_polygons.push_back(polygons[remaining_polygons[i]]); @@ -2196,10 +2514,16 @@ TEST_CASE("Sequential test 7", "[Sequential Arrangement Core]") } while (!remaining_polygons.empty()); + #ifdef DEBUG finish = clock(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing sequential 7 ... finished\n"); + #endif + + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + INFO("Testing sequential 7 ... finished"); } diff --git a/src/libseqarrange/test/seq_test_sequential.hpp b/src/libseqarrange/test/seq_test_sequential.hpp index 13cac6b4f1..2c8dd90c74 100644 --- a/src/libseqarrange/test/seq_test_sequential.hpp +++ b/src/libseqarrange/test/seq_test_sequential.hpp @@ -1,6 +1,6 @@ /*================================================================*/ /* - * Author: Pavel Surynek, 2023 - 2024 + * Author: Pavel Surynek, 2023 - 2025 * Company: Prusa Research * * File: seq_test_sequential.hpp