MCPcopy Create free account
hub / github.com/LiangliangNan/PolyFit / ordered_coefficients

Function ordered_coefficients

code/math/linear_program_io.cpp:77–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75#ifdef SORT_VARIABLES_IN_INCREASING_ORDER
76
77 std::vector<std::pair<int, double>> ordered_coefficients(const LinearExpression* expr, bool increasing_order /* = true*/) {
78 std::vector<std::pair<int, double>> coeffs(expr->coefficients().begin(), expr->coefficients().end());
79
80 // it is possible to make the order an parameter when constructing SortObj, but this is a bit more efficient
81 if (increasing_order) {
82 struct SortIncreasing {
83 bool operator()(const std::pair<int, double>& a, const std::pair<int, double>& b) {
84 return a.first < b.first;
85 }
86 };
87 std::sort(coeffs.begin(), coeffs.end(), SortIncreasing());
88 }
89 else {
90 struct SortDecreasing {
91 bool operator()(const std::pair<int, double>& a, const std::pair<int, double>& b) {
92 return a.first > b.first;
93 }
94 };
95 std::sort(coeffs.begin(), coeffs.end(), SortDecreasing());
96 }
97
98 return coeffs;
99 }
100#endif
101
102}

Callers 1

saveMethod · 0.85

Calls 4

SortIncreasingClass · 0.85
SortDecreasingClass · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected