Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
comb_example.C File Reference

Combinatorics helpers in Aleph-w (ah-comb.H): transpose, Cartesian products, combinations. More...

#include <iostream>
#include <iomanip>
#include <string>
#include <tclap/CmdLine.h>
#include <htlist.H>
#include <ah-comb.H>
Include dependency graph for comb_example.C:

Go to the source code of this file.

Functions

void print_section (const string &title)
 
void print_subsection (const string &title)
 
template<typename T >
void print_list (const string &label, const DynList< T > &l)
 
template<typename T >
void print_matrix (const string &label, const DynList< DynList< T > > &mat)
 
void demo_transpose ()
 
void demo_permutations ()
 
void demo_perm_predicates ()
 
void demo_traverse ()
 
void demo_fold ()
 
void demo_build ()
 
void demo_practical ()
 
int main (int argc, char *argv[])
 

Detailed Description

Combinatorics helpers in Aleph-w (ah-comb.H): transpose, Cartesian products, combinations.

Overview

This example demonstrates combinatorics utilities from ah-comb.H, including:

  • matrix/list transpose helpers
  • enumeration of Cartesian products (called "permutations" in this demo)
  • combination builders
  • predicate/fold/traversal helpers over generated configurations

Terminology note

In this file, the "permutations" demos are about Cartesian products of lists (choose one element from each list), not the classic factorial n! permutations.

Usage / CLI

This example uses TCLAP and supports selecting one section:

  • --section / -s <section>: one of transpose, perm, predicates, traverse, fold, build, practical, all (default).
  • --help: show help.
# Run all demos
./comb_example
# Run a specific section
./comb_example --section transpose
./comb_example --section perm
./comb_example --section predicates
./comb_example --section traverse
./comb_example --section fold
./comb_example --section build
./comb_example --section practical
# Short form
./comb_example -s perm
# Show help
./comb_example --help

Complexity

  • transpose of an n×m matrix-like structure: O(n*m)
  • Cartesian product enumeration: O(∏ n_i) outputs (can be exponential)
  • k-combinations from n: O(C(n, k)) outputs

Pitfalls and edge cases

  • Cartesian products grow exponentially; keep input lists small.

References / see also

Author
Leandro Rabindranath León
Date
2024

Definition in file comb_example.C.

Function Documentation

◆ demo_build()

◆ demo_fold()

◆ demo_perm_predicates()

◆ demo_permutations()

◆ demo_practical()

◆ demo_transpose()

◆ demo_traverse()

◆ main()

int main ( int  argc,
char *  argv[] 
)

◆ print_list()

template<typename T >
void print_list ( const string &  label,
const DynList< T > &  l 
)

Definition at line 96 of file comb_example.C.

References LocateFunctions< Container, Type >::get_it(), l, and Aleph::maps().

◆ print_matrix()

template<typename T >
void print_matrix ( const string &  label,
const DynList< DynList< T > > &  mat 
)

Definition at line 110 of file comb_example.C.

References LocateFunctions< Container, Type >::get_it(), and Aleph::maps().

Referenced by demo_transpose().

◆ print_section()

void print_section ( const string &  title)

◆ print_subsection()

void print_subsection ( const string &  title)