-
Notifications
You must be signed in to change notification settings - Fork 0
/
PermutationAndConmbinationHelpers.h
58 lines (50 loc) · 1.32 KB
/
PermutationAndConmbinationHelpers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef CNCR_H
#define CNCR_H
#include <vector>
#include <list>
class CnCr
{
private:
std::vector<bool>* pBitmask;
bool first;
int N;
int K;
public:
CnCr(int fromN, int takeK);
~CnCr();
/* Get next combination until NULL, that is there is none left */
std::vector<int>* choose_next_K_from_N();
std::vector<int>* those_not_in_K_from_N();
};
class RouteDesignatorPermutator
{
private:
std::vector<int>& rDesignator;
int node_count;
int route_count;
int inc_pos;
public:
RouteDesignatorPermutator(std::vector<int>& designator_to_permute, int nodes, int routes);
bool next_designator();
};
class RouteEndPermutator
{
private:
std::vector<int>* route_starts;
std::vector< std::list<int> > valid_end_nodes_for_routes;
std::vector< std::list<int>::iterator > current_route_end_nodes;
int current_nondegenerate_route_count;
int node_count;
int route_count;
// helper method that validates the current configuration and advances
// with next_permutation until a valid is found.
bool is_valid_permutation();
public:
RouteEndPermutator(int nodes, int routes);
bool initialize_permutator(std::vector<int>& remaining_nodes, std::vector<int>& start_nodes);
std::vector<int>* get_end_nodes();
int get_nondegenerate_route_count();
// skips all degerate configurations and
bool next_valid_permutation();
};
#endif /*CNCR_H*/