Skip to content

Commit 525a14f

Browse files
Increase node count by using bit vector structure.
1 parent 073dc08 commit 525a14f

File tree

3 files changed

+104
-10
lines changed

3 files changed

+104
-10
lines changed

models/starComplexity.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ struct EvalStack
170170
auto numStars=data.pos.size();
171171
auto recipeSize=2*numStars-1;
172172

173-
// suitable up to 10 node networks
174-
constexpr unsigned maxNodes=11, maxStars=2*maxNodes-1;
175-
static_assert(sizeof(linkRep)*8 > (maxNodes*(maxNodes-1))/2);
176173
assert(nodes<=maxNodes);
177174
auto elemStars=&data.elemStars[0];
178175
auto pos=&data.pos[0];
@@ -214,7 +211,7 @@ struct EvalStack
214211
};
215212

216213
// constant representing no graph at all
217-
constexpr linkRep noGraph=~linkRep(0);
214+
const linkRep noGraph=~linkRep(0);
218215

219216
class OutputBuffer
220217
{
@@ -434,7 +431,7 @@ NautyRep toNautyRep(linkRep g, unsigned nodes)
434431
NautyRep n(nodes);
435432
for (unsigned i=0; i<nodes; ++i)
436433
for (unsigned j=0; j<i; ++j)
437-
if (g&(1<<(i*(i-1)/2+j)))
434+
if (g&(linkRep(1)<<(i*(i-1)/2+j)))
438435
n(i,j)=n(j,i)=true;
439436
return n;
440437
}

models/starComplexity.h

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,98 @@
1-
using linkRep=unsigned long long;
1+
// hard code maximum number of nodes
2+
constexpr unsigned maxNodes=22, maxStars=2*maxNodes-1;
3+
4+
//using linkRep=unsigned long long;
5+
6+
#include "netcomplexity.h"
7+
8+
class linkRep
9+
{
10+
public:
11+
using Impl=/*long long*/ unsigned;
12+
private:
13+
constexpr static unsigned size=maxNodes*(maxNodes-1)/(16*sizeof(Impl))+1;
14+
Impl data[linkRep::size];
15+
CLASSDESC_ACCESS(linkRep);
16+
public:
17+
linkRep()=default;
18+
linkRep(unsigned long long x) {
19+
static_assert(sizeof(data)>=sizeof(x));
20+
memcpy(data,&x,sizeof(x));
21+
memset(((char*)data)+sizeof(x),0,sizeof(data)-sizeof(x));
22+
}
23+
const linkRep& operator|=(const linkRep& x) {
24+
for (unsigned i=0; i<size; ++i) data[i]|=x.data[i];
25+
return *this;
26+
}
27+
linkRep operator|(linkRep x) {return x|=*this;}
28+
const linkRep& operator&=(const linkRep& x) {
29+
for (unsigned i=0; i<size; ++i) data[i]&=x.data[i];
30+
return *this;
31+
}
32+
linkRep operator&(linkRep x) {return x&=*this;}
33+
34+
linkRep operator~() const {
35+
linkRep r;
36+
for (unsigned i=0; i<size; ++i) r.data[i]=~data[i];
37+
return r;
38+
}
39+
linkRep operator<<(int n) {
40+
linkRep r;
41+
auto d=div(n, int(8*sizeof(Impl)));
42+
for (unsigned i=0; i<size-d.quot; ++i)
43+
r.data[i+d.quot]=data[i]<<d.rem;
44+
return r;
45+
}
46+
operator const void*() const {
47+
for (unsigned i=0; i<size; ++i)
48+
if (data[i]) return data;
49+
return nullptr;
50+
}
51+
52+
bool operator<(const linkRep& x) const {
53+
for (unsigned i=0; i<size; ++i)
54+
{
55+
if (data[i]<x.data[i]) return true;
56+
if (data[i]>x.data[i]) return false;
57+
}
58+
return false;
59+
}
60+
std::vector<linkRep::Impl> dataAsVector() const {
61+
return std::vector<Impl>(data,data+size);
62+
}
63+
void dataFromVector(const std::vector<linkRep::Impl>& x) {
64+
memcpy(data,x.data(),std::min(size_t(size),x.size())*sizeof(linkRep::Impl));
65+
}
66+
};
67+
68+
// Convert to/from a JSON array for Python conversion
69+
#define CLASSDESC_json_pack___linkRep
70+
#define CLASSDESC_json_unpack___linkRep
71+
72+
#include "json_pack_base.h"
73+
namespace classdesc_access
74+
{
75+
template <> struct access_json_pack<linkRep> {
76+
template <class _CD_ARG_TYPE>
77+
void operator()(classdesc::json_pack_t& targ, const classdesc::string& desc,_CD_ARG_TYPE& arg)
78+
{
79+
std::vector<linkRep::Impl> tmp=arg.dataAsVector();
80+
targ<<tmp;
81+
}
82+
};
83+
84+
template <> struct access_json_unpack<linkRep> {
85+
template <class _CD_ARG_TYPE>
86+
void operator()(classdesc::json_pack_t& targ, const classdesc::string& desc,_CD_ARG_TYPE& arg)
87+
{
88+
std::vector<linkRep::Impl> tmp;
89+
targ>>tmp;
90+
arg.dataFromVector(tmp);
91+
}
92+
};
93+
}
94+
95+
static_assert(sizeof(linkRep)*8 > (maxNodes*(maxNodes-1))/2);
296

397
#include <map>
498
#include <unordered_map>

models/starComplexity.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#print(ecolab.device())
33

44
from starComplexity import starC
5-
nodes=11
5+
nodes=22
66
# computed from max_{l\in[0,L]}min(n+L-l,2l) where L=n(n-1)/2
77
maxStars=0
88
L=int(0.5*nodes*(nodes-1))
@@ -13,9 +13,9 @@
1313
print('maxStars=',maxStars)
1414
maxStars=9
1515

16-
#starC.blockSize(256)
16+
starC.blockSize(256)
1717
#starC.blockSize(4096)
18-
starC.blockSize(17920)
18+
#starC.blockSize(17920)
1919
#starC.blockSize(40320)
2020

2121
starC.generateElementaryStars(nodes)
@@ -25,5 +25,8 @@
2525
print('g','links','*','C','C*','omega(g)','omega(g\')',sep=',')
2626
for i in starC.starMap.keys():
2727
c=starC.complexity(i)
28-
print(i,bin(i).count('1'),starC.symmStar(i),c.complexity(),c.starComplexity(),starC.counts[i],starC.counts[starC.complement(i)],sep=',')
28+
links=0
29+
for j in i:
30+
links+=bin(j).count('1')
31+
print(links,starC.symmStar(i),c.complexity(),c.starComplexity(),starC.counts[i],starC.counts[starC.complement(i)()],sep=',')
2932

0 commit comments

Comments
 (0)