Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
GF2Solver.h
Go to the documentation of this file.
1
33#pragma once
34
35#include <ogdf/basic/Array.h>
36#include <ogdf/basic/List.h>
37#include <ogdf/basic/basic.h>
38#include <ogdf/basic/memory.h>
39
40#include <iomanip>
41#include <iostream>
42
43namespace ogdf {
44
45class GF2Solver {
46 static constexpr int chunkSize = 13;
47 static constexpr int chunkSize2 = 9;
48
49 template<int Dim, typename Next>
50 struct ChunkBase {
51 int m_x[Dim];
52 int m_max;
53 Next* m_next;
54
55 bool full() const { return m_max == Dim - 1; }
56
58 m_max = -1;
59 m_next = nullptr;
60 for (int i = 0; i < Dim; i++) {
61 m_x[i] = 0;
62 }
63 }
64
66 };
67
68 struct Chunk : public ChunkBase<chunkSize, Chunk> {
70
71 void add(int x) { m_x[++m_max] = x; }
72
74 };
75
76 struct Chunk2 : public ChunkBase<chunkSize2, Chunk2> {
78
80
81 void add(int x, ListIterator<int> it) {
82 ++m_max;
83 m_x[m_max] = x;
84 m_it[m_max] = it;
85 }
86
88 };
89
90#if 0
91 struct Row {
92 Chunk *m_pHead;
93 Chunk *m_pTail;
94
95 Row() {
96 m_pHead = m_pTail = nullptr;
97 }
98
99 void addChunk(Chunk *p) {
100 if(m_pHead == nullptr)
101 m_pHead = m_pTail = p;
102 else {
103 m_pTail->m_next = p;
104 m_pTail = p;
105 }
106 }
107 };
108#endif
109
110 struct Row2 {
113
114 Row2() { m_pHead = m_pTail = nullptr; }
115
116 void addChunk(Chunk2* p) {
117 if (m_pHead == nullptr) {
118 m_pHead = m_pTail = p;
119 } else {
120 m_pTail->m_next = p;
121 m_pTail = p;
122 }
123 }
124 };
125
128
129#if 0
130 Chunk *getChunk() {
131 if(m_freelist != nullptr) {
132 Chunk *p = m_freelist;
133 m_freelist = p->m_next;
134 p->m_next = nullptr;
135 p->m_max = -1;
136 return p;
137 }
138 return new Chunk;
139 }
140#endif
141
143 if (m_freelist2 != nullptr) {
144 Chunk2* p = m_freelist2;
145 m_freelist2 = p->m_next;
146 p->m_next = nullptr;
147 p->m_max = -1;
148 return p;
149 }
150 return new Chunk2;
151 }
152
153#if 0
154 void freeChunk(Chunk *p) {
155 p->m_next = m_freelist;
156 m_freelist = p;
157 }
158#endif
159
161 p->m_next = m_freelist2;
162 m_freelist2 = p;
163 }
164
165#if 0
166 void freeChunks(Chunk *pHead, Chunk *pTail) {
167 pTail->m_next = m_freelist;
168 m_freelist = pHead;
169 }
170#endif
171
172 void freeChunks2(Chunk2* pHead, Chunk2* pTail) {
173 pTail->m_next = m_freelist2;
174 m_freelist2 = pHead;
175 }
176
177#if 0
178 bool contains(const Row &r, int x) const;
179
180 void symDiff(Row &r, const Row &other);
181#endif
182 void symDiff2(int r1, int r2, Array<Row2>& rows, Array<List<int>>& cols);
183
184public:
185 class Equation {
187
188 public:
190
191 void print() { std::cout << m_objects << std::endl; }
192
194
196
197#if 0
198 bool contains(OBJ obj) const {
199 for(OBJ x : m_objects) {
200 if(x == obj)
201 return true;
202 else if(x > obj)
203 return false;
204 }
205 return false;
206 }
207#endif
208
209 int size() const { return m_objects.size(); }
210
213 while (it.valid() && *it < obj) {
214 ++it;
215 }
216 if (it.valid()) {
217 if (*it != obj) {
218 m_objects.insertBefore(obj, it);
219 }
220 } else {
221 m_objects.pushBack(obj);
222 }
223
224 return *this;
225 }
226
227#if 0
228 Equation &operator^=(const Equation &other) {
229 ListConstIterator<OBJ> itOther = other.m_objects.begin();
231
232 while(itOther.valid())
233 {
234 if(!it.valid()) {
235 m_objects.pushBack(*itOther);
236 ++itOther;
237
238 } else if(*it == *itOther) {
239 ListIterator<OBJ> itDel = it;
240 ++it; ++itOther;
241 m_objects.del(itDel);
242
243 } else if(*itOther < *it) {
244 m_objects.insertBefore(*itOther, it);
245 ++itOther;
246
247 } else {
248 ++it;
249 }
250 }
251
252 return *this;
253 }
254#endif
255
257 };
258
259 class Matrix {
263
264 public:
265 Matrix() : m_equations(0, 255, nullptr), m_numRows(0), m_numCols(0) { }
266
268 for (int i = 0; i < m_numRows; ++i) {
269 delete m_equations[i];
270 }
271 }
272
274 OGDF_ASSERT(i >= 0);
276 return *m_equations[i];
277 }
278
279 const Equation& operator[](int i) const {
280 OGDF_ASSERT(i >= 0);
282 return *m_equations[i];
283 }
284
285 int numRows() const { return m_numRows; }
286
287 int numColumns() const { return m_numCols; }
288
289 int addRow() {
290 int i = m_numRows++;
291 if (i == m_equations.size()) {
292 m_equations.grow(m_equations.size(), nullptr);
293 }
294 m_equations[i] = new Equation;
295
296 return i;
297 }
298
299 int addColumn() { return m_numCols++; }
300
301 void clear() {
302 for (int i = 0; i < m_numRows; ++i) {
303 delete m_equations[i];
304 }
305
306 m_equations.init(0, 255, nullptr);
307 m_numRows = m_numCols = 0;
308 }
309
310 void print() const {
311 for (int i = 0; i < m_numRows; ++i) {
312 std::cout << std::setw(4) << i << ": ";
313 m_equations[i]->print();
314 }
315 }
316 };
317
319 : m_freelist(nullptr), m_freelist2(nullptr), m_matrix(Mx) { }
320
322
323 bool solve();
324 bool solve2();
325
326
327private:
329};
330
331}
Declaration and implementation of Array class and Array algorithms.
Declaration of doubly linked lists and iterators.
Basic declarations, included by all source files.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
Equation & operator|=(int obj)
Definition GF2Solver.h:211
ListConstIterator< int > begin() const
Definition GF2Solver.h:193
ListConstIterator< int > end() const
Definition GF2Solver.h:195
Equation & operator[](int i)
Definition GF2Solver.h:273
Array< Equation * > m_equations
Definition GF2Solver.h:260
const Equation & operator[](int i) const
Definition GF2Solver.h:279
Matrix & m_matrix
Definition GF2Solver.h:328
void freeChunks2(Chunk2 *pHead, Chunk2 *pTail)
Definition GF2Solver.h:172
void freeChunk2(Chunk2 *p)
Definition GF2Solver.h:160
void symDiff2(int r1, int r2, Array< Row2 > &rows, Array< List< int > > &cols)
Chunk2 * m_freelist2
Definition GF2Solver.h:127
static constexpr int chunkSize2
Definition GF2Solver.h:47
Chunk2 * getChunk2()
Definition GF2Solver.h:142
Chunk * m_freelist
Definition GF2Solver.h:126
GF2Solver(GF2Solver::Matrix &Mx)
Definition GF2Solver.h:318
static constexpr int chunkSize
Definition GF2Solver.h:46
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
int size() const
Returns the number of elements in the list.
Definition List.h:1488
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1547
void del(iterator it)
Removes it from the list.
Definition List.h:1611
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
Definition List.h:1566
Encapsulates a pointer to a list element.
Definition List.h:113
bool valid() const
Returns true iff the iterator points to an element.
Definition List.h:153
iterator begin()
Returns an iterator to the first element of the list.
Definition List.h:391
iterator end()
Returns an iterator to one-past-last element of the list.
Definition List.h:409
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:85
Declaration of memory manager for allocating small pieces of memory.
The namespace for all OGDF objects.
void add(int x, ListIterator< int > it)
Definition GF2Solver.h:81
ListIterator< int > m_it[chunkSize2]
Definition GF2Solver.h:77
void addChunk(Chunk2 *p)
Definition GF2Solver.h:116