GCC Code Coverage Report


Directory: ./
File: tests/load_problem.h
Date: 2025-03-05 17:18:30
Exec Total Coverage
Lines: 35 35 100.0%
Branches: 47 80 58.8%

Line Branch Exec Source
1
2 #ifndef _CLASS_LOAD_TEST_PROBLEMS
3 #define _CLASS_LOAD_TEST_PROBLEMS
4
5 #include <stdlib.h>
6
7 #include <fstream>
8 #include <iostream>
9 #include <string>
10
11 #include "ndcurves/bezier_curve.h"
12 #include "ndcurves/exact_cubic.h"
13 #include "ndcurves/helpers/effector_spline.h"
14 #include "ndcurves/helpers/effector_spline_rotation.h"
15 #include "ndcurves/optimization/details.h"
16 #include "ndcurves/optimization/integral_cost.h"
17 #include "ndcurves/optimization/quadratic_problem.h"
18
19 namespace ndcurves {
20
21 typedef Eigen::Vector3d point_t;
22 typedef std::vector<point_t, Eigen::aligned_allocator<point_t> > t_point_t;
23 typedef Eigen::VectorXd pointX_t;
24 typedef std::pair<double, pointX_t> Waypoint;
25 typedef std::vector<Waypoint> T_Waypoint;
26
27 typedef Eigen::Matrix<double, 1, 1> point_one;
28 typedef std::pair<double, point_one> WaypointOne;
29 typedef std::vector<WaypointOne> T_WaypointOne;
30
31 namespace optimization {
32 typedef curve_constraints<point_t> constraint_linear;
33 typedef linear_variable<double, true> linear_variable_t;
34 typedef std::vector<linear_variable_t> T_linear_variable_t;
35 typedef T_linear_variable_t::const_iterator CIT_linear_variable_t;
36 typedef std::pair<std::size_t, std::size_t> pair_size_t;
37 typedef std::pair<T_linear_variable_t, pair_size_t> var_pair_t;
38 typedef problem_data<point_t, double> problem_data_t;
39 typedef problem_definition<point_t, double> problem_definition_t;
40 typedef quadratic_problem<point_t, double> problem_t;
41
42 #define MAXBUFSIZE ((int)1e6)
43
44 6 Eigen::MatrixXd readMatrix(std::ifstream& infile) {
45 6 int cols = 0, rows = 0;
46 double buff[MAXBUFSIZE];
47
48 // Read numbers from file into buffer.
49 // ifstream infile;
50 // infile.open(filename);
51
1/2
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string line = "noise";
52
7/8
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 1 times.
✓ Branch 6 taken 25 times.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 25 times.
✓ Branch 9 taken 6 times.
31 while (!infile.eof() && !line.empty()) {
53
1/2
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
25 std::getline(infile, line);
54
55 25 int temp_cols = 0;
56
1/2
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
25 std::stringstream stream(line);
57
4/6
✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 60 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 35 times.
✓ Branch 7 taken 25 times.
60 while (!stream.eof()) stream >> buff[cols * rows + temp_cols++];
58
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if (temp_cols == 0) continue;
60
61
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 19 times.
25 if (cols == 0) cols = temp_cols;
62
63 25 rows++;
64
1/2
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
25 }
65 // infile.close();
66 6 rows--;
67
68 // Populate matrix with numbers.
69
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 Eigen::MatrixXd result(rows, cols);
70
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 6 times.
25 for (int i = 0; i < rows; i++)
71
3/4
✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29 times.
✓ Branch 4 taken 19 times.
48 for (int j = 0; j < cols; j++) result(i, j) = buff[cols * i + j];
72
73 12 return result;
74 6 }
75
76 1 problem_definition_t loadproblem(const std::string& filename) {
77
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 problem_definition_t pDef(3);
78
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 std::ifstream in(filename.c_str());
79
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
1 if (!in.is_open()) throw std::runtime_error("cant open filename");
80 // first line is degree totaltime flag
81
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 Eigen::Vector3d degTimeFlag = readMatrix(in);
82
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 pDef.degree = (std::size_t)(degTimeFlag[0]);
83
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 pDef.totalTime = degTimeFlag[1];
84
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 pDef.flag = (constraint_flag)(degTimeFlag[2]);
85 // Then startpos then empty line
86
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 pDef.init_pos = readMatrix(in);
87 // Then endpos then empty line
88
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 pDef.end_pos = readMatrix(in);
89 // Then splittimes then empty line
90
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 pDef.splitTimes_ = readMatrix(in);
91 // The inequality matrices, empty line, inequality vector as many times
92
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
2 for (int i = 0; i < pDef.splitTimes_.rows() + 1; ++i) {
93
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 pDef.inequalityMatrices_.push_back(readMatrix(in));
94
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 pDef.inequalityVectors_.push_back(readMatrix(in));
95 }
96
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 in.close();
97 2 return pDef;
98 // TODO curve constraints
99 1 }
100
101 } // namespace optimization
102 } // namespace ndcurves
103
104 #endif //_CLASS_LOAD_TEST_PROBLEMS
105