Bug fix in scheduling test (empty set of objects) and reformating of tests using test macros.

This commit is contained in:
surynek 2024-11-10 21:26:08 +01:00 committed by Lukas Matena
parent 847dc52a24
commit c65315ce5a
13 changed files with 517 additions and 658 deletions

View File

@ -8,6 +8,9 @@ set(CMAKE_CXX_EXTENSIONS False)
find_package(Z3 REQUIRED)
slic3r_remap_configs("z3::libz3" RelWithDebInfo Release)
find_package(Catch2 2.9 REQUIRED)
include(Catch)
add_library(libseqarrange STATIC src/seq_interface.cpp src/seq_preprocess.cpp src/seq_sequential.cpp src/seq_utilities.cpp)
target_include_directories(libseqarrange PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include/libseqarrange)
target_link_libraries(libseqarrange libslic3r z3::libz3)
@ -29,7 +32,7 @@ target_link_libraries(sequential_decimator libseqarrange)
# target_link_libraries(seq_test_arrangement libseqarrange)
add_executable(seq_test_polygon test/seq_test_polygon.cpp test/prusaparts.cpp)
target_link_libraries(seq_test_polygon libseqarrange)
target_link_libraries(seq_test_polygon Catch2::Catch2 libseqarrange)
target_include_directories(seq_test_polygon PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}/include/libseqarrange")
add_executable(seq_test_sequential test/seq_test_sequential.cpp)
@ -44,3 +47,7 @@ add_executable(seq_test_interface test/seq_test_interface.cpp)
target_link_libraries(seq_test_interface libseqarrange)
target_include_directories(seq_test_interface PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}/include/libseqarrange")
add_test(seq_test_polygon seq_test_polygon)
add_test(seq_test_preprocess seq_test_preprocess)
add_test(seq_test_sequential seq_test_sequential)
add_test(seq_test_interface seq_test_interface)

View File

@ -222,7 +222,7 @@ bool check_ScheduledObjectsForSequentialPrintability(const SolverConfiguration
std::vector<Rational> dec_values_X;
std::vector<Rational> dec_values_Y;
std::vector<Rational> dec_values_T;
std::vector<Rational> dec_values_T;
for (const auto& scheduled_object: scheduled_plate.scheduled_objects)
{
@ -261,7 +261,7 @@ bool check_ScheduledObjectsForSequentialPrintability(const SolverConfiguration
{
printf("Line check ...\n");
}
#endif
#endif
if (!check_PolygonLineIntersections(dec_values_X,
dec_values_Y,
dec_values_T,

View File

@ -249,11 +249,14 @@ void introduce_TemporalOrdering(z3::solver &Solver,
int temporal_spread,
const std::vector<Slic3r::Polygon> &polygons)
{
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
if (!polygons.empty())
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
Solver.add(dec_vars_T[i] > dec_vars_T[j] + temporal_spread || dec_vars_T[i] + temporal_spread < dec_vars_T[j]);
for (unsigned int j = i + 1; j < polygons.size(); ++j)
{
Solver.add(dec_vars_T[i] > dec_vars_T[j] + temporal_spread || dec_vars_T[i] + temporal_spread < dec_vars_T[j]);
}
}
}
}
@ -268,14 +271,17 @@ void introduce_SequentialTemporalOrderingAgainstFixed(z3::solver
int temporal_spread,
const std::vector<Slic3r::Polygon> &SEQ_UNUSED(polygons))
{
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
if (!undecided.empty())
{
for (unsigned int j = i + 1; j < undecided.size(); ++j)
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
{
Solver.add(dec_vars_T[undecided[i]] > dec_vars_T[undecided[j]] + temporal_spread || dec_vars_T[undecided[i]] + temporal_spread < dec_vars_T[undecided[j]]);
for (unsigned int j = i + 1; j < undecided.size(); ++j)
{
Solver.add(dec_vars_T[undecided[i]] > dec_vars_T[undecided[j]] + temporal_spread || dec_vars_T[undecided[i]] + temporal_spread < dec_vars_T[undecided[j]]);
}
}
}
for (unsigned int i = 0; i < undecided.size(); ++i)
{
for (unsigned int j = 0; j < fixed.size(); ++j)
@ -306,11 +312,14 @@ void introduce_ConsequentialTemporalOrderingAgainstFixed(z3::solver
int temporal_spread,
const std::vector<Slic3r::Polygon> &SEQ_UNUSED(polygons))
{
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
if (!undecided.empty())
{
for (unsigned int j = i + 1; j < undecided.size(); ++j)
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
{
Solver.add(dec_vars_T[undecided[i]] > dec_vars_T[undecided[j]] + temporal_spread || dec_vars_T[undecided[i]] + temporal_spread < dec_vars_T[undecided[j]]);
for (unsigned int j = i + 1; j < undecided.size(); ++j)
{
Solver.add(dec_vars_T[undecided[i]] > dec_vars_T[undecided[j]] + temporal_spread || dec_vars_T[undecided[i]] + temporal_spread < dec_vars_T[undecided[j]]);
}
}
}
@ -374,9 +383,12 @@ void introduce_ConsequentialTemporalLepoxAgainstFixed(z3::solver
}
else
{
for (unsigned int j = 0; j < undecided.size() - 1; ++j)
if (!undecided.empty())
{
Solver.add(dec_vars_T[undecided[j]] + temporal_spread < dec_vars_T[undecided[i]]);
for (unsigned int j = 0; j < undecided.size() - 1; ++j)
{
Solver.add(dec_vars_T[undecided[j]] + temporal_spread < dec_vars_T[undecided[i]]);
}
}
}
}
@ -2991,18 +3003,21 @@ void introduce_PolygonWeakNonoverlapping(z3::solver &Sol
const z3::expr_vector &dec_vars_Y,
const std::vector<Slic3r::Polygon> &polygons)
{
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
if (!polygons.empty())
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
introduce_PolygonOutsidePolygon(Solver,
Context,
dec_vars_X[i],
dec_vars_Y[i],
polygons[i],
dec_vars_X[j],
dec_vars_Y[j],
polygons[j]);
for (unsigned int j = i + 1; j < polygons.size(); ++j)
{
introduce_PolygonOutsidePolygon(Solver,
Context,
dec_vars_X[i],
dec_vars_Y[i],
polygons[i],
dec_vars_X[j],
dec_vars_Y[j],
polygons[j]);
}
}
}
}
@ -3042,22 +3057,25 @@ void introduce_SequentialPolygonWeakNonoverlapping(z3::solver
const std::vector<Slic3r::Polygon> &polygons,
const std::vector<std::vector<Slic3r::Polygon> > &unreachable_polygons)
{
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
if (!polygons.empty())
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
introduce_SequentialPolygonOutsidePolygon(Solver,
Context,
dec_vars_X[i],
dec_vars_Y[i],
dec_vars_T[i],
polygons[i],
unreachable_polygons[i],
dec_vars_X[j],
dec_vars_Y[j],
dec_vars_T[j],
polygons[j],
unreachable_polygons[j]);
for (unsigned int j = i + 1; j < polygons.size(); ++j)
{
introduce_SequentialPolygonOutsidePolygon(Solver,
Context,
dec_vars_X[i],
dec_vars_Y[i],
dec_vars_T[i],
polygons[i],
unreachable_polygons[i],
dec_vars_X[j],
dec_vars_Y[j],
dec_vars_T[j],
polygons[j],
unreachable_polygons[j]);
}
}
}
}
@ -3097,22 +3115,25 @@ void introduce_ConsequentialPolygonWeakNonoverlapping(z3::solver
const std::vector<Slic3r::Polygon> &polygons,
const std::vector<std::vector<Slic3r::Polygon> > &unreachable_polygons)
{
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
if (!polygons.empty())
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
introduce_ConsequentialPolygonOutsidePolygon(Solver,
Context,
dec_vars_X[i],
dec_vars_Y[i],
dec_vars_T[i],
polygons[i],
unreachable_polygons[i],
dec_vars_X[j],
dec_vars_Y[j],
dec_vars_T[j],
polygons[j],
unreachable_polygons[j]);
for (unsigned int j = i + 1; j < polygons.size(); ++j)
{
introduce_ConsequentialPolygonOutsidePolygon(Solver,
Context,
dec_vars_X[i],
dec_vars_Y[i],
dec_vars_T[i],
polygons[i],
unreachable_polygons[i],
dec_vars_X[j],
dec_vars_Y[j],
dec_vars_T[j],
polygons[j],
unreachable_polygons[j]);
}
}
}
}
@ -3128,18 +3149,21 @@ void introduce_PolygonWeakNonoverlapping(z3::solver &Sol
const std::vector<int> &undecided,
const std::vector<Slic3r::Polygon> &polygons)
{
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
if (!undecided.empty())
{
for (unsigned int j = i + 1; j < undecided.size(); ++j)
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
{
introduce_PolygonOutsidePolygon(Solver,
Context,
dec_vars_X[undecided[i]],
dec_vars_Y[undecided[i]],
polygons[undecided[i]],
dec_vars_X[undecided[j]],
dec_vars_Y[undecided[j]],
polygons[undecided[j]]);
for (unsigned int j = i + 1; j < undecided.size(); ++j)
{
introduce_PolygonOutsidePolygon(Solver,
Context,
dec_vars_X[undecided[i]],
dec_vars_Y[undecided[i]],
polygons[undecided[i]],
dec_vars_X[undecided[j]],
dec_vars_Y[undecided[j]],
polygons[undecided[j]]);
}
}
}
@ -3209,27 +3233,30 @@ void introduce_SequentialPolygonWeakNonoverlapping(z3::solver
const std::vector<Slic3r::Polygon> &polygons,
const std::vector<std::vector<Slic3r::Polygon> > &unreachable_polygons)
{
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
if (!undecided.empty())
{
for (unsigned int j = i + 1; j < undecided.size(); ++j)
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
{
#ifdef DEBUG
for (unsigned int j = i + 1; j < undecided.size(); ++j)
{
printf("PoP: %d,%d\n", undecided[i], undecided[j]);
#ifdef DEBUG
{
printf("PoP: %d,%d\n", undecided[i], undecided[j]);
}
#endif
introduce_SequentialPolygonOutsidePolygon(Solver,
Context,
dec_vars_X[undecided[i]],
dec_vars_Y[undecided[i]],
dec_vars_T[undecided[i]],
polygons[undecided[i]],
unreachable_polygons[undecided[i]],
dec_vars_X[undecided[j]],
dec_vars_Y[undecided[j]],
dec_vars_T[undecided[j]],
polygons[undecided[j]],
unreachable_polygons[undecided[j]]);
}
#endif
introduce_SequentialPolygonOutsidePolygon(Solver,
Context,
dec_vars_X[undecided[i]],
dec_vars_Y[undecided[i]],
dec_vars_T[undecided[i]],
polygons[undecided[i]],
unreachable_polygons[undecided[i]],
dec_vars_X[undecided[j]],
dec_vars_Y[undecided[j]],
dec_vars_T[undecided[j]],
polygons[undecided[j]],
unreachable_polygons[undecided[j]]);
}
}
@ -3310,28 +3337,31 @@ void introduce_ConsequentialPolygonWeakNonoverlapping(const SolverConfiguration
const std::vector<int> &undecided,
const std::vector<Slic3r::Polygon> &polygons,
const std::vector<std::vector<Slic3r::Polygon> > &unreachable_polygons)
{
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
{
if (!undecided.empty())
{
for (unsigned int j = i + 1; j < undecided.size(); ++j)
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
{
#ifdef DEBUG
for (unsigned int j = i + 1; j < undecided.size(); ++j)
{
printf("PoP: %d,%d\n", undecided[i], undecided[j]);
#ifdef DEBUG
{
printf("PoP: %d,%d\n", undecided[i], undecided[j]);
}
#endif
introduce_ConsequentialPolygonExternalPolygon(Solver,
Context,
dec_vars_X[undecided[i]],
dec_vars_Y[undecided[i]],
dec_vars_T[undecided[i]],
polygons[undecided[i]],
unreachable_polygons[undecided[i]],
dec_vars_X[undecided[j]],
dec_vars_Y[undecided[j]],
dec_vars_T[undecided[j]],
polygons[undecided[j]],
unreachable_polygons[undecided[j]]);
}
#endif
introduce_ConsequentialPolygonExternalPolygon(Solver,
Context,
dec_vars_X[undecided[i]],
dec_vars_Y[undecided[i]],
dec_vars_T[undecided[i]],
polygons[undecided[i]],
unreachable_polygons[undecided[i]],
dec_vars_X[undecided[j]],
dec_vars_Y[undecided[j]],
dec_vars_T[undecided[j]],
polygons[undecided[j]],
unreachable_polygons[undecided[j]]);
}
}
@ -3470,31 +3500,34 @@ void introduce_PolygonStrongNonoverlapping(z3::solver &S
dec_vars_Y,
polygons);
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
if (!polygons.empty())
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
for (unsigned int p1 = 0; p1 < polygons[i].points.size(); ++p1)
{
const Point &point1 = polygons[i].points[p1];
const Point &next_point1 = polygons[i].points[(p1 + 1) % polygons[i].points.size()];
for (unsigned int p2 = 0; p2 < polygons[j].points.size(); ++p2)
{
const Point &point2 = polygons[j].points[p2];
const Point &next_point2 = polygons[j].points[(p2 + 1) % polygons[j].points.size()];
introduce_LineNonIntersection(Solver,
Context,
dec_vars_X[i],
dec_vars_Y[i],
z3::expr(Context.real_const(("hidden-var-" + to_string(hidden_var_cnt)).c_str())),
Line(point1, next_point1),
dec_vars_X[j],
dec_vars_Y[j],
z3::expr(Context.real_const(("hidden-var-" + to_string(hidden_var_cnt + 1)).c_str())),
Line(point2, next_point2));
hidden_var_cnt += 2;
for (unsigned int j = i + 1; j < polygons.size(); ++j)
{
for (unsigned int p1 = 0; p1 < polygons[i].points.size(); ++p1)
{
const Point &point1 = polygons[i].points[p1];
const Point &next_point1 = polygons[i].points[(p1 + 1) % polygons[i].points.size()];
for (unsigned int p2 = 0; p2 < polygons[j].points.size(); ++p2)
{
const Point &point2 = polygons[j].points[p2];
const Point &next_point2 = polygons[j].points[(p2 + 1) % polygons[j].points.size()];
introduce_LineNonIntersection(Solver,
Context,
dec_vars_X[i],
dec_vars_Y[i],
z3::expr(Context.real_const(("hidden-var-" + to_string(hidden_var_cnt)).c_str())),
Line(point1, next_point1),
dec_vars_X[j],
dec_vars_Y[j],
z3::expr(Context.real_const(("hidden-var-" + to_string(hidden_var_cnt + 1)).c_str())),
Line(point2, next_point2));
hidden_var_cnt += 2;
}
}
}
}
@ -3731,6 +3764,7 @@ bool refine_PolygonWeakNonoverlapping(z3::solver &Solver
{
bool refined = false;
assert(!polygons.empty());
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
@ -3816,6 +3850,7 @@ bool refine_PolygonWeakNonoverlapping(z3::solver &Solver
{
bool refined = false;
assert(!polygons.empty());
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
@ -3896,6 +3931,7 @@ bool refine_PolygonWeakNonoverlapping(z3::solver &Solver
{
bool refined = false;
assert(!polygons.empty());
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
@ -3979,6 +4015,7 @@ bool refine_SequentialPolygonWeakNonoverlapping(z3::solver
{
bool refined = false;
assert(!polygons.empty());
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
@ -4168,6 +4205,7 @@ bool refine_SequentialPolygonWeakNonoverlapping(z3::solver
{
bool refined = false;
assert(!polygons.empty());
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
@ -4374,6 +4412,7 @@ bool refine_ConsequentialPolygonWeakNonoverlapping(z3::solver
{
bool refined = false;
assert(!polygons.empty());
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
@ -4560,6 +4599,7 @@ bool refine_ConsequentialPolygonWeakNonoverlapping(z3::solver
{
bool refined = false;
assert(!polygons.empty());
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
@ -4766,18 +4806,21 @@ void introduce_PolygonWeakNonoverlappingAgainstFixed(z3::solver
const std::vector<int> &undecided,
const std::vector<Slic3r::Polygon> &polygons)
{
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
if (!undecided.empty())
{
for (unsigned int j = i + 1; j < undecided.size(); ++j)
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
{
introduce_PolygonOutsidePolygon(Solver,
Context,
dec_vars_X[undecided[i]],
dec_vars_Y[undecided[i]],
polygons[undecided[i]],
dec_vars_X[undecided[j]],
dec_vars_Y[undecided[j]],
polygons[undecided[j]]);
for (unsigned int j = i + 1; j < undecided.size(); ++j)
{
introduce_PolygonOutsidePolygon(Solver,
Context,
dec_vars_X[undecided[i]],
dec_vars_Y[undecided[i]],
polygons[undecided[i]],
dec_vars_X[undecided[j]],
dec_vars_Y[undecided[j]],
polygons[undecided[j]]);
}
}
}
@ -4810,6 +4853,7 @@ bool refine_PolygonWeakNonoverlapping(z3::solver &Solver
{
bool refined = false;
assert(!undecided.empty());
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
{
for (unsigned int j = i + 1; j < undecided.size(); ++j)
@ -4974,6 +5018,7 @@ bool refine_PolygonWeakNonoverlapping(z3::solver &Solver
printf("Refining ***************************\n");
}
#endif
assert(!undecided.empty());
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
{
for (unsigned int j = i + 1; j < undecided.size(); ++j)
@ -5215,7 +5260,8 @@ bool refine_SequentialPolygonWeakNonoverlapping(z3::solver
}
}
#endif
assert(!undecided.empty());
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
{
for (unsigned int j = i + 1; j < undecided.size(); ++j)
@ -5727,7 +5773,8 @@ bool refine_ConsequentialPolygonWeakNonoverlapping(z3::solver
}
}
#endif
assert(!undecided.empty());
for (unsigned int i = 0; i < undecided.size() - 1; ++i)
{
for (unsigned int j = i + 1; j < undecided.size(); ++j)
@ -6191,146 +6238,149 @@ bool check_PointsOutsidePolygons(const std::vector<Rational>
const std::vector<Slic3r::Polygon> &polygons,
const std::vector<std::vector<Slic3r::Polygon> > &unreachable_polygons)
{
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
if (!polygons.empty())
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
if (dec_values_T[i] > dec_values_T[j])
for (unsigned int j = i + 1; j < polygons.size(); ++j)
{
for (unsigned int p1 = 0; p1 < polygons[i].points.size(); ++p1)
if (dec_values_T[i] > dec_values_T[j])
{
const Point &point1 = polygons[i].points[p1];
#ifdef DEBUG
for (unsigned int p1 = 0; p1 < polygons[i].points.size(); ++p1)
{
printf(">----------------\n");
}
#endif
const Point &point1 = polygons[i].points[p1];
for (unsigned int poly2 = 0; poly2 < unreachable_polygons[j].size(); ++poly2)
{
if (unreachable_polygons[j][poly2].points.size() >= 3)
#ifdef DEBUG
{
bool always_inside_halfplane = true;
printf(">----------------\n");
}
#endif
for (unsigned int poly2 = 0; poly2 < unreachable_polygons[j].size(); ++poly2)
{
if (unreachable_polygons[j][poly2].points.size() >= 3)
{
bool always_inside_halfplane = true;
#ifdef DEBUG
{
printf("....\n");
}
#endif
#ifdef DEBUG
{
printf("....\n");
}
#endif
for (unsigned int p2 = 0; p2 < unreachable_polygons[j][poly2].points.size(); ++p2)
{
const Point &point2 = unreachable_polygons[j][poly2].points[p2];
const Point &next_point2 = unreachable_polygons[j][poly2].points[(p2 + 1) % unreachable_polygons[j][poly2].points.size()];
Line line(point2, next_point2);
Vector normal = line.normal();
for (unsigned int p2 = 0; p2 < unreachable_polygons[j][poly2].points.size(); ++p2)
{
const Point &point2 = unreachable_polygons[j][poly2].points[p2];
const Point &next_point2 = unreachable_polygons[j][poly2].points[(p2 + 1) % unreachable_polygons[j][poly2].points.size()];
Line line(point2, next_point2);
Vector normal = line.normal();
double outside = (normal.x() * (dec_values_X[i].as_double() + point1.x()))
+ (normal.y() * (dec_values_Y[i].as_double() + point1.y()))
- (normal.x() * dec_values_X[j].as_double())
- (normal.x() * line.a.x())
- (normal.y() * dec_values_Y[j].as_double())
- (normal.y() * line.a.y());
double outside = (normal.x() * (dec_values_X[i].as_double() + point1.x()))
+ (normal.y() * (dec_values_Y[i].as_double() + point1.y()))
- (normal.x() * dec_values_X[j].as_double())
- (normal.x() * line.a.x())
- (normal.y() * dec_values_Y[j].as_double())
- (normal.y() * line.a.y());
#ifdef DEBUG
{
printf("Tested point: %d, %d\n", point1.x(), point1.y());
printf("Point: %d, %d\n", point2.x(), point2.y());
printf("Next point: %d, %d\n", next_point2.x(), next_point2.y());
printf("X[i]: %.3f, Y[i]: %.3f, X[j]: %.3f, Y[j]: %.3f\n", dec_values_X[i].as_double(), dec_values_Y[i].as_double(), dec_values_X[j].as_double(), dec_values_Y[j].as_double());
printf("Outside 1: %.3f\n", outside);
}
#endif
#ifdef DEBUG
{
printf("Tested point: %d, %d\n", point1.x(), point1.y());
printf("Point: %d, %d\n", point2.x(), point2.y());
printf("Next point: %d, %d\n", next_point2.x(), next_point2.y());
printf("X[i]: %.3f, Y[i]: %.3f, X[j]: %.3f, Y[j]: %.3f\n", dec_values_X[i].as_double(), dec_values_Y[i].as_double(), dec_values_X[j].as_double(), dec_values_Y[j].as_double());
printf("Outside 1: %.3f\n", outside);
}
#endif
if (outside > -EPSILON)
{
always_inside_halfplane = false;
break;
if (outside > -EPSILON)
{
always_inside_halfplane = false;
break;
}
}
if (always_inside_halfplane)
{
return false;
}
}
if (always_inside_halfplane)
{
return false;
}
}
}
}
}
else if (dec_values_T[i] < dec_values_T[j])
{
for (unsigned int p2 = 0; p2 < polygons[j].points.size(); ++p2)
else if (dec_values_T[i] < dec_values_T[j])
{
const Point &point2 = polygons[j].points[p2];
#ifdef DEBUG
for (unsigned int p2 = 0; p2 < polygons[j].points.size(); ++p2)
{
printf("<----------------\n");
}
#endif
for (unsigned int poly1 = 0; poly1 < unreachable_polygons[i].size(); ++poly1)
{
if (unreachable_polygons[i][poly1].points.size() >= 3)
{
bool always_inside_halfplane = true;
const Point &point2 = polygons[j].points[p2];
#ifdef DEBUG
#ifdef DEBUG
{
printf("<----------------\n");
}
#endif
for (unsigned int poly1 = 0; poly1 < unreachable_polygons[i].size(); ++poly1)
{
if (unreachable_polygons[i][poly1].points.size() >= 3)
{
printf("....\n");
}
#endif
bool always_inside_halfplane = true;
#ifdef DEBUG
{
printf("....\n");
}
#endif
for (unsigned int p1 = 0; p1 < unreachable_polygons[i][poly1].points.size(); ++p1)
{
const Point &point1 = unreachable_polygons[i][poly1].points[p1];
const Point &next_point1 = unreachable_polygons[i][poly1].points[(p1 + 1) % unreachable_polygons[i][poly1].points.size()];
Line line(point1, next_point1);
Vector normal = line.normal();
for (unsigned int p1 = 0; p1 < unreachable_polygons[i][poly1].points.size(); ++p1)
{
const Point &point1 = unreachable_polygons[i][poly1].points[p1];
const Point &next_point1 = unreachable_polygons[i][poly1].points[(p1 + 1) % unreachable_polygons[i][poly1].points.size()];
Line line(point1, next_point1);
Vector normal = line.normal();
double outside = (normal.x() * (dec_values_X[j].as_double() + point2.x()))
+ (normal.y() * (dec_values_Y[j].as_double() + point2.y()))
- (normal.x() * dec_values_X[i].as_double())
- (normal.x() * line.a.x())
- (normal.y() * dec_values_Y[i].as_double())
- (normal.y() * line.a.y());
double outside = (normal.x() * (dec_values_X[j].as_double() + point2.x()))
+ (normal.y() * (dec_values_Y[j].as_double() + point2.y()))
- (normal.x() * dec_values_X[i].as_double())
- (normal.x() * line.a.x())
- (normal.y() * dec_values_Y[i].as_double())
- (normal.y() * line.a.y());
#ifdef DEBUG
{
printf("Tested point: %.3f, %.3f\n", dec_values_X[j].as_double() + point2.x(), dec_values_Y[j].as_double() + point2.y());
printf("Point: %.3f, %.3f\n", point1.x() + dec_values_X[i].as_double(), point1.y() + dec_values_Y[i].as_double());
printf("Next point: %.3f, %.3f\n", next_point1.x() + dec_values_X[i].as_double(), next_point1.y() + dec_values_Y[i].as_double());
printf("X[i]: %.3f, Y[i]: %.3f, X[j]: %.3f, Y[j]: %.3f\n", dec_values_X[i].as_double(), dec_values_Y[i].as_double(), dec_values_X[j].as_double(), dec_values_Y[j].as_double());
printf("Outside 2: %.3f\n", outside);
#ifdef DEBUG
{
printf("Tested point: %.3f, %.3f\n", dec_values_X[j].as_double() + point2.x(), dec_values_Y[j].as_double() + point2.y());
printf("Point: %.3f, %.3f\n", point1.x() + dec_values_X[i].as_double(), point1.y() + dec_values_Y[i].as_double());
printf("Next point: %.3f, %.3f\n", next_point1.x() + dec_values_X[i].as_double(), next_point1.y() + dec_values_Y[i].as_double());
printf("X[i]: %.3f, Y[i]: %.3f, X[j]: %.3f, Y[j]: %.3f\n", dec_values_X[i].as_double(), dec_values_Y[i].as_double(), dec_values_X[j].as_double(), dec_values_Y[j].as_double());
printf("Outside 2: %.3f\n", outside);
}
#endif
if (outside > -EPSILON)
{
always_inside_halfplane = false;
break;
}
}
#endif
if (outside > -EPSILON)
if (always_inside_halfplane)
{
always_inside_halfplane = false;
break;
}
}
if (always_inside_halfplane)
{
return false;
return false;
}
}
}
}
}
}
else
{
#ifdef DEBUG
{
printf("Time collision: %.3f, %.3f\n", dec_values_T[i].as_double(), dec_values_T[j].as_double());
}
}
else
{
#ifdef DEBUG
{
printf("Time collision: %.3f, %.3f\n", dec_values_T[i].as_double(), dec_values_T[j].as_double());
}
#endif
assert(false);
}
#endif
assert(false);
}
}
}
}
#ifdef DEBUG
{
@ -6348,99 +6398,36 @@ bool check_PolygonLineIntersections(const std::vector<Rational>
const std::vector<Slic3r::Polygon> &polygons,
const std::vector<std::vector<Slic3r::Polygon> > &unreachable_polygons)
{
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
if (!polygons.empty())
{
for (unsigned int j = i + 1; j < polygons.size(); ++j)
for (unsigned int i = 0; i < polygons.size() - 1; ++i)
{
if (dec_values_T[i] > dec_values_T[j])
for (unsigned int j = i + 1; j < polygons.size(); ++j)
{
for (unsigned int p1 = 0; p1 < polygons[i].points.size(); ++p1)
{
const Point &point1 = polygons[i].points[p1];
const Point &next_point1 = polygons[i].points[(p1 + 1) % polygons[i].points.size()];
for (unsigned int poly2 = 0; poly2 < unreachable_polygons[j].size(); ++poly2)
{
#ifdef DEBUG
{
printf("temporal: %.3f %.3f [ij: %d,%d]\n", dec_values_T[i].as_double(), dec_values_T[j].as_double(), i, j);
printf("proto X1: %ld, %ld, %ld\n", unreachable_polygons.size(), unreachable_polygons[j].size(), unreachable_polygons[j][poly2].points.size());
}
#endif
for (unsigned int p2 = 0; p2 < unreachable_polygons[j][poly2].points.size(); ++p2)
{
const Point &point2 = unreachable_polygons[j][poly2].points[p2];
const Point &next_point2 = unreachable_polygons[j][poly2].points[(p2 + 1) % unreachable_polygons[j][poly2].points.size()];
#ifdef DEBUG
{
printf("testing alpha %d %d (%d,%d): [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f]\n", i, j, p1, p2,
dec_values_X[i].as_double() + point1.x(), dec_values_Y[i].as_double() + point1.y(),
dec_values_X[i].as_double() + next_point1.x(), dec_values_Y[i].as_double() + next_point1.y(),
dec_values_X[j].as_double() + point2.x(), dec_values_Y[j].as_double() + point2.y(),
dec_values_X[j].as_double() + next_point2.x(), dec_values_Y[j].as_double() + next_point2.y());
}
#endif
if (lines_intersect_open(dec_values_X[i].as_double() + point1.x(), dec_values_Y[i].as_double() + point1.y(),
next_point1.x() - point1.x(), next_point1.y() - point1.y(),
dec_values_X[j].as_double() + point2.x(), dec_values_Y[j].as_double() + point2.y(),
next_point2.x() - point2.x(), next_point2.y() - point2.y()))
{
#ifdef DEBUG
{
printf("temps: [ij: %d,%d] [%.3f, %.3f]\n", i, j,
dec_values_T[i].as_double(),
dec_values_T[j].as_double());
printf("dec_values: [%.3f, %.3f] [%.3f,%.3f]\n",
dec_values_X[i].as_double(),
dec_values_Y[i].as_double(),
dec_values_X[j].as_double(),
dec_values_Y[j].as_double());
printf("intersect 1: %d [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f]\n",
hidden_var_cnt,
dec_values_X[i].as_double() + point1.x(), dec_values_Y[i].as_double() + point1.y(),
dec_values_X[i].as_double() + next_point1.x(), dec_values_Y[i].as_double() + next_point1.y(),
dec_values_X[j].as_double() + point2.x(), dec_values_Y[j].as_double() + point2.y(),
dec_values_X[j].as_double() + next_point2.x(), dec_values_Y[j].as_double() + next_point2.y());
}
#endif
return false;
}
}
}
}
}
else
{
if (dec_values_T[i] < dec_values_T[j])
if (dec_values_T[i] > dec_values_T[j])
{
for (unsigned int poly1 = 0; poly1 < unreachable_polygons[i].size(); ++poly1)
{
for (unsigned int p1 = 0; p1 < unreachable_polygons[i][poly1].points.size(); ++p1)
for (unsigned int p1 = 0; p1 < polygons[i].points.size(); ++p1)
{
const Point &point1 = polygons[i].points[p1];
const Point &next_point1 = polygons[i].points[(p1 + 1) % polygons[i].points.size()];
for (unsigned int poly2 = 0; poly2 < unreachable_polygons[j].size(); ++poly2)
{
#ifdef DEBUG
{
printf("proto2: %ld, %ld, %ld\n", unreachable_polygons.size(), unreachable_polygons[i].size(), unreachable_polygons[i][poly1].points.size());
{
printf("temporal: %.3f %.3f [ij: %d,%d]\n", dec_values_T[i].as_double(), dec_values_T[j].as_double(), i, j);
printf("proto X1: %ld, %ld, %ld\n", unreachable_polygons.size(), unreachable_polygons[j].size(), unreachable_polygons[j][poly2].points.size());
}
#endif
const Point &point1 = unreachable_polygons[i][poly1].points[p1];
const Point &next_point1 = unreachable_polygons[i][poly1].points[(p1 + 1) % unreachable_polygons[i][poly1].points.size()];
for (unsigned int p2 = 0; p2 < polygons[j].points.size(); ++p2)
for (unsigned int p2 = 0; p2 < unreachable_polygons[j][poly2].points.size(); ++p2)
{
const Point &point2 = polygons[j].points[p2];
const Point &next_point2 = polygons[j].points[(p2 + 1) % polygons[j].points.size()];
const Point &point2 = unreachable_polygons[j][poly2].points[p2];
const Point &next_point2 = unreachable_polygons[j][poly2].points[(p2 + 1) % unreachable_polygons[j][poly2].points.size()];
#ifdef DEBUG
{
printf("testing beta: [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f]\n",
printf("testing alpha %d %d (%d,%d): [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f]\n", i, j, p1, p2,
dec_values_X[i].as_double() + point1.x(), dec_values_Y[i].as_double() + point1.y(),
dec_values_X[i].as_double() + next_point1.x(), dec_values_Y[i].as_double() + next_point1.y(),
dec_values_X[j].as_double() + point2.x(), dec_values_Y[j].as_double() + point2.y(),
@ -6465,8 +6452,8 @@ bool check_PolygonLineIntersections(const std::vector<Rational>
dec_values_Y[i].as_double(),
dec_values_X[j].as_double(),
dec_values_Y[j].as_double());
printf("intersect 2: %d [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f]\n",
printf("intersect 1: %d [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f]\n",
hidden_var_cnt,
dec_values_X[i].as_double() + point1.x(), dec_values_Y[i].as_double() + point1.y(),
dec_values_X[i].as_double() + next_point1.x(), dec_values_Y[i].as_double() + next_point1.y(),
@ -6479,16 +6466,81 @@ bool check_PolygonLineIntersections(const std::vector<Rational>
}
}
}
}
}
}
else
{
#ifdef DEBUG
if (dec_values_T[i] < dec_values_T[j])
{
printf("Time collision: %.3f, %.3f\n", dec_values_T[i].as_double(), dec_values_T[j].as_double());
for (unsigned int poly1 = 0; poly1 < unreachable_polygons[i].size(); ++poly1)
{
for (unsigned int p1 = 0; p1 < unreachable_polygons[i][poly1].points.size(); ++p1)
{
#ifdef DEBUG
{
printf("proto2: %ld, %ld, %ld\n", unreachable_polygons.size(), unreachable_polygons[i].size(), unreachable_polygons[i][poly1].points.size());
}
#endif
const Point &point1 = unreachable_polygons[i][poly1].points[p1];
const Point &next_point1 = unreachable_polygons[i][poly1].points[(p1 + 1) % unreachable_polygons[i][poly1].points.size()];
for (unsigned int p2 = 0; p2 < polygons[j].points.size(); ++p2)
{
const Point &point2 = polygons[j].points[p2];
const Point &next_point2 = polygons[j].points[(p2 + 1) % polygons[j].points.size()];
#ifdef DEBUG
{
printf("testing beta: [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f]\n",
dec_values_X[i].as_double() + point1.x(), dec_values_Y[i].as_double() + point1.y(),
dec_values_X[i].as_double() + next_point1.x(), dec_values_Y[i].as_double() + next_point1.y(),
dec_values_X[j].as_double() + point2.x(), dec_values_Y[j].as_double() + point2.y(),
dec_values_X[j].as_double() + next_point2.x(), dec_values_Y[j].as_double() + next_point2.y());
}
#endif
if (lines_intersect_open(dec_values_X[i].as_double() + point1.x(), dec_values_Y[i].as_double() + point1.y(),
next_point1.x() - point1.x(), next_point1.y() - point1.y(),
dec_values_X[j].as_double() + point2.x(), dec_values_Y[j].as_double() + point2.y(),
next_point2.x() - point2.x(), next_point2.y() - point2.y()))
{
#ifdef DEBUG
{
printf("temps: [ij: %d,%d] [%.3f, %.3f]\n", i, j,
dec_values_T[i].as_double(),
dec_values_T[j].as_double());
printf("dec_values: [%.3f, %.3f] [%.3f,%.3f]\n",
dec_values_X[i].as_double(),
dec_values_Y[i].as_double(),
dec_values_X[j].as_double(),
dec_values_Y[j].as_double());
printf("intersect 2: %d [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f] [%.3f,%.3f]\n",
hidden_var_cnt,
dec_values_X[i].as_double() + point1.x(), dec_values_Y[i].as_double() + point1.y(),
dec_values_X[i].as_double() + next_point1.x(), dec_values_Y[i].as_double() + next_point1.y(),
dec_values_X[j].as_double() + point2.x(), dec_values_Y[j].as_double() + point2.y(),
dec_values_X[j].as_double() + next_point2.x(), dec_values_Y[j].as_double() + next_point2.y());
}
#endif
return false;
}
}
}
}
}
else
{
#ifdef DEBUG
{
printf("Time collision: %.3f, %.3f\n", dec_values_T[i].as_double(), dec_values_T[j].as_double());
}
#endif
assert(false);
}
#endif
assert(false);
}
}
}

View File

@ -19,6 +19,10 @@
#include <gecode/minimodel.hh>
#include <gecode/search.hh>
#define CATCH_CONFIG_EXTERNAL_INTERFACES
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
#include "seq_defs.hpp"
#include "seq_test_arrangement.hpp"
@ -81,9 +85,9 @@ public:
};
void test_arrangement_1(void)
TEST_CASE("Arrangement test 1", "[Classical Arrangement]")
{
printf("Testing sheet arrangement 1 ...\n");
printf("Testing plate arrangement 1 ...\n");
SizeOptions opt("Queens");
opt.iterations(200);
@ -92,7 +96,7 @@ void test_arrangement_1(void)
Script::run<Queens,LDS,SizeOptions>(opt);
printf("Testing sheet arrangement 1 ... finished\n");
printf("Testing plate arrangement 1 ... finished\n");
}
@ -140,7 +144,7 @@ public:
};
const int sheet_size = 9;
const int plate_size = 9;
const int Obj1_width = 5;
const int Obj1_height = 4;
@ -161,7 +165,7 @@ public:
public:
ArrangementProblem()
: vars(*this, 6, 0, sheet_size - 1)
: vars(*this, 6, 0, plate_size - 1)
, Obj1_x(vars[0])
, Obj1_y(vars[1])
, Obj2_x(vars[2])
@ -191,16 +195,16 @@ public:
nooverlap(*this, Xs, widths, Ys, heights);
rel(*this, Obj1_x + Obj1_width <= sheet_size);
rel(*this, Obj2_x + Obj2_width <= sheet_size);
rel(*this, Obj3_x + Obj3_width <= sheet_size);
rel(*this, Obj1_x + Obj1_width <= plate_size);
rel(*this, Obj2_x + Obj2_width <= plate_size);
rel(*this, Obj3_x + Obj3_width <= plate_size);
rel(*this, Obj2_x == Obj1_x + 5);
rel(*this, Obj2_y == Obj1_y + 1);
rel(*this, Obj1_y + Obj1_height <= sheet_size);
rel(*this, Obj2_y + Obj2_height <= sheet_size);
rel(*this, Obj3_y + Obj3_height <= sheet_size);
rel(*this, Obj1_y + Obj1_height <= plate_size);
rel(*this, Obj2_y + Obj2_height <= plate_size);
rel(*this, Obj3_y + Obj3_height <= plate_size);
branch(*this, vars, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
};
@ -236,7 +240,7 @@ public:
};
const int sheet_resolution = 20;
const int plate_resolution = 20;
const int time_resolution = 80;
const int low_Obj1_width = 5;
@ -274,9 +278,9 @@ public:
public:
SimpleSequentialProblem()
: space_vars(*this, 8, 0, sheet_resolution)
: space_vars(*this, 8, 0, plate_resolution)
, time_vars(*this, 4, 0, time_resolution)
, kine_vars(*this, 2, 0, sheet_resolution)
, kine_vars(*this, 2, 0, plate_resolution)
, low_Obj1_x(space_vars[0])
, low_Obj1_y(space_vars[1])
@ -362,15 +366,15 @@ public:
rel(*this, low_Obj2_t >= high_Obj1_t + high_Obj1_duration || high_Obj1_t >= low_Obj2_t + low_Obj2_duration);
rel(*this, low_Obj1_t >= high_Obj1_t + high_Obj1_duration || high_Obj1_t >= low_Obj1_t + low_Obj1_duration);
rel(*this, low_Obj1_x + low_Obj1_width <= sheet_resolution);
rel(*this, low_Obj2_x + low_Obj2_width <= sheet_resolution);
rel(*this, low_Obj3_x + low_Obj3_width <= sheet_resolution);
rel(*this, high_Obj1_x + high_Obj1_width <= sheet_resolution);
rel(*this, low_Obj1_x + low_Obj1_width <= plate_resolution);
rel(*this, low_Obj2_x + low_Obj2_width <= plate_resolution);
rel(*this, low_Obj3_x + low_Obj3_width <= plate_resolution);
rel(*this, high_Obj1_x + high_Obj1_width <= plate_resolution);
rel(*this, low_Obj1_y + low_Obj1_height <= sheet_resolution);
rel(*this, low_Obj2_y + low_Obj2_height <= sheet_resolution);
rel(*this, low_Obj3_y + low_Obj3_height <= sheet_resolution);
rel(*this, high_Obj1_y + high_Obj1_height <= sheet_resolution);
rel(*this, low_Obj1_y + low_Obj1_height <= plate_resolution);
rel(*this, low_Obj2_y + low_Obj2_height <= plate_resolution);
rel(*this, low_Obj3_y + low_Obj3_height <= plate_resolution);
rel(*this, high_Obj1_y + high_Obj1_height <= plate_resolution);
rel(*this, low_Obj1_t + low_Obj1_duration <= time_resolution);
rel(*this, low_Obj2_t + low_Obj2_duration <= time_resolution);
@ -436,10 +440,10 @@ public:
};
int complex_sheet_resolution = 30;
int complex_plate_resolution = 30;
int complex_sheet_resolution_min = 10;
int complex_sheet_resolution_max = 200;
int complex_plate_resolution_min = 10;
int complex_plate_resolution_max = 200;
int complex_time_resolution = 1000;
int complex_height_threshold = 25;
@ -482,9 +486,9 @@ public:
public:
ComplexSequentialProblem()
: space_vars(*this, 2 * complex_Obj_count, 0, complex_sheet_resolution)
: space_vars(*this, 2 * complex_Obj_count, 0, complex_plate_resolution)
, time_vars(*this, complex_Obj_count, 0, complex_time_resolution)
, kine_vars(*this, 2 * complex_Obj_count, 0, complex_sheet_resolution)
, kine_vars(*this, 2 * complex_Obj_count, 0, complex_plate_resolution)
{
/*
int width_span = max_width - min_width;
@ -535,8 +539,8 @@ public:
for (int i = 0; i < complex_Obj_count; ++i)
{
rel(*this, complex_Obj_x[i] + complex_Obj_widths[i] <= complex_sheet_resolution, IPL_BND);
rel(*this, complex_Obj_y[i] + complex_Obj_heights[i] <= complex_sheet_resolution, IPL_BND);
rel(*this, complex_Obj_x[i] + complex_Obj_widths[i] <= complex_plate_resolution, IPL_BND);
rel(*this, complex_Obj_y[i] + complex_Obj_heights[i] <= complex_plate_resolution, IPL_BND);
}
for (int i = 0; i < complex_Obj_count; ++i)
@ -617,16 +621,16 @@ public:
};
int complex_sheet_resolution_X = 200;
int complex_plate_resolution_X = 200;
int complex_sheet_resolution_X_min = 10;
int complex_sheet_resolution_X_max = 200;
int complex_plate_resolution_X_min = 10;
int complex_plate_resolution_X_max = 200;
int complex_sheet_resolution_Y = 30;
int complex_plate_resolution_Y = 30;
int complex_sheet_resolution_Y_min = 10;
int complex_sheet_resolution_Y_max = 200;
int complex_plate_resolution_Y_min = 10;
int complex_plate_resolution_Y_max = 200;
void generate_random_complex_objects(void)
@ -665,11 +669,11 @@ public:
public:
ComplexSequentialProblemXY()
: space_vars_X(*this, 2 * complex_Obj_count, 0, complex_sheet_resolution_X)
, space_vars_Y(*this, 2 * complex_Obj_count, 0, complex_sheet_resolution_Y)
: space_vars_X(*this, 2 * complex_Obj_count, 0, complex_plate_resolution_X)
, space_vars_Y(*this, 2 * complex_Obj_count, 0, complex_plate_resolution_Y)
, time_vars(*this, complex_Obj_count, 0, complex_time_resolution)
, kine_vars_L(*this, complex_Obj_count, 0, complex_sheet_resolution_Y)
, kine_vars_R(*this, complex_Obj_count, 0, complex_sheet_resolution_Y)
, kine_vars_L(*this, complex_Obj_count, 0, complex_plate_resolution_Y)
, kine_vars_R(*this, complex_Obj_count, 0, complex_plate_resolution_Y)
{
for (int i = 0; i < complex_Obj_count; ++i)
{
@ -709,8 +713,8 @@ public:
for (int i = 0; i < complex_Obj_count; ++i)
{
rel(*this, complex_Obj_x[i] + complex_Obj_widths[i] <= complex_sheet_resolution_X, IPL_BND);
rel(*this, complex_Obj_y[i] + complex_Obj_heights[i] <= complex_sheet_resolution_Y, IPL_BND);
rel(*this, complex_Obj_x[i] + complex_Obj_widths[i] <= complex_plate_resolution_X, IPL_BND);
rel(*this, complex_Obj_y[i] + complex_Obj_heights[i] <= complex_plate_resolution_Y, IPL_BND);
}
@ -794,9 +798,9 @@ public:
};
void test_arrangement_2(void)
TEST_CASE("Arrangement test 2", "[Classical Arrangement]")
{
printf("Testing sheet arrangement 2 ...\n");
printf("Testing plate arrangement 2 ...\n");
SimpleProblem *simple_problem = new SimpleProblem();
DFS<SimpleProblem> engine(simple_problem);
@ -810,13 +814,13 @@ void test_arrangement_2(void)
Search::Statistics stat = engine.statistics();
printf("Statistics: %ld, %ld, %ld, %ld, %ld\n", stat.fail, stat.node, stat.depth, stat.restart, stat.nogood);
printf("Testing sheet arrangement 2 ... finished\n");
printf("Testing plate arrangement 2 ... finished\n");
}
void test_arrangement_3(void)
TEST_CASE("Arrangement test 3", "[Classical Arrangement]")
{
printf("Testing sheet arrangement 3 ...\n");
printf("Testing plate arrangement 3 ...\n");
ArrangementProblem *arrangement_problem = new ArrangementProblem();
DFS<ArrangementProblem> engine(arrangement_problem);
@ -832,13 +836,13 @@ void test_arrangement_3(void)
Search::Statistics stat = engine.statistics();
printf("Statistics: %ld, %ld, %ld, %ld, %ld\n", stat.fail, stat.node, stat.depth, stat.restart, stat.nogood);
printf("Testing sheet arrangement 3 ... finished\n");
printf("Testing plate arrangement 3 ... finished\n");
}
void test_arrangement_4(void)
TEST_CASE("Arrangement test 4", "[Classical Arrangement]")
{
printf("Testing sheet arrangement 4 ...\n");
printf("Testing plate arrangement 4 ...\n");
SimpleSequentialProblem *sequential_problem = new SimpleSequentialProblem();
DFS<SimpleSequentialProblem> engine(sequential_problem);
@ -855,13 +859,13 @@ void test_arrangement_4(void)
getchar();
}
printf("Testing sheet arrangement 4 ... finished\n");
printf("Testing plate arrangement 4 ... finished\n");
}
void test_arrangement_5(void)
TEST_CASE("Arrangement test 5", "[Classical Arrangement]")
{
printf("Testing sheet arrangement 5 ...\n");
printf("Testing plate arrangement 5 ...\n");
generate_random_complex_objects();
ComplexSequentialProblem *sequential_problem = new ComplexSequentialProblem();
@ -889,20 +893,20 @@ void test_arrangement_5(void)
clock_t end = clock();
printf("Time (CPU): %.3fs\n", (end - begin) / (double)CLOCKS_PER_SEC);
printf("Testing sheet arrangement 5 ... finished\n");
printf("Testing plate arrangement 5 ... finished\n");
}
void test_arrangement_6(void)
TEST_CASE("Arrangement test 6", "[Classical Arrangement]")
{
printf("Testing sheet arrangement 6 ...\n");
printf("Testing plate arrangement 6 ...\n");
generate_random_complex_objects();
complex_sheet_resolution = complex_sheet_resolution_max;
complex_plate_resolution = complex_plate_resolution_max;
while (complex_sheet_resolution > complex_sheet_resolution_min)
while (complex_plate_resolution > complex_plate_resolution_min)
{
printf("Trying sheet resolution = %d\n", complex_sheet_resolution);
printf("Trying plate resolution = %d\n", complex_plate_resolution);
ComplexSequentialProblem *sequential_problem = new ComplexSequentialProblem();
@ -943,23 +947,23 @@ void test_arrangement_6(void)
}
delete sequential_P;
complex_sheet_resolution -= 1;
complex_plate_resolution -= 1;
}
printf("Testing sheet arrangement 6 ... finished\n");
printf("Testing plate arrangement 6 ... finished\n");
}
void test_arrangement_7(void)
TEST_CASE("Arrangement test 7", "[Classical Arrangement]")
{
printf("Testing sheet arrangement 7 ...\n");
printf("Testing plate arrangement 7 ...\n");
generate_random_complex_objects();
complex_sheet_resolution_X = complex_sheet_resolution_X_max;
complex_plate_resolution_X = complex_plate_resolution_X_max;
while (complex_sheet_resolution_X > complex_sheet_resolution_X_min)
while (complex_plate_resolution_X > complex_plate_resolution_X_min)
{
printf("Trying sheet resolution X = %d, Y = %d\n", complex_sheet_resolution_X, complex_sheet_resolution_Y);
printf("Trying plate resolution X = %d, Y = %d\n", complex_plate_resolution_X, complex_plate_resolution_Y);
ComplexSequentialProblemXY *sequential_problem = new ComplexSequentialProblemXY();
Search::Options options;
@ -998,26 +1002,12 @@ void test_arrangement_7(void)
}
delete sequential_P;
complex_sheet_resolution_X -= 1;
complex_plate_resolution_X -= 1;
}
printf("Testing sheet arrangement 7 ... finished\n");
printf("Testing plate arrangement 7 ... finished\n");
}
/*----------------------------------------------------------------*/
int main(int UNUSED(argc), char **UNUSED(argv))
{
// test_arrangement_1();
// test_arrangement_2();
// test_arrangement_3();
// test_arrangement_4();
// test_arrangement_5();
// test_arrangement_6();
test_arrangement_7();
return 0;
}

View File

@ -15,30 +15,5 @@
/*----------------------------------------------------------------*/
/* Plate arrangment test 1 */
void test_arrangement_1(void);
/* Plate arrangment test 2 */
void test_arrangement_2(void);
/* Plate arrangment test 3 */
void test_arrangement_3(void);
/* Plate arrangment test 4 */
void test_arrangement_4(void);
/* Plate arrangment test 5 */
void test_arrangement_5(void);
/* Plate arrangment test 6 */
void test_arrangement_6(void);
/* Plate arrangment test 7 */
void test_arrangement_7(void);
/*----------------------------------------------------------------*/
#endif /* __SEQ_TEST_ARRANGEMENT_HPP__ */

View File

@ -19,6 +19,10 @@
#include "libslic3r/Geometry/ConvexHull.hpp"
#include "libslic3r/SVG.hpp"
#define CATCH_CONFIG_EXTERNAL_INTERFACES
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
#include <z3++.h>
#include "seq_interface.hpp"
@ -111,7 +115,7 @@ void save_import_data(const std::string &filename,
/*----------------------------------------------------------------*/
void test_interface_1(void)
TEST_CASE("Interface test 1", "[Sequential Arrangement Interface]")
{
clock_t start, finish;
@ -159,7 +163,7 @@ void test_interface_1(void)
}
void test_interface_2(void)
TEST_CASE("Interface test 2", "[Sequential Arrangement Interface]")
{
clock_t start, finish;
@ -216,7 +220,7 @@ void test_interface_2(void)
}
void test_interface_3(void)
TEST_CASE("Interface test 3", "[Sequential Arrangement Interface]")
{
clock_t start, finish;
@ -266,7 +270,7 @@ void test_interface_3(void)
}
int test_interface_4(void)
TEST_CASE("Interface test 4", "[Sequential Arrangement Interface]")
{
clock_t start, finish;
@ -290,7 +294,7 @@ int test_interface_4(void)
if (result != 0)
{
printf("Cannot load printer geometry (code: %d).\n", result);
return result;
return;
}
solver_configuration.setup(printer_geometry);
printf("Loading printer geometry ... finished\n");
@ -320,12 +324,10 @@ int test_interface_4(void)
printf("Time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC);
printf("Testing interface 4 ... finished\n");
return 0;
}
int test_interface_5(void)
TEST_CASE("Interface test 5", "[Sequential Arrangement Interface]")
{
clock_t start, finish;
@ -349,7 +351,7 @@ int test_interface_5(void)
if (result != 0)
{
printf("Cannot load printer geometry (code: %d).\n", result);
return result;
return;
}
solver_configuration.setup(printer_geometry);
printf("Loading printer geometry ... finished\n");
@ -396,12 +398,10 @@ int test_interface_5(void)
printf("Checking time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC);
printf("Testing interface 5 ... finished\n");
return 0;
}
int test_interface_6(void)
TEST_CASE("Interface test 6", "[Sequential Arrangement Interface]")
{
clock_t start, finish;
@ -430,7 +430,7 @@ int test_interface_6(void)
if (result != 0)
{
printf("Cannot load printer geometry (code: %d).\n", result);
return result;
return;
}
solver_configuration.setup(printer_geometry);
printf("Loading printer geometry ... finished\n");
@ -477,23 +477,9 @@ int test_interface_6(void)
printf("Checking time: %.3f\n", (finish - start) / (double)CLOCKS_PER_SEC);
printf("Testing interface 6 ... finished\n");
return 0;
}
/*----------------------------------------------------------------*/
int main(int SEQ_UNUSED(argc), char **SEQ_UNUSED(argv))
{
// test_interface_1();
// test_interface_2();
// test_interface_3();
// test_interface_4();
test_interface_5();
// test_interface_6();
return 0;
}

View File

@ -14,24 +14,5 @@
/*----------------------------------------------------------------*/
/* Interface test 1 */
void test_interface_1(void);
/* Interface test 2 */
void test_interface_2(void);
/* Interface test 3 */
void test_interface_3(void);
/* Interface test 4 */
int test_interface_4(void);
/* Interface test 5 */
int test_interface_5(void);
/* Interface test 6 */
int test_interface_6(void);
/*----------------------------------------------------------------*/
#endif /* __SEQ_TEST_PREPROCESS_HPP__ */

View File

@ -18,6 +18,10 @@
#include "libslic3r/Geometry/ConvexHull.hpp"
#include "libslic3r/SVG.hpp"
#define CATCH_CONFIG_EXTERNAL_INTERFACES
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
#include <z3++.h>
#include "prusaparts.hpp"
@ -45,8 +49,8 @@ using namespace Sequential;
/*----------------------------------------------------------------*/
void test_polygon_1(void)
{
TEST_CASE("Polygon test 1", "[Polygon]")
{
printf("Testing polygon 1 ...\n");
Polygon polygon_1 = {{-1000000, -1000000}, {1000000, -1000000}, {1000000, 1000000}, {-1000000, 1000000} };
@ -61,7 +65,7 @@ void test_polygon_1(void)
}
void test_polygon_2(void)
TEST_CASE("Polygon test 2", "[Polygon]")
{
printf("Testing polygon 2 ...\n");
@ -129,9 +133,7 @@ void test_polygon_2(void)
printf("%s\n", ins3 ? "yes" : "no");
bool ins4 = is_inside(point_1 - point_2);
printf("%s\n", ins4 ? "yes" : "no");
}
getchar();
}
}
printf("Testing polygon 2 ... finished\n");
@ -141,7 +143,7 @@ void test_polygon_2(void)
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)} };
void test_polygon_3(void)
TEST_CASE("Polygon test 3", "[Polygon]")
{
clock_t start, finish;
@ -281,7 +283,7 @@ void test_polygon_3(void)
}
void test_polygon_4(void)
TEST_CASE("Polygon test 4", "[Polygon]")
{
clock_t start, finish;
@ -425,7 +427,7 @@ int poly_line_count = 4;
Line poly_lines[] = {{Point(100,100), Point(200,100)}, {Point(200,100), Point(200,200)}, {Point(200,200), Point(100,200)}, {Point(100,200), Point(100,100)} };
void test_polygon_5(void)
TEST_CASE("Polygon test 5", "[Polygon]")
{
clock_t start, finish;
@ -566,7 +568,7 @@ Polygon polygon_1 = {{0, 0}, {50, 0}, {50, 50}, {0, 50}};
//Polygon polygon_1 = {{scale_(0), scale_(0)}, {scale_(50), scale_(0)}, {scale_(50), scale_(50)}, {scale_(0), scale_(50)}};
void test_polygon_6(void)
TEST_CASE("Polygon test 6", "[Polygon]")
{
clock_t start, finish;
@ -692,7 +694,7 @@ Polygon polygon_2 = {{0, 0}, {150, 0}, {150, 50}, {75, 120}, {0, 50} };
//Polygon polygon_2 = {{scale_(0), scale_(0)}, {scale_(150), scale_(0)}, {scale_(150), scale_(50)}, {scale_(75), scale_(120)}, {scale_(0), scale_(50)} };
void test_polygon_7(void)
TEST_CASE("Polygon test 7", "[Polygon]")
{
clock_t start, finish;
@ -900,7 +902,7 @@ 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}};
void test_polygon_8(void)
TEST_CASE("Polygon test 8", "[Polygon]")
{
clock_t start, finish;
@ -1202,7 +1204,7 @@ void test_polygon_8(void)
}
void test_polygon_9(void)
TEST_CASE("Polygon test 9", "[Polygon]")
{
clock_t start, finish;
@ -1502,7 +1504,7 @@ void test_polygon_9(void)
Polygon polygon_4 = {{20, 0}, {40, 0}, {60, 30}, {30, 50}, {0, 30}};
void test_polygon_10(void)
TEST_CASE("Polygon test 10", "[Polygon]")
{
clock_t start, finish;
@ -1837,7 +1839,7 @@ void test_polygon_10(void)
}
void test_polygon_11(void)
TEST_CASE("Polygon test 11", "[Polygon]")
{
clock_t start, finish;
@ -2290,7 +2292,7 @@ void test_polygon_11(void)
}
void test_polygon_12(void)
TEST_CASE("Polygon test 12", "[Polygon]")
{
clock_t start, finish;
@ -2400,7 +2402,7 @@ void test_polygon_12(void)
}
void test_polygon_13(void)
TEST_CASE("Polygon test 13", "[Polygon]")
{
clock_t start, finish;
@ -2556,7 +2558,7 @@ void test_polygon_13(void)
}
void test_polygon_14(void)
TEST_CASE("Polygon test 14", "[Polygon]")
{
clock_t start, finish;
@ -2810,7 +2812,7 @@ void test_polygon_14(void)
}
void test_polygon_15(void)
TEST_CASE("Polygon test 15", "[Polygon]")
{
clock_t start, finish;
@ -3006,7 +3008,7 @@ void test_polygon_15(void)
}
void test_polygon_16(void)
TEST_CASE("Polygon test 16", "[Polygon]")
{
clock_t start, finish;
@ -3034,26 +3036,3 @@ void test_polygon_16(void)
/*----------------------------------------------------------------*/
int main(int SEQ_UNUSED(argc), char **SEQ_UNUSED(argv))
{
//test_polygon_1();
//test_polygon_2();
//test_polygon_3();
//test_polygon_4();
//test_polygon_5();
//test_polygon_6();
//test_polygon_7();
//test_polygon_8();
//test_polygon_9();
//test_polygon_10();
//test_polygon_11();
//test_polygon_12();
//test_polygon_13();
//test_polygon_14();
//test_polygon_15();
test_polygon_16();
return 0;
}

View File

@ -14,54 +14,5 @@
/*----------------------------------------------------------------*/
/* Polygon test 1 */
void test_polygon_1(void);
/* Polygon test 2 */
void test_polygon_2(void);
/* Polygon test 3 */
void test_polygon_3(void);
/* Polygon test 4 */
void test_polygon_4(void);
/* Polygon test 5 */
void test_polygon_5(void);
/* Polygon test 6 */
void test_polygon_6(void);
/* Polygon test 7 */
void test_polygon_7(void);
/* Polygon test 8 */
void test_polygon_8(void);
/* Polygon test 9 */
void test_polygon_9(void);
/* Polygon test 10 */
void test_polygon_10(void);
/* Polygon test 11 */
void test_polygon_11(void);
/* Polygon test 12 */
void test_polygon_12(void);
/* Polygon test 13 */
void test_polygon_13(void);
/* Polygon test 14 */
void test_polygon_14(void);
/* Polygon test 15 */
void test_polygon_15(void);
/* Polygon test 16 */
void test_polygon_16(void);
/*----------------------------------------------------------------*/
#endif /* __SEQ_TEST_POLYGON_HPP__ */

View File

@ -20,6 +20,10 @@
#include "libslic3r/Geometry/ConvexHull.hpp"
#include "libslic3r/SVG.hpp"
#define CATCH_CONFIG_EXTERNAL_INTERFACES
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
#include <z3++.h>
#include "prusaparts.hpp"
@ -76,7 +80,7 @@ Polygon scale_UP(const Polygon &polygon, double x_pos, double y_pos)
std::vector<Polygon> test_polygons;
void test_preprocess_1(void)
TEST_CASE("Preprocessing test 1", "[Sequential Arrangement Preprocessing]")
{
clock_t start, finish;
@ -109,7 +113,7 @@ void test_preprocess_1(void)
}
void test_preprocess_2(void)
TEST_CASE("Preprocessing test 2", "[Sequential Arrangement Preprocessing]")
{
clock_t start, finish;
@ -326,7 +330,7 @@ void test_preprocess_2(void)
}
void test_preprocess_3(void)
TEST_CASE("Preprocessing test 3", "[Sequential Arrangement Preprocessing]")
{
clock_t start, finish;
@ -595,7 +599,7 @@ void test_preprocess_3(void)
}
void test_preprocess_4(void)
TEST_CASE("Preprocessing test 4", "[Sequential Arrangement Preprocessing]")
{
clock_t start, finish;
@ -825,7 +829,7 @@ void test_preprocess_4(void)
}
void test_preprocess_5(void)
TEST_CASE("Preprocessing test 5", "[Sequential Arrangement Preprocessing]")
{
clock_t start, finish;
@ -884,7 +888,7 @@ void test_preprocess_5(void)
}
void test_preprocess_6(void)
TEST_CASE("Preprocessing test 6", "[Sequential Arrangement Preprocessing]")
{
clock_t start, finish;
@ -1121,16 +1125,3 @@ void test_preprocess_6(void)
/*----------------------------------------------------------------*/
int main(int SEQ_UNUSED(argc), char **SEQ_UNUSED(argv))
{
//test_preprocess_1();
//test_preprocess_2();
//test_preprocess_3();
//test_preprocess_4();
//test_preprocess_5();
test_preprocess_6();
return 0;
}

View File

@ -14,25 +14,5 @@
/*----------------------------------------------------------------*/
/* Preprocess test 1 */
void test_preprocess_1(void);
/* Preprocess test 2 */
void test_preprocess_2(void);
/* Preprocess test 3 */
void test_preprocess_3(void);
/* Preprocess test 4 */
void test_preprocess_4(void);
/* Preprocess test 5 */
void test_preprocess_5(void);
/* Preprocess test 6 */
void test_preprocess_6(void);
/*----------------------------------------------------------------*/
#endif /* __SEQ_TEST_PREPROCESS_HPP__ */

View File

@ -19,6 +19,10 @@
#include "libslic3r/Geometry/ConvexHull.hpp"
#include "libslic3r/SVG.hpp"
#define CATCH_CONFIG_EXTERNAL_INTERFACES
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
#include <z3++.h>
#include "seq_defs.hpp"
@ -69,7 +73,7 @@ Polygon scale_UP(const Polygon &polygon, double x_pos, double y_pos)
}
void test_sequential_1(void)
TEST_CASE("Sequential test 1", "[Sequential Arrangement Core]")
{
printf("Testing sequential scheduling 1 ...\n");
@ -239,7 +243,7 @@ void generate_random_complex_objects(void)
typedef std::basic_string<char> sString;
void test_sequential_2(void)
TEST_CASE("Sequential test 2", "[Sequential Arrangement Core]")
{
clock_t start, finish;
@ -489,7 +493,7 @@ void generate_random_rotated_complex_objects(void)
}
void test_sequential_3(void)
TEST_CASE("Sequential test 3", "[Sequential Arrangement Core]")
{
clock_t start, finish;
@ -767,7 +771,7 @@ std::vector<Polygon> unreachable_polygons_4 = {
};
void test_sequential_4(void)
TEST_CASE("Sequential test 4", "[Sequential Arrangement Core]")
{
clock_t start, finish;
@ -1228,7 +1232,7 @@ void test_sequential_4(void)
}
void test_sequential_5(void)
TEST_CASE("Sequential test 5", "[Sequential Arrangement Core]")
{
clock_t start, finish;
@ -1724,8 +1728,7 @@ void test_sequential_5(void)
}
void test_sequential_6(void)
TEST_CASE("Sequential test 6", "[Sequential Arrangement Core]")
{
clock_t start, finish;
@ -2017,7 +2020,7 @@ void test_sequential_6(void)
}
void test_sequential_7(void)
TEST_CASE("Sequential test 7", "[Sequential Arrangement Core]")
{
clock_t start, finish;
@ -2298,16 +2301,3 @@ void test_sequential_7(void)
/*----------------------------------------------------------------*/
int main(int SEQ_UNUSED(argc), char **SEQ_UNUSED(argv))
{
// test_sequential_1();
// test_sequential_2();
// test_sequential_3();
// test_sequential_4();
// test_sequential_5();
// test_sequential_6();
test_sequential_7();
return 0;
}

View File

@ -14,28 +14,5 @@
/*----------------------------------------------------------------*/
/* Sequential arrangment test 1 */
void test_sequential_1(void);
/* Sequential arrangment test 2 */
void test_sequential_2(void);
/* Sequential arrangment test 3 */
void test_sequential_3(void);
/* Sequential arrangment test 4 */
void test_sequential_4(void);
/* Sequential arrangment test 5 */
void test_sequential_5(void);
/* Sequential arrangment test 6 */
void test_sequential_6(void);
/* Sequential arrangment test 7 */
void test_sequential_7(void);
/*----------------------------------------------------------------*/
#endif /* __SEQ_TEST_SEQUENTIAL_HPP__ */