Skip to content

Commit aa22378

Browse files
First cut at starUpperBound algorithm.
1 parent a0821b1 commit aa22378

File tree

5 files changed

+89
-13
lines changed

5 files changed

+89
-13
lines changed

include/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ ifdef AEGIS
127127
# for now, we maintain the code for C++98 standard
128128
# noexcept-type is a warning about ABI changes coming in C++17
129129
# Travis complains about unused-local-typedefs, so shut it up.
130-
CXXFLAGS+=-Wno-noexcept-type -Wno-unused-local-typedefs -std=c++20
130+
CXXFLAGS+=-Wno-noexcept-type -Wno-unused-local-typedefs
131131
endif
132+
CXXFLAGS+=-std=c++20
132133

133134
ifndef MXE
134135
# needed for generating .so files

models/starComplexity.cc

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "starComplexity.h"
2+
#ifdef SYCL_LANGUAGE_VERSION
23
#include "vecBitSet.cd"
4+
#endif
35
#include "starComplexity.cd"
46
#include "netcomplexity.h"
57
#include "pythonBuffer.h"
@@ -33,6 +35,8 @@ linkRep edge(unsigned i, unsigned j)
3335
return linkRep(1)<<(i*(i-1)/2+j);
3436
}
3537

38+
39+
3640
void StarComplexityGen::generateElementaryStars(unsigned nodes)
3741
{
3842
for (unsigned i=0; i<nodes; ++i)
@@ -431,7 +435,7 @@ NautyRep toNautyRep(linkRep g, unsigned nodes)
431435
NautyRep n(nodes);
432436
for (unsigned i=0; i<nodes; ++i)
433437
for (unsigned j=0; j<i; ++j)
434-
if (g&(linkRep(1)<<(i*(i-1)/2+j)))
438+
if (!(g&(linkRep(1)<<(i*(i-1)/2+j))).empty())
435439
n(i,j)=n(j,i)=true;
436440
return n;
437441
}
@@ -545,3 +549,59 @@ GraphComplexity StarComplexityGen::complexity(linkRep g) const
545549
}
546550
return r;
547551
}
552+
553+
554+
unsigned starUpperBound(linkRep x, unsigned nodes)
555+
{
556+
// Firstly remove those nodes that are full stars
557+
vector<unsigned> fullStars;
558+
for (unsigned i=0; i<nodes; ++i)
559+
{
560+
bool fullStar=true;
561+
for (unsigned j=0; fullStar && j<nodes; ++j)
562+
if (i!=j && !x(i,j))
563+
fullStar=false;
564+
if (fullStar) fullStars.push_back(i);
565+
}
566+
567+
unsigned stars=fullStars.size();
568+
for (auto i: fullStars)
569+
for (unsigned j=0; j<nodes; ++j)
570+
x&=~edge(i,j); // remove all edges to this node
571+
572+
573+
// calculate node degree
574+
map<unsigned,unsigned> nodeDegree;
575+
for (unsigned i=0; i<maxNodes; ++i)
576+
for (unsigned j=0; j<i; ++j)
577+
if (x(i,j))
578+
{
579+
++nodeDegree[i];
580+
++nodeDegree[j];
581+
}
582+
583+
584+
struct SecondLess
585+
{
586+
bool operator()(const pair<unsigned,unsigned>& x, const pair<unsigned,unsigned>& y)
587+
const {return x.second < y.second;}
588+
};
589+
590+
// compute the number of operations xᵢ∪(xₖ∩xₗ…)
591+
auto maxDegree=max_element(nodeDegree.begin(), nodeDegree.end(), SecondLess());
592+
593+
while (maxDegree->second>0)
594+
{
595+
stars+=1+maxDegree->second;
596+
maxDegree->second=0; // accounted for all links to this node
597+
for (unsigned j=0; j<maxNodes; ++j)
598+
if (x(maxDegree->first, j) && nodeDegree[j])
599+
--nodeDegree[j];
600+
maxDegree=max_element(nodeDegree.begin(), nodeDegree.end(), SecondLess());
601+
}
602+
603+
return stars;
604+
}
605+
606+
unsigned StarComplexityGen::starUpperBound(const linkRep& x) const
607+
{return min(::starUpperBound(x, elemStars.size()), ::starUpperBound(~x,elemStars.size()));}

models/starComplexity.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// hard code maximum number of nodes
2-
constexpr unsigned maxNodes=22, maxStars=2*maxNodes-1;
2+
constexpr unsigned maxNodes=8, maxStars=2*maxNodes-1;
33

44
//using linkRep=unsigned long long;
55

@@ -19,7 +19,7 @@ class linkRepImpl
1919
CLASSDESC_ACCESS(linkRepImpl);
2020
public:
2121
linkRepImpl()=default;
22-
linkRepImpl(unsigned long long x) {
22+
linkRepImpl(unsigned x) {
2323
static_assert(sizeof(data)>=sizeof(x));
2424
memcpy(data,&x,sizeof(x));
2525
memset(((char*)data)+sizeof(x),0,sizeof(data)-sizeof(x));
@@ -47,12 +47,22 @@ class linkRepImpl
4747
r.data[i+d.quot]=data[i]<<d.rem;
4848
return r;
4949
}
50-
operator const void*() const {
50+
// return true if there is a link between nodes i and j
51+
bool operator()(unsigned i,unsigned j) const {
52+
if (i<j) std::swap(i,j);
53+
auto d=div(i*(i-1)/2+j, int(8*sizeof(Impl)));
54+
return (data[d.quot] & (Impl(1)<<d.rem))!=0;
55+
}
56+
bool empty() const {
5157
for (unsigned i=0; i<size; ++i)
52-
if (data[i]) return data;
53-
return nullptr;
58+
if (data[i]) return false;
59+
return true;
60+
}
61+
bool operator==(const linkRepImpl& x) const {
62+
for (unsigned i=0; i<size; ++i)
63+
if (data[i]!=x.data[i]) return false;
64+
return true;
5465
}
55-
5666
auto operator<=>(const linkRepImpl& x) const {
5767
for (unsigned i=0; i<size; ++i)
5868
if (auto r=data[i]<=>x.data[i]; r!=0)
@@ -134,5 +144,8 @@ struct StarComplexityGen
134144
linkRep complement(linkRep) const;
135145
unsigned symmStar(linkRep) const;
136146
GraphComplexity complexity(linkRep) const;
147+
148+
/// return an upper bound on the number of stars in the link representation
149+
unsigned starUpperBound(const linkRep&) const;
137150
};
138151

models/starComplexity.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from starComplexity import starC
55
from datetime import datetime
6-
nodes=22
6+
nodes=7
77
# computed from max_{l\in[0,L]}min(n+L-l,2l) where L=n(n-1)/2
88
maxStars=0
99
L=int(0.5*nodes*(nodes-1))
@@ -12,7 +12,7 @@
1212
maxStars=max(maxStars,v)
1313

1414
print('maxStars=',maxStars)
15-
maxStars=12
15+
maxStars=6
1616

1717
#starC.blockSize(256)
1818
starC.blockSize(4096)
@@ -21,7 +21,7 @@
2121
#starC.blockSize(40320)
2222

2323
starC.generateElementaryStars(nodes)
24-
for numStars in range(2,maxStars+1):
24+
for numStars in range(1,maxStars+1):
2525
starC.fillStarMap(numStars)
2626
print('completed',numStars,datetime.now())
2727
starC.canonicaliseStarMap()
@@ -33,5 +33,7 @@
3333
links=0
3434
for j in i:
3535
links+=bin(j).count('1')
36-
print(id,links,starC.symmStar(i)-1,c.complexity(),c.starComplexity(),starC.counts[i],starC.counts[starC.complement(i)()],sep=',',file=out)
36+
37+
#print(id,links,starC.symmStar(i)-1,c.complexity(),c.starComplexity(),starC.counts[i],sep=',',file=out)
38+
print(id,bin(i[0]),starC.starMap[i],starC.starUpperBound(i));
3739
id+=1

0 commit comments

Comments
 (0)