-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgo_x.h
56 lines (38 loc) · 1.34 KB
/
algo_x.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
#ifndef ALGO_X_H
#define ALGO_X_H
#include <stdbool.h>
// A small library that implements Knuth's algorithm X with dancing links
// ------------------------------------------------------------------------------------------ Data structures
struct node {
struct node* left;
struct node* right;
struct node* top;
struct node* bottom;
struct column* col;
};
typedef struct node Node;
struct column {
struct node* node;
int size;
};
typedef struct column Column;
struct matrix {
struct node* head;
struct column* headers;
int num_columns;
};
typedef struct matrix Matrix;
// ------------------------------------------------------------------------------------------ Getters
Matrix* get_matrix(int num_primaries, int num_secondaries);
void destroy_matrix(Matrix* matrix);
// ------------------------------------------------------------------------------------------ Construct matrix
// Use this struct to add constraints to the matrix. It corresponds to adding a row to the matrix.
// The integers in the array denote the column that should have a '1' in that particular row.
struct constraint {
int* array;
int length;
};
void add_constraints(struct constraint* constraint_row, Matrix* matrix);
// ------------------------------------------------------------------------------------------ Algo X
int algorithm_x(Matrix* matrix);
#endif // ALGO_X_H