diff --git a/src/libseqarrange/CMakeLists.txt b/src/libseqarrange/CMakeLists.txt index f0d393e1c0..2e14ceca48 100644 --- a/src/libseqarrange/CMakeLists.txt +++ b/src/libseqarrange/CMakeLists.txt @@ -15,20 +15,20 @@ target_link_libraries(sequential_decimator PRIVATE libseqarrange) -#if (SLIC3R_BUILD_TESTS) -# find_package(Catch2 3.8 REQUIRED) +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) -# target_include_directories(libseqarrange_tests PRIVATE src ) -# target_link_libraries(libseqarrange_tests PRIVATE Catch2::Catch2WithMain libseqarrange) + 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) -# set(_catch_args "exclude:[NotWorking] exclude:[Slow]") -# list(APPEND _catch_args "${CATCH_EXTRA_ARGS}") -# add_test(NAME libseqarrange_tests -# COMMAND libseqarrange_tests ${_catch_args} -# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + set(_catch_args "exclude:[NotWorking] exclude:[Slow]") + list(APPEND _catch_args "${CATCH_EXTRA_ARGS}") + add_test(NAME libseqarrange_tests + COMMAND libseqarrange_tests ${_catch_args} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -#endif() +endif() 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 fa729c42f5..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,61 +547,104 @@ 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; - REQUIRE(scheduled_object.x >= 0); - REQUIRE(scheduled_object.x <= solver_configuration.x_plate_bounding_box_size * SEQ_SLICER_SCALE_FACTOR); - REQUIRE(scheduled_object.y >= 0); - REQUIRE(scheduled_object.y <= solver_configuration.y_plate_bounding_box_size * SEQ_SLICER_SCALE_FACTOR); + #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); + REQUIRE(scheduled_object.y <= solver_configuration.plate_bounding_box.max.y() * SEQ_SLICER_SCALE_FACTOR); } } } 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,141 +655,257 @@ 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; - REQUIRE(scheduled_object.x >= 0); - REQUIRE(scheduled_object.x <= solver_configuration.x_plate_bounding_box_size * SEQ_SLICER_SCALE_FACTOR); - REQUIRE(scheduled_object.y >= 0); - REQUIRE(scheduled_object.y <= solver_configuration.y_plate_bounding_box_size * SEQ_SLICER_SCALE_FACTOR); + #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); + REQUIRE(scheduled_object.y <= solver_configuration.plate_bounding_box.max.y() * SEQ_SLICER_SCALE_FACTOR); } } } 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); @@ -738,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); @@ -810,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) { @@ -858,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()); @@ -902,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 22a2616104..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 @@ -56,44 +56,56 @@ const int SEQ_PRUSA_MK3S_Y_SIZE = 2100; TEST_CASE("Polygon test 1", "[Polygon]") { - printf("Testing polygon 1 ...\n"); + INFO("Testing polygon 1 ..."); Polygon polygon_1 = {{-1000000, -1000000}, {1000000, -1000000}, {1000000, 1000000}, {-1000000, 1000000} }; - for (unsigned int i = 0; i < polygon_1.size(); ++i) + #ifdef DEBUG { - Point point = polygon_1[i]; - printf("%d,%d\n", point.x(), point.y()); + for (unsigned int i = 0; i < polygon_1.size(); ++i) + { + Point point = polygon_1[i]; + printf("%d,%d\n", point.x(), point.y()); + } } + #endif REQUIRE(polygon_1.size() > 0); - printf("Testing polygon 1 ... finished\n"); + INFO("Testing polygon 1 ... finished"); } TEST_CASE("Polygon test 2", "[Polygon]") { - printf("Testing polygon 2 ...\n"); + INFO("Testing polygon 2 ..."); for (unsigned int k = 0; k < PRUSA_PART_POLYGONS.size(); ++k) { - printf("k = %d\n", k); + #ifdef DEBUG + { + printf("k = %d\n", k); + } + #endif const Polygon &polygon_1 = PRUSA_PART_POLYGONS[k]; Polygon hull_1 = convex_hull(polygon_1); - - for (unsigned int i = 0; i < polygon_1.size(); ++i) + + #ifdef DEBUG { - const Point &point = polygon_1[i]; - printf("poly %d: %d,%d\n", i, point.x(), point.y()); - } - printf("\n"); + for (unsigned int i = 0; i < polygon_1.size(); ++i) + { + const Point &point = polygon_1[i]; + printf("poly %d: %d,%d\n", i, point.x(), point.y()); + } + printf("\n"); - for (unsigned int i = 0; i < hull_1.size(); ++i) - { - const Point &point = hull_1[i]; - printf("hull %d: %d,%d\n", i, point.x(), point.y()); + for (unsigned int i = 0; i < hull_1.size(); ++i) + { + const Point &point = hull_1[i]; + printf("hull %d: %d,%d\n", i, point.x(), point.y()); + } } + #endif REQUIRE(hull_1.size() > 0); @@ -102,26 +114,49 @@ TEST_CASE("Polygon test 2", "[Polygon]") const Point &point_1 = hull_1[0]; const Point &point_2 = hull_1[1]; - Point v = (point_2 - point_1); //.normalized(); - printf("v: %d,%d\n", v.x(), v.y()); - cout << v << endl; - - Point u = v.normalized(); - printf("u: %d,%d\n", u.x(), u.y()); - cout << u << endl; + Point v = (point_2 - point_1); //.normalized(); + #ifdef DEBUG + { + printf("v: %d,%d\n", v.x(), v.y()); + cout << v << endl; + } + #endif + + #ifdef DEBUG + { + Point u = v.normalized(); + printf("u: %d,%d\n", u.x(), u.y()); + cout << u << endl; + } + #endif - printf("Ortho:\n"); Point n(v.y(), -v.x()); - cout << n << endl; + + #ifdef DEBUG + { + printf("Ortho:\n"); + cout << n << endl; + } + #endif coord_t d = n.x() * point_1.x() + n.y() * point_1.y(); - printf("%d\n", d); - cout << d << endl; + + #ifdef DEBUG + { + printf("%d\n", d); + cout << d << endl; + } + #endif auto is_inside=[&](const Point &p) { coord_t d1 = n.x() * p.x() + n.y() * p.y() - d; - printf("d1: %d\n", d1); + + #ifdef DEBUG + { + printf("d1: %d\n", d1); + } + #endif if (d1 >= 0) { @@ -133,23 +168,39 @@ TEST_CASE("Polygon test 2", "[Polygon]") } }; - bool ins1 = is_inside(point_1); - printf("%s\n", ins1 ? "yes" : "no"); + bool ins1 = is_inside(point_1); + #ifdef DEBUG + { + printf("%s\n", ins1 ? "yes" : "no"); + } + #endif REQUIRE(ins1); bool ins2 = is_inside(point_2); - printf("%s\n", ins2 ? "yes" : "no"); + #ifdef DEBUG + { + printf("%s\n", ins2 ? "yes" : "no"); + } + #endif REQUIRE(ins2); - bool ins3 = is_inside(point_1 + point_2); - printf("%s\n", ins3 ? "yes" : "no"); + #ifdef DEBUG + { + bool ins3 = is_inside(point_1 + point_2); + printf("%s\n", ins3 ? "yes" : "no"); + } + #endif - bool ins4 = is_inside(point_1 - point_2); - printf("%s\n", ins4 ? "yes" : "no"); + #ifdef DEBUG + { + bool ins4 = is_inside(point_1 - point_2); + printf("%s\n", ins4 ? "yes" : "no"); + } + #endif } } - printf("Testing polygon 2 ... finished\n"); + INFO("Testing polygon 2 ... finished"); } @@ -157,12 +208,17 @@ int line_count = 4; Line lines[] = {{Point(100,100), Point(200,200)}, {Point(200,100), Point(100,200)}, {Point(0,0), Point(100,10)}, {Point(50,0), Point(60,100)} }; TEST_CASE("Polygon test 3", "[Polygon]") -{ - clock_t start, finish; - - printf("Testing polygon 3 ...\n"); +{ + #ifdef DEBUG + clock_t start, finish; + #endif + + INFO("Testing polygon 3 ..."); + + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -171,26 +227,35 @@ TEST_CASE("Polygon test 3", "[Polygon]") for (int i = 0; i < line_count; ++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 < line_count; ++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 (int i = 0; i < line_count; ++i) { string name = "t_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T_parameters.push_back(expr(z_context.real_const(name.c_str()))); } @@ -234,18 +299,30 @@ TEST_CASE("Polygon test 3", "[Polygon]") 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 return; break; } case z3::unknown: { - printf(" UNKNOWN\n"); + #ifdef DEBUG + { + printf(" UNKNOWN\n"); + } + #endif break; } default: @@ -264,60 +341,68 @@ TEST_CASE("Polygon test 3", "[Polygon]") } #endif - finish = clock(); + #ifdef DEBUG + finish = clock(); + #endif - printf("Printing interpretation:\n"); - for (unsigned int i = 0; i < z_model.size(); ++i) + #ifdef DEBUG { - printf("Variable:%s ", z_model[i].name().str().c_str()); - - #ifdef DEBUG + printf("Printing interpretation:\n"); + for (unsigned int i = 0; i < z_model.size(); ++i) { - 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("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); + printf("value: %.3f\n", value); - cout << float(z_model[i]) << "\n"; + 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; + 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; + } + } } - case Z3_L_TRUE: - { - printf(" value: TRUE\n"); - break; - } - case Z3_L_UNDEF: - { - printf(" value: UNDEF\n"); - break; - } - default: - { - break; - } - } - } - #endif + } + + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); } - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 3 ... finished\n"); + #endif + + INFO("Testing polygon 3 ... finished"); } TEST_CASE("Polygon test 4", "[Polygon]") -{ +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 4 ...\n"); + INFO("Testing polygon 4 ..."); + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -326,26 +411,35 @@ TEST_CASE("Polygon test 4", "[Polygon]") for (int i = 0; i < line_count; ++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 < line_count; ++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 (int i = 0; i < line_count; ++i) { string name = "t_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T_parameters.push_back(expr(z_context.real_const(name.c_str()))); } @@ -373,11 +467,15 @@ TEST_CASE("Polygon test 4", "[Polygon]") T_parameters[3], lines[3]); - 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; @@ -386,18 +484,30 @@ TEST_CASE("Polygon test 4", "[Polygon]") 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 return; break; } case z3::unknown: { - printf(" UNKNOWN\n"); + #ifdef DEBUG + { + printf(" UNKNOWN\n"); + } + #endif break; } default: @@ -407,50 +517,54 @@ TEST_CASE("Polygon test 4", "[Polygon]") } REQUIRE(sat); - z3::model z_model(z_solver.get_model()); - printf("Printing model:\n"); - cout << z_model << "\n"; + #ifdef DEBUG + { + z3::model z_model(z_solver.get_model()); + printf("Printing model:\n"); + cout << z_model << "\n"; - finish = clock(); - - printf("Printing interpretation:\n"); - for (unsigned int i = 0; i < z_model.size(); ++i) - { - printf("Variable:%s ", z_model[i].name().str().c_str()); + finish = clock(); + + 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(); + 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); + printf("value: %.3f\n", value); - 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"); + 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; - } - default: - { + } + case Z3_L_TRUE: + { + printf(" value: TRUE\n"); break; + } + case Z3_L_UNDEF: + { + printf(" value: UNDEF\n"); + break; + } + default: + { + break; + } + } } - } + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); } - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 4 ... finished\n"); + #endif + + INFO("Testing polygon 4 ... finished"); } @@ -459,12 +573,16 @@ Line poly_lines[] = {{Point(100,100), Point(200,100)}, {Point(200,100), Point(20 TEST_CASE("Polygon test 5", "[Polygon]") -{ +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 5 ...\n"); + INFO("Testing polygon 5 ..."); + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -472,18 +590,24 @@ TEST_CASE("Polygon test 5", "[Polygon]") for (int i = 0; i < poly_line_count; ++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 < poly_line_count; ++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()))); } @@ -533,18 +657,30 @@ TEST_CASE("Polygon test 5", "[Polygon]") 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 return; break; } case z3::unknown: { - printf(" UNKNOWN\n"); + #ifdef DEBUG + { + printf(" UNKNOWN\n"); + } + #endif break; } default: @@ -562,22 +698,25 @@ TEST_CASE("Polygon test 5", "[Polygon]") } #endif - finish = clock(); + #ifdef DEBUG + finish = clock(); + #endif - printf("Printing interpretation:\n"); - for (unsigned int i = 0; i < z_model.size(); ++i) + #ifdef DEBUG { - printf("Variable:%s ", z_model[i].name().str().c_str()); + printf("Printing interpretation:\n"); - #ifdef DEBUG + 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); - + cout << float(z_model[i]) << "\n"; - + switch (z_model.get_const_interp(z_model[i]).bool_value()) { case Z3_L_FALSE: @@ -601,11 +740,11 @@ TEST_CASE("Polygon test 5", "[Polygon]") } } } - #endif - } - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 5 ... finished\n"); + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + + INFO("Testing polygon 5 ... finished"); } namespace { @@ -614,13 +753,18 @@ namespace { } -TEST_CASE("Polygon test 6", "[Polygon]") -{ +//TEST_CASE("Polygon test 6", "[Polygon]") +void polygon_test_6(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 6 ...\n"); + INFO("Testing polygon 6 ..."); + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -628,18 +772,24 @@ TEST_CASE("Polygon test 6", "[Polygon]") for (int i = 0; i < poly_line_count; ++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 < poly_line_count; ++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()))); } @@ -669,18 +819,30 @@ TEST_CASE("Polygon test 6", "[Polygon]") 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 return; break; } case z3::unknown: { - printf(" UNKNOWN\n"); + #ifdef DEBUG + { + printf(" UNKNOWN\n"); + } + #endif break; } default: @@ -699,22 +861,23 @@ TEST_CASE("Polygon test 6", "[Polygon]") } #endif - finish = clock(); + #ifdef DEBUG + finish = clock(); + #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"; - - z3::expr valo_1 = z_model.get_const_interp(z_model[i]); - z3::expr deco_1 = expr(z_context.real_const("deco_1")); - - z3::expr lino_1 = (valo_1 * deco_1 == 0); - - #ifdef DEBUG + #ifdef DEBUG + { + printf("Printing interpretation:\n"); + + for (unsigned int i = 0; i < z_model.size(); ++i) { - printf("value: %.3f\n", value); + printf("Variable:%s ", z_model[i].name().str().c_str()); + cout << z_model.get_const_interp(z_model[i]).as_double() << "\n"; + + z3::expr valo_1 = z_model.get_const_interp(z_model[i]); + z3::expr deco_1 = expr(z_context.real_const("deco_1")); + + z3::expr lino_1 = (valo_1 * deco_1 == 0); cout << float(z_model[i]) << "\n"; @@ -741,11 +904,11 @@ TEST_CASE("Polygon test 6", "[Polygon]") } } } - #endif + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); } - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 6 ... finished\n"); + #endif + + INFO("Testing polygon 6 ... finished"); } @@ -754,12 +917,16 @@ Polygon polygon_2 = {{0, 0}, {150, 0}, {150, 50}, {75, 120}, {0, 50} }; TEST_CASE("Polygon test 7", "[Polygon]") -{ +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 7 ...\n"); + INFO("Testing polygon 7 ..."); + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -769,34 +936,46 @@ TEST_CASE("Polygon test 7", "[Polygon]") for (int i = 0; i < 2; ++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 < 2; ++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 = "t1_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T1_parameters.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_2.points.size(); ++i) { string name = "t2_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T2_parameters.push_back(expr(z_context.real_const(name.c_str()))); } @@ -830,18 +1009,30 @@ TEST_CASE("Polygon test 7", "[Polygon]") 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 return; break; } case z3::unknown: { - printf(" UNKNOWN\n"); + #ifdef DEBUG + { + printf(" UNKNOWN\n"); + } + #endif break; } default: @@ -860,36 +1051,47 @@ TEST_CASE("Polygon test 7", "[Polygon]") } #endif - finish = clock(); - - double poly_1_pos_x, poly_1_pos_y, poly_2_pos_x, poly_2_pos_y; - poly_1_pos_x = poly_1_pos_y = poly_2_pos_x = poly_2_pos_y = 0.0; + #ifdef DEBUG + finish = clock(); + + double poly_1_pos_x, poly_1_pos_y, poly_2_pos_x, poly_2_pos_y; + poly_1_pos_x = poly_1_pos_y = poly_2_pos_x = poly_2_pos_y = 0.0; + #endif + + #ifdef DEBUG + { + 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()); + #ifdef DEBUG + { + double value = z_model.get_const_interp(z_model[i]).as_double(); - 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); + 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); - if (z_model[i].name().str() == "x_pos-0") - { - poly_1_pos_x = value; + if (z_model[i].name().str() == "x_pos-0") + { + poly_1_pos_x = value; + } + else if (z_model[i].name().str() == "y_pos-0") + { + poly_1_pos_y = value; + } + else if (z_model[i].name().str() == "x_pos-1") + { + poly_2_pos_x = value; + } + else if (z_model[i].name().str() == "y_pos-1") + { + poly_2_pos_y = value; + } } - else if (z_model[i].name().str() == "y_pos-0") - { - poly_1_pos_y = value; - } - else if (z_model[i].name().str() == "x_pos-1") - { - poly_2_pos_x = value; - } - else if (z_model[i].name().str() == "y_pos-1") - { - poly_2_pos_y = value; - } + #endif #ifdef DEBUG { @@ -922,7 +1124,11 @@ TEST_CASE("Polygon test 7", "[Polygon]") } - printf("Positions: %.3f, %.3f, %.3f, %.3f\n", poly_1_pos_x, poly_1_pos_y, poly_2_pos_x, poly_2_pos_y); + #ifdef DEBUG + { + printf("Positions: %.3f, %.3f, %.3f, %.3f\n", poly_1_pos_x, poly_1_pos_y, poly_2_pos_x, poly_2_pos_y); + } + #endif #ifdef DEBUG { @@ -931,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); } } @@ -946,10 +1152,14 @@ TEST_CASE("Polygon test 7", "[Polygon]") } #endif - preview_svg.Close(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 7 ... finished\n"); + preview_svg.Close(); + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + + INFO("Testing polygon 7 ... finished"); } @@ -982,13 +1192,18 @@ Polygon scale_UP(const Polygon &polygon, double x_pos, double y_pos) Polygon polygon_3 = {{40, 0}, {80, 40}, {40, 80}, {0, 40}}; //Polygon polygon_3 = {{20, 0}, {40, 0}, {60, 30}, {30, 50}, {0, 30}}; -TEST_CASE("Polygon test 8", "[Polygon]") -{ +//TEST_CASE("Polygon test 8", "[Polygon]") +void polygon_test_8(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 8 ...\n"); + INFO("Testing polygon 8 ..."); + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -999,42 +1214,57 @@ TEST_CASE("Polygon test 8", "[Polygon]") for (int i = 0; i < 3; ++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 < 3; ++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 = "t1_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T1_parameters.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_2.points.size(); ++i) { string name = "t2_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T2_parameters.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_3.points.size(); ++i) { string name = "t3_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T3_parameters.push_back(expr(z_context.real_const(name.c_str()))); } @@ -1122,21 +1352,33 @@ TEST_CASE("Polygon test 8", "[Polygon]") switch (z_solver.check(decision_box_assumptions)) { case z3::sat: - { - printf(" SATISFIABLE\n"); + { + #ifdef DEBUG + { + printf(" SATISFIABLE\n"); + } + #endif last_solvable_decision_box_size = decision_box_size; 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: @@ -1155,15 +1397,23 @@ TEST_CASE("Polygon test 8", "[Polygon]") 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") { @@ -1194,44 +1444,20 @@ TEST_CASE("Polygon test 8", "[Polygon]") 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(); + #endif REQUIRE(last_solvable_decision_box_size > 0); - printf("Solvable decision box: %d\n", last_solvable_decision_box_size); - printf("Positions: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", poly_1_pos_x, poly_1_pos_y, poly_2_pos_x, poly_2_pos_y, poly_3_pos_x, poly_3_pos_y); + #ifdef DEBUG + { + printf("Solvable decision box: %d\n", last_solvable_decision_box_size); + printf("Positions: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", poly_1_pos_x, poly_1_pos_y, poly_2_pos_x, poly_2_pos_y, poly_3_pos_x, poly_3_pos_y); + } + #endif #ifdef DEBUG { @@ -1241,7 +1467,8 @@ TEST_CASE("Polygon test 8", "[Polygon]") 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 @@ -1250,25 +1477,34 @@ TEST_CASE("Polygon test 8", "[Polygon]") 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"); - preview_svg.Close(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 8 ... finished\n"); + preview_svg.Close(); + + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + + INFO("Testing polygon 8 ... finished"); } TEST_CASE("Polygon test 9", "[Polygon]") -{ +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 9 ...\n"); + INFO("Testing polygon 9 ..."); + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -1279,42 +1515,57 @@ TEST_CASE("Polygon test 9", "[Polygon]") for (int i = 0; i < 3; ++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 < 3; ++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 = "t1_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T1_parameters.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_2.points.size(); ++i) { string name = "t2_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T2_parameters.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_3.points.size(); ++i) { string name = "t3_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T3_parameters.push_back(expr(z_context.real_const(name.c_str()))); } @@ -1402,21 +1653,33 @@ TEST_CASE("Polygon test 9", "[Polygon]") switch (z_solver.check(bounding_box_assumptions)) { case z3::sat: - { - printf(" SATISFIABLE\n"); + { + #ifdef DEBUG + { + printf(" SATISFIABLE\n"); + } + #endif last_solvable_bounding_box_size = bounding_box_size; 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: @@ -1435,15 +1698,23 @@ TEST_CASE("Polygon test 9", "[Polygon]") 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") { @@ -1475,41 +1746,19 @@ 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(); + #endif - REQUIRE(last_solvable_bounding_box_size > 0); - printf("Solvable bounding box: %d\n", last_solvable_bounding_box_size); - printf("Positions: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", poly_1_pos_x, poly_1_pos_y, poly_2_pos_x, poly_2_pos_y, poly_3_pos_x, poly_3_pos_y); + REQUIRE(last_solvable_bounding_box_size > 0); + + #ifdef DEBUG + { + printf("Solvable bounding box: %d\n", last_solvable_bounding_box_size); + printf("Positions: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", poly_1_pos_x, poly_1_pos_y, poly_2_pos_x, poly_2_pos_y, poly_3_pos_x, poly_3_pos_y); + } + #endif #ifdef DEBUG { @@ -1534,22 +1783,31 @@ TEST_CASE("Polygon test 9", "[Polygon]") preview_svg.draw(display_polygon_2, "blue"); preview_svg.draw(display_polygon_3, "red"); - preview_svg.Close(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 9 ... finished\n"); + preview_svg.Close(); + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + + INFO("Testing polygon 9 ... finished"); } Polygon polygon_4 = {{20, 0}, {40, 0}, {60, 30}, {30, 50}, {0, 30}}; -TEST_CASE("Polygon test 10", "[Polygon]") -{ +//TEST_CASE("Polygon test 10", "[Polygon]") +void polygon_test_10(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 10 ...\n"); + INFO("Testing polygon 10 ..."); + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -1561,50 +1819,68 @@ TEST_CASE("Polygon test 10", "[Polygon]") 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 = "t1_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T1_parameters.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_2.points.size(); ++i) { string name = "t2_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T2_parameters.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_3.points.size(); ++i) { string name = "t3_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T3_parameters.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_4.points.size(); ++i) { string name = "t4_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T4_parameters.push_back(expr(z_context.real_const(name.c_str()))); } @@ -1650,21 +1926,33 @@ TEST_CASE("Polygon test 10", "[Polygon]") switch (z_solver.check(bounding_box_assumptions)) { case z3::sat: - { - printf(" SATISFIABLE\n"); + { + #ifdef DEBUG + { + printf(" SATISFIABLE\n"); + } + #endif last_solvable_bounding_box_size = bounding_box_size; 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: @@ -1683,16 +1971,25 @@ TEST_CASE("Polygon test 10", "[Polygon]") 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") { poly_1_pos_x = value; @@ -1731,50 +2028,26 @@ TEST_CASE("Polygon test 10", "[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(); + #endif REQUIRE(last_solvable_bounding_box_size > 0); - printf("Solvable bounding box: %d\n", last_solvable_bounding_box_size); - printf("Positions: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", 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); + #ifdef DEBUG + { + printf("Solvable bounding box: %d\n", last_solvable_bounding_box_size); + printf("Positions: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", 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); + } + #endif #ifdef DEBUG { @@ -1801,20 +2074,29 @@ TEST_CASE("Polygon test 10", "[Polygon]") preview_svg.draw(display_polygon_3, "red"); preview_svg.draw(display_polygon_4, "grey"); - preview_svg.Close(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 10 ... finished\n"); + preview_svg.Close(); + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + + INFO("Testing polygon 10 ... finished"); } TEST_CASE("Polygon test 11", "[Polygon]") -{ +//void polygon_test_11(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 11 ...\n"); + INFO("Testing polygon 11 ..."); + #ifdef DEBUG start = clock(); + #endif z3::context z_context; z3::expr_vector X_positions(z_context); @@ -1826,50 +2108,68 @@ TEST_CASE("Polygon test 11", "[Polygon]") 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 = "t1_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T1_parameters.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_2.points.size(); ++i) { string name = "t2_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T2_parameters.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_3.points.size(); ++i) { string name = "t3_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T3_parameters.push_back(expr(z_context.real_const(name.c_str()))); } for (unsigned int i = 0; i < polygon_4.points.size(); ++i) { string name = "t4_par-" + to_string(i); - printf("name: %s\n", name.c_str()); - + #ifdef DEBUG + { + printf("name: %s\n", name.c_str()); + } + #endif T4_parameters.push_back(expr(z_context.real_const(name.c_str()))); } @@ -1903,7 +2203,11 @@ TEST_CASE("Polygon test 11", "[Polygon]") 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); @@ -1916,20 +2220,32 @@ TEST_CASE("Polygon test 11", "[Polygon]") 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: @@ -1948,15 +2264,23 @@ TEST_CASE("Polygon test 11", "[Polygon]") 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") { @@ -1992,14 +2316,18 @@ TEST_CASE("Polygon test 11", "[Polygon]") } } - printf("preRefined positions: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", poly_1_pos_x, + #ifdef DEBUG + { + printf("preRefined positions: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", 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_4_pos_y); + } + #endif while (true) { @@ -2030,20 +2358,32 @@ TEST_CASE("Polygon test 11", "[Polygon]") 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: @@ -2100,14 +2440,18 @@ TEST_CASE("Polygon test 11", "[Polygon]") poly_4_pos_y = value; } } - printf("Refined positions: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", poly_1_pos_x, + #ifdef DEBUG + { + printf("Refined positions: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", 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_4_pos_y); + } + #endif } else { @@ -2125,43 +2469,17 @@ 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(); + #endif REQUIRE(last_solvable_bounding_box_size > 0); - printf("Solvable bounding box: %d\n", last_solvable_bounding_box_size); - printf("Positions: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", poly_1_pos_x, + #ifdef DEBUG + { + printf("Solvable bounding box: %d\n", last_solvable_bounding_box_size); + printf("Positions: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", poly_1_pos_x, poly_1_pos_y, poly_2_pos_x, poly_2_pos_y, @@ -2169,6 +2487,8 @@ TEST_CASE("Polygon test 11", "[Polygon]") poly_3_pos_y, poly_4_pos_x, poly_4_pos_y); + } + #endif #ifdef DEBUG { @@ -2195,20 +2515,29 @@ TEST_CASE("Polygon test 11", "[Polygon]") preview_svg.draw(display_polygon_3, "red"); preview_svg.draw(display_polygon_4, "grey"); - preview_svg.Close(); - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 11 ... finished\n"); + preview_svg.Close(); + + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + + INFO("Testing polygon 11 ... finished"); } TEST_CASE("Polygon test 12", "[Polygon]") -{ +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 12 ...\n"); + INFO("Testing polygon 12 ..."); + #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}); @@ -2242,16 +2571,22 @@ TEST_CASE("Polygon test 12", "[Polygon]") dec_var_names_map, polygons); + #ifdef DEBUG finish = clock(); + #endif REQUIRE(optimized); if (optimized) { - printf("Polygon positions:\n"); - for (unsigned int i = 0; i < polygons.size(); ++i) + #ifdef DEBUG { - printf(" %.3f, %.3f\n", X_values[i], Y_values[i]); + printf("Polygon positions:\n"); + for (unsigned int i = 0; i < polygons.size(); ++i) + { + printf(" %.3f, %.3f\n", X_values[i], Y_values[i]); + } } + #endif SVG preview_svg("polygon_test_12.svg"); @@ -2306,21 +2641,34 @@ TEST_CASE("Polygon test 12", "[Polygon]") } else { - printf("Polygon optimization FAILED.\n"); + #ifdef DEBUG + { + printf("Polygon optimization FAILED.\n"); + } + #endif } - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 12 ... finished\n"); + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + + INFO("Testing polygon 12 ... finished"); } -TEST_CASE("Polygon test 13", "[Polygon]") -{ +//TEST_CASE("Polygon test 13", "[Polygon]") +void polygon_test_13(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 13 ...\n"); + INFO("Testing polygon 13 ..."); + #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}); @@ -2366,16 +2714,23 @@ TEST_CASE("Polygon test 13", "[Polygon]") dec_var_names_map, polygons); + #ifdef DEBUG finish = clock(); + #endif + REQUIRE(optimized); if (optimized) { - printf("Polygon positions:\n"); - for (unsigned int i = 0; i < polygons.size(); ++i) - { - printf(" %.3f, %.3f\n", X_values[i], Y_values[i]); + #ifdef DEBUG + { + printf("Polygon positions:\n"); + for (unsigned int i = 0; i < polygons.size(); ++i) + { + printf(" %.3f, %.3f\n", X_values[i], Y_values[i]); + } } + #endif SVG preview_svg("polygon_test_13.svg"); @@ -2460,21 +2815,33 @@ TEST_CASE("Polygon test 13", "[Polygon]") } else { - printf("Polygon optimization FAILED.\n"); + #ifdef DEBUG + { + printf("Polygon optimization FAILED.\n"); + } + #endif } - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 13 ... finished\n"); + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + + INFO("Testing polygon 13 ... finished"); } TEST_CASE("Polygon test 14", "[Polygon]") -{ +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 14 ...\n"); - + INFO("Testing polygon 14 ..."); + + #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}); @@ -2553,7 +2920,11 @@ TEST_CASE("Polygon test 14", "[Polygon]") poly_positions_Y[undecided[i]] = Y_values[undecided[i]]; } - printf("Optimized 1: %d\n", optimized); + #ifdef DEBUG + { + printf("Optimized 1: %d\n", optimized); + } + #endif } { @@ -2610,22 +2981,33 @@ TEST_CASE("Polygon test 14", "[Polygon]") undecided, dec_var_names_map, polygons); - printf("Optimized 2: %d\n", optimized); + + #ifdef DEBUG + { + printf("Optimized 2: %d\n", optimized); + } + #endif decided.push_back(4); decided.push_back(5); decided.push_back(6); decided.push_back(7); - + + #ifdef DEBUG finish = clock(); + #endif if (optimized) { - printf("Polygon positions:\n"); - for (unsigned int i = 0; i < decided.size(); ++i) + #ifdef DEBUG { - printf(" %.3f, %.3f\n", X_values[decided[i]].as_double(), Y_values[decided[i]].as_double()); + printf("Polygon positions:\n"); + for (unsigned int i = 0; i < decided.size(); ++i) + { + printf(" %.3f, %.3f\n", X_values[decided[i]].as_double(), Y_values[decided[i]].as_double()); + } } + #endif SVG preview_svg("polygon_test_14.svg"); @@ -2710,24 +3092,37 @@ TEST_CASE("Polygon test 14", "[Polygon]") } else { - printf("Polygon optimization FAILED.\n"); + #ifdef DEBUG + { + printf("Polygon optimization FAILED.\n"); + } + #endif } REQUIRE(optimized); } - - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 14 ... finished\n"); + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + + INFO("Testing polygon 14 ... finished"); } TEST_CASE("Polygon test 15", "[Polygon]") -{ +//void polygon_test_15(void) +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 15 ...\n"); + INFO("Testing polygon 15 ..."); + #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}); @@ -2789,16 +3184,20 @@ TEST_CASE("Polygon test 15", "[Polygon]") if (optimized) { - printf("Polygon positions:\n"); - for (unsigned int i = 0; i < decided_polygons.size(); ++i) + #ifdef DEBUG { - printf(" %.3f, %.3f\n", poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[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(" %.3f, %.3f\n", poly_positions_X[decided_polygons[i]].as_double(), poly_positions_Y[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("polygon_test_15.svg"); @@ -2885,7 +3284,11 @@ TEST_CASE("Polygon test 15", "[Polygon]") } else { - printf("Polygon optimization FAILED.\n"); + #ifdef DEBUG + { + printf("Polygon optimization FAILED.\n"); + } + #endif } REQUIRE(optimized); @@ -2902,20 +3305,31 @@ TEST_CASE("Polygon test 15", "[Polygon]") } while (!remaining_polygons.empty()); + #ifdef DEBUG finish = clock(); + #endif - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 15 ... finished\n"); + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + + INFO("Testing polygon 15 ... finished"); } TEST_CASE("Polygon test 16", "[Polygon]") -{ +{ + #ifdef DEBUG clock_t start, finish; + #endif - printf("Testing polygon 16 ...\n"); + INFO("Testing polygon 16 ..."); + #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}); @@ -2929,12 +3343,23 @@ TEST_CASE("Polygon test 16", "[Polygon]") double area = calc_PolygonUnreachableZoneArea(polygon_1, polygons); REQUIRE(area > 0.0); - printf("Polygons area: %.3f\n", area); + #ifdef DEBUG + { + printf("Polygons area: %.3f\n", area); + } + #endif + #ifdef DEBUG finish = clock(); + #endif - printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); - printf("Testing polygon 16 ... finished\n"); + #ifdef DEBUG + { + printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC); + } + #endif + + INFO("Testing polygon 16 ... finished"); } 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