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