30 const std::string set_begin {
"{" };
31 const std::string set_end {
"}" };
32 const std::string set_intersection {
"&" };
33 const std::string set_difference {
"\\" };
34 const std::string set_union {
"|" };
35 const std::string set_separator {
" " };
36 const std::string set_comma {
"," };
37 const std::string feature_and {
"*" };
38 const std::string feature_or {
"+" };
39 const std::string feature_not {
"!" };
40 const std::string feature {
"f" };
41 const std::string feature_separator {
" " };
42 const std::string system {
"S" };
43 const std::string difference_expression {
"E" };
44 const std::string separator {
"\t" };
45 const std::string opening_parenthesis {
"(" };
46 const std::string closing_parenthesis {
")" };
107 using features_isolation_t = std::map<std::string,systems_difference_t>;
108 using differences_t = std::vector<system_feature_difference_t>;
114 if (from == 0llu || to == 0llu)
128 return n == 0llu ? 1llu :
product(1llu,n);
166 return power(2,exponent);
172 std::vector<T>&
concat(std::vector<T>& destination,
const std::vector<T>& v)
174 destination.reserve(destination.size() + v.size());
175 destination.insert(destination.end(),v.cbegin(),v.cend());
184 return std::find(v.cbegin(),v.cend(),e) != v.cend();
194 std::vector<feature_id_t> result;
209 return (M == 2 || M == 4 || M == 6 || M == 8 || M == 11 || M == 13 ||
210 M == 14 || M == 16 || M == 17 || M == 19
218 return (M == 3 || M == 4 || M == 7 || M == 8 || M == 12 || M == 13 ||
219 M == 15 || M == 16 || M == 18 || M == 19
227 return (M == 5 || M == 6 || M == 7 || M == 8 || M == 9 || M == 10 ||
228 M == 11 || M == 12 || M == 13 || M == 14 || M == 15 ||
229 M == 16 || M == 17 || M == 18 || M == 19
237 return (M == 9 || M == 11 || M == 12 || M == 13 || M == 17 ||
246 return (M == 10 || M == 14 || M == 15 || M == 16 || M == 17 ||
255 return feature + std::to_string(i);
262 std::string result { feature + std::to_string(ids.at(0)) };
263 for (std::size_t i { 1 }; i < ids.size(); ++i)
265 result = result + feature_separator + feature_or + feature_separator
267 + std::to_string(ids.at(i));
276 std::string result { feature + std::to_string(ids.at(0)) };
277 for (std::size_t i { 1 }; i < ids.size(); ++i)
279 result = result + feature_separator + feature_and + feature_separator
281 + std::to_string(ids.at(i));
290 return feature_not + feature + std::to_string(i);
297 std::string result { feature_not + feature +
298 std::to_string(ids.at(0)) };
299 for (std::size_t i { 1 }; i < ids.size(); ++i)
301 result = result + feature_separator + feature_or + feature_separator
303 + feature + std::to_string(ids.at(i));
312 std::string result { feature_not + feature +
313 std::to_string(ids.at(0)) };
314 for (std::size_t i { 1 }; i < ids.size(); ++i)
316 result = result + feature_separator + feature_and + feature_separator
318 + feature + std::to_string(ids.at(i));
327 return system + std::to_string(n);
334 return difference_expression + std::to_string(n);
342 for (
const auto& v : ids)
344 result |= idf.at(v - 1).second;
354 for (
const auto& v : ids)
356 result &= idf.at(v - 1).second;
366 for (
const auto& v : ids)
368 result |= nf.at(v - 1).second;
378 for (
const auto& v : ids)
380 result &= nf.at(v - 1).second;
389 std::vector<feature_id_t> result;
390 for (
maxnat_t bit { 0 }; bit <
sizeof(u) * CHAR_BIT; ++bit)
394 result.push_back(bit + 1);
409 :m_symbols(symbols),m_k(
k)
411 if (
k > symbols.size())
413 throw std::logic_error(
"n = " +
414 std::to_string(symbols.size()) +
415 ", k = " + std::to_string(
k) +
416 " violates n >= k!\n"
425 std::size_t start { };
426 for (
auto i {
k() }; i > 0; --i)
428 m_state.push_back(start++);
433 std::size_t
k()
const
441 for (
auto i { m_state.size() }; i > 0; --i)
443 auto v { m_state.at(i - 1) };
444 if (v < m_symbols.size() &&
445 v + 1 +
k() - i < m_symbols.size()
448 m_state.at(i - 1) += 1;
449 for (
auto j { i }; j < m_state.size(); ++j)
451 m_state.at(j) = m_state.at(j - 1) + 1;
463 std::vector<T> result;
464 for (
const auto& e : m_state)
466 result.push_back(m_symbols.at(e));
471 std::vector<T> m_symbols;
472 std::vector <std::size_t> m_state;
492 m_N {
hasN(m_) ? n_ : 0u },
497 (
hasN(m_) ? n_ : 0) +
504 (
hasN(m_) ? n_ : 0) +
510 for (std::size_t i { 1 }; i <= m_n; ++i)
512 m_raw_independent_features.push_back(i);
514 for (std::size_t i { 2 }; i <= m_n; ++i)
519 m_raw_dependent_features.push_back(c());
526 const auto&
n()
const
532 const auto&
F()
const
538 const auto&
S()
const
544 const auto&
M()
const
550 const auto&
O()
const
556 const auto&
A()
const
562 const auto&
N()
const
568 const auto&
ON()
const
574 const auto&
AN()
const
580 const auto&
DF()
const
586 const auto&
T()
const
592 const auto&
D()
const
601 std::vector<std::string> result;
602 for (
const auto& i : f)
613 std::vector<std::string> result;
626 sort(result.begin(),result.end());
635 std::vector<std::string> result;
654 sort(result.begin(),result.end());
663 std::vector<std::string> result;
667 for (
const auto& i : f)
679 std::vector<std::string> result;
693 sort(result.begin(),result.end());
702 std::vector<std::string> result;
722 sort(result.begin(),result.end());
731 std::vector<std::string> result;
738 sort(result.begin(),result.end());
745 std::vector<std::vector<std::string>> result;
756 return m_raw_independent_features;
763 return m_raw_dependent_features;
769 return m_all_systems;
776 os <<
"M" <<
M() << separator <<
"selected model\n"
777 <<
T() << separator <<
"T" << separator <<
"actual total number of features\n"
778 <<
F() << separator <<
"F" << separator <<
"number of independent features\n"
779 <<
DF() << separator <<
"DF" << separator <<
"actual total number of inherently dependent features\n"
780 <<
O() << separator <<
"O" << separator <<
"actual number of or-features\n"
781 <<
A() << separator <<
"A" << separator <<
"actual number of and-features\n"
782 <<
N() << separator <<
"N" << separator <<
"actual number of not-features\n"
783 <<
ON() << separator <<
"ON" << separator <<
"actual number of or-not-features\n"
784 <<
AN() << separator <<
"AN" << separator <<
"actual number of and-not-features\n"
785 <<
S() << separator <<
"S" << separator <<
"number of systems of SPL\n"
786 <<
D() << separator <<
"D" << separator <<
"number of all set differences of SPL systems\n";
797 for (
const auto& feature : system)
799 os << feature << separator;
818 std::vector<feature_id_t> m_raw_independent_features;
819 std::vector<std::vector<feature_id_t>> m_raw_dependent_features;
820 std::vector<feature_names_t> m_all_systems;
843 m_all_features.reserve(m_all_features.size()
844 + m_independent_features.size()
845 + m_or_features.size()
846 + m_and_features.size()
847 + m_not_features.size()
848 + m_or_not_features.size()
849 + m_and_not_features.size()
852 m_independent_features),m_or_features),m_and_features),
853 m_not_features),m_or_not_features),m_and_not_features
855 std::sort(m_all_features.begin(),m_all_features.end());
879 }
while (combination.next());
898 }
while (combination.next());
931 }
while (combination.next());
950 }
while (combination.next());
959 return m_independent_features;
965 return m_or_features;
971 return m_and_features;
977 return m_not_features;
983 return m_or_not_features;
989 return m_and_not_features;
995 return m_all_features;
1001 return m_feature_isolations;
1007 features_isolation_t result;
1024 result.insert(std::make_pair(f,difference));
1033 std::size_t counter { },
1035 os << opening_parenthesis << set_separator;
1036 for (
const auto& e : s)
1039 if (++counter < size)
1041 os << set_separator << set_intersection << set_separator;
1044 os << set_separator << closing_parenthesis;
1049 void print_unions(
const std::set<std::string>& s,std::ostream& os = std::cout)
const
1051 std::size_t counter { },
1053 os << opening_parenthesis << set_separator;
1054 for (
const auto& e : s)
1057 if (++counter < size)
1059 os << set_separator << set_union << set_separator;
1062 os << set_separator << closing_parenthesis;
1071 os << e.first << separator;
1073 os << set_separator << set_difference << set_separator;
1079 std::vector<std::string> m_independent_features,
1086 features_isolation_t m_feature_isolations;
1103 m_non_empty_differences = generate_non_empty_differences();
1110 if (s.length() < system.length() + 1 || s.find(system) != 0)
1112 throw std::logic_error(s +
" is not a system identifier.");
1114 std::set<std::string> result;
1115 std::size_t pos { stoull(s.erase(0,system.size())) };
1129 for (
maxnat_t position { 0 }; position <
S(); ++position)
1131 if (s & 1ull << position)
1148 std::set<std::string> result;
1155 auto left { result };
1158 std::set_intersection(left.begin(),left.end(),
1159 right.begin(),right.end(),
1160 std::inserter(result,result.begin()));
1161 if (result.size() == 0)
1175 std::set<std::string> result;
1176 if (diff.
unions.size() >= 1)
1178 auto first { diff.
unions.cbegin() };
1180 while (++first != diff.
unions.end())
1182 auto left { result };
1185 std::set_union(left.begin(),left.end(),
1186 right.begin(),right.end(),
1187 std::inserter(result,result.begin()));
1199 std::set<std::string> result;
1200 std::set_difference(intersections.begin(),intersections.end(),
1201 unions.begin(),unions.end(),
1202 std::inserter(result,result.begin()));
1206 differences_t generate_non_empty_differences()
const
1208 differences_t result { };
1215 if (res.size() != 1)
1217 throw std::length_error(
"Set size = " + std::to_string(res.size()) +
", must be 1!");
1219 result.push_back(system_feature_difference_t { e,*res.begin(),diff });
1228 return m_non_empty_differences;
1238 << e.feature << separator;
1240 os << set_separator << set_difference << set_separator;
1246 differences_t m_non_empty_differences;
1271 m_independent_features),m_or_features),m_and_features),
1272 m_not_features),m_or_not_features),m_and_not_features
1284 bitmask |= (1llu << s);
1292 return m_systems_bitmask;
1302 if (index & (1llu << s))
1308 result.difference.unions.insert(
system_name(s + 1));
1317 differences_t result;
1322 sort(result.begin(),result.end(),[] (
auto a,
auto b) ->
bool { return a.difference_id < b.difference_id; });
1329 return m_differences;
1346 if (counter == 0llu)
1348 bit = (bit == 1llu ? 0llu : 1llu);
1369 }
while (combination.next());
1387 }
while (combination.next());
1403 result.push_back(make_pair(feature_not + f.first,~(f.second ^
systems_bitmask())));
1421 }
while (combination.next());
1439 }
while (combination.next());
1448 return m_independent_features;
1454 return m_or_features;
1460 return m_and_features;
1466 return m_not_features;
1472 return m_or_not_features;
1478 return m_and_not_features;
1484 return m_all_features;
1491 std::size_t counter { },
1493 os << opening_parenthesis << set_separator;
1494 for (
const auto& e : s)
1497 if (++counter < size)
1499 os << set_separator << set_intersection << set_separator;
1502 os << set_separator << closing_parenthesis;
1507 void print_unions(
const std::set<std::string>& s,std::ostream& os = std::cout)
const
1509 std::size_t counter { },
1511 os << opening_parenthesis << set_separator;
1512 for (
const auto& e : s)
1515 if (++counter < size)
1517 os << set_separator << set_union << set_separator;
1520 os << set_separator << closing_parenthesis;
1530 << e.feature << separator;
1532 os << set_separator << set_difference << set_separator;
1539 differences_t m_differences;
Definition: features.hpp:404
bool next()
Definition: features.hpp:439
void initialize()
Definition: features.hpp:423
std::size_t k() const
Definition: features.hpp:433
combination_t(const std::vector< T > symbols, std::size_t k)
Definition: features.hpp:408
std::vector< T > operator()() const
Definition: features.hpp:461
Definition: features.hpp:1254
feature_expression_t and_features() const
Definition: features.hpp:1458
differences_t calculate_differences() const
Definition: features.hpp:1315
void print_results(std::ostream &os=std::cout) const
Definition: features.hpp:1525
maxnat_t initialize_bitmask() const
Definition: features.hpp:1279
feature_expression_t all_features() const
Definition: features.hpp:1482
feature_expression_t not_features() const
Definition: features.hpp:1464
feature_expression_t calculate_and_not_features() const
Definition: features.hpp:1428
feature_expression_t independent_features() const
Definition: features.hpp:1446
void print_unions(const std::set< std::string > &s, std::ostream &os=std::cout) const
Definition: features.hpp:1507
feature_expression_t calculate_not_features() const
Definition: features.hpp:1394
feature_expression_t calculate_and_features() const
Definition: features.hpp:1376
feature_expression_t or_not_features() const
Definition: features.hpp:1470
feature_expression_t and_not_features() const
Definition: features.hpp:1476
feature_expression_t calculate_or_features() const
Definition: features.hpp:1358
system_feature_difference_t calculate_difference(maxnat_t index, const std::string &name) const
Definition: features.hpp:1297
void print_intersections(const std::set< std::string > &s, std::ostream &os=std::cout) const
Definition: features.hpp:1489
feature_expression_t or_features() const
Definition: features.hpp:1452
feature_expression_t calculate_or_not_features() const
Definition: features.hpp:1410
feature_location_calculation_t(feature_id_t n_, feature_id_t m_)
Definition: features.hpp:1259
differences_t differences() const
Definition: features.hpp:1327
const maxnat_t & systems_bitmask() const
Definition: features.hpp:1290
feature_expression_t calculate_independent_features() const
Definition: features.hpp:1333
Definition: features.hpp:1094
std::set< std::string > evaluate_intersections(const systems_difference_t &diff) const
Definition: features.hpp:1146
systems_difference_t generate_difference(maxnat_t s) const
Definition: features.hpp:1126
feature_location_differences_t(feature_id_t n_, feature_id_t m_)
Definition: features.hpp:1099
void print_results(std::ostream &os=std::cout) const
Definition: features.hpp:1233
std::set< std::string > evaluate_unions(const systems_difference_t &diff) const
Definition: features.hpp:1173
std::set< std::string > system2features(std::string s) const
Definition: features.hpp:1108
differences_t non_empty_differences() const
Definition: features.hpp:1226
std::set< std::string > evaluate_difference(const systems_difference_t &diff) const
Definition: features.hpp:1195
Definition: features.hpp:828
feature_names_t generate_or_not_features() const
Definition: features.hpp:920
feature_names_t generate_and_features() const
Definition: features.hpp:887
feature_names_t generate_or_features() const
Definition: features.hpp:868
const std::vector< std::string > & or_not_features() const
Definition: features.hpp:981
const std::vector< std::string > & not_features() const
Definition: features.hpp:975
void print_unions(const std::set< std::string > &s, std::ostream &os=std::cout) const
Definition: features.hpp:1049
feature_names_t generate_and_not_features() const
Definition: features.hpp:939
void print_intersections(const std::set< std::string > &s, std::ostream &os=std::cout) const
Definition: features.hpp:1031
void print_results(std::ostream &os=std::cout) const
Definition: features.hpp:1067
const std::vector< std::string > & and_features() const
Definition: features.hpp:969
feature_names_t generate_not_features() const
Definition: features.hpp:906
const features_isolation_t & feature_isolations() const
Definition: features.hpp:999
const std::vector< std::string > & all_features() const
Definition: features.hpp:993
const std::vector< std::string > & and_not_features() const
Definition: features.hpp:987
const std::vector< std::string > & or_features() const
Definition: features.hpp:963
feature_names_t generate_independent_features() const
Definition: features.hpp:861
features_isolation_t generate_feature_isolations() const
Definition: features.hpp:1005
feature_location_isolation_t(feature_id_t n_, feature_id_t m_)
Definition: features.hpp:833
const feature_names_t & independent_features() const
Definition: features.hpp:957
Definition: features.hpp:479
feature_names_t generate_and_not_features(const std::vector< feature_id_t > &nf) const
Definition: features.hpp:700
feature_location_t(feature_id_t n_, feature_id_t m_)
Definition: features.hpp:484
const auto & T() const
Definition: features.hpp:586
const auto & D() const
Definition: features.hpp:592
const auto & DF() const
Definition: features.hpp:580
const auto & all_systems() const
Definition: features.hpp:767
void print_header(std::ostream &os=std::cout)
Definition: features.hpp:774
const auto & O() const
Definition: features.hpp:550
const auto & M() const
Definition: features.hpp:544
systems_t generate_all_systems() const
Definition: features.hpp:743
const auto & S() const
Definition: features.hpp:538
feature_names_t generate_or_not_features(const std::vector< feature_id_t > &nf) const
Definition: features.hpp:677
feature_names_t generate_not_features(const std::vector< feature_id_t > &nf) const
Definition: features.hpp:661
const auto & F() const
Definition: features.hpp:532
feature_names_t generate_or_features(const std::vector< feature_id_t > &f) const
Definition: features.hpp:611
const std::vector< feature_id_t > & raw_independent_features() const
Definition: features.hpp:754
feature_names_t generate_and_features(const std::vector< feature_id_t > &f) const
Definition: features.hpp:633
feature_names_t generate_independent_features(const std::vector< feature_id_t > &f) const
Definition: features.hpp:599
const auto & AN() const
Definition: features.hpp:574
const auto & n() const
Definition: features.hpp:526
system_t generate_system(const std::vector< feature_id_t > &f) const
Definition: features.hpp:729
const std::vector< std::vector< feature_id_t > > & raw_dependent_features() const
Definition: features.hpp:761
const auto & N() const
Definition: features.hpp:562
const auto & A() const
Definition: features.hpp:556
void print_systems(std::ostream &os=std::cout)
Definition: features.hpp:792
const auto & ON() const
Definition: features.hpp:568
uintmax_t maxnat_t
Definition: fl.cpp:30
Definition: features.hpp:29
std::string difference_name(feature_id_t n)
Definition: features.hpp:332
bool hasN(model_id_t M)
Definition: features.hpp:225
maxnat_t factorial(maxnat_t n)
Definition: features.hpp:126
maxnat_t combinations(maxnat_t n, maxnat_t k)
Definition: features.hpp:133
maxnat_t power2(maxnat_t exponent)
Definition: features.hpp:164
unsigned short int model_id_t
Definition: features.hpp:53
std::string or_feature_name(const std::vector< feature_id_t > &ids)
Definition: features.hpp:260
unsigned short int feature_id_t
Definition: features.hpp:50
maxnat_t product(maxnat_t from, maxnat_t to)
Definition: features.hpp:112
std::vector< feature_id_t > negate(const std::vector< feature_id_t > &v, feature_id_t n)
Definition: features.hpp:192
std::vector< feature_id_t > unsigned2vector(maxnat_t u)
Definition: features.hpp:387
std::vector< std::pair< std::string, maxnat_t > > feature_expression_t
Definition: features.hpp:61
maxnat_t and_not_feature_value(const std::vector< feature_id_t > &ids, const feature_expression_t &nf, const maxnat_t &bitmask)
Definition: features.hpp:375
bool hasAN(model_id_t M)
Definition: features.hpp:244
std::vector< T > & concat(std::vector< T > &destination, const std::vector< T > &v)
Definition: features.hpp:172
bool contains(const std::vector< T > &v, const T &e)
Definition: features.hpp:182
bool hasO(model_id_t M)
Definition: features.hpp:207
std::string and_feature_name(const std::vector< feature_id_t > &ids)
Definition: features.hpp:274
std::string independent_feature_name(feature_id_t i)
Definition: features.hpp:253
feature_names_t system_t
Definition: features.hpp:70
std::string system_name(feature_id_t n)
Definition: features.hpp:325
bool hasA(model_id_t M)
Definition: features.hpp:216
maxnat_t power(maxnat_t base, maxnat_t exponent)
Definition: features.hpp:152
std::vector< std::string > feature_names_t
Definition: features.hpp:67
std::string or_not_feature_name(const std::vector< feature_id_t > &ids)
Definition: features.hpp:295
std::string and_not_feature_name(const std::vector< feature_id_t > &ids)
Definition: features.hpp:310
std::map< maxnat_t, std::string > expression_feature_t
Definition: features.hpp:64
bool hasON(model_id_t M)
Definition: features.hpp:235
maxnat_t sum_of_combinations(maxnat_t n, maxnat_t k)
Definition: features.hpp:140
std::vector< system_t > systems_t
Definition: features.hpp:74
maxnat_t or_not_feature_value(const std::vector< feature_id_t > &ids, const feature_expression_t &nf)
Definition: features.hpp:363
uintmax_t maxnat_t
Definition: features.hpp:56
std::string not_feature_name(feature_id_t i)
Definition: features.hpp:288
maxnat_t or_feature_value(const std::vector< feature_id_t > &ids, const feature_expression_t &idf)
Definition: features.hpp:339
maxnat_t and_feature_value(const std::vector< feature_id_t > &ids, const feature_expression_t &idf)
Definition: features.hpp:351
Definition: features.hpp:95
maxnat_t difference_id
Definition: features.hpp:98
systems_difference_t difference
Definition: features.hpp:104
std::string feature
Definition: features.hpp:101
Definition: features.hpp:79
std::set< std::string > unions
Definition: features.hpp:87
std::set< std::string > intersections
Definition: features.hpp:83