Skip to content

Commit

Permalink
Revising for paper deadline
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Jenkins committed Jan 6, 2021
1 parent 69c5328 commit 4d41c47
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int main(int argc, char *argv[])
{
GlobalTestConfig gtc;
const size_t numVertices = 1024;
const size_t meanEdgesPerVertex = 32;
const size_t meanEdgesPerVertex = 20;
const size_t vertexLoad = 50;

/* queues */
Expand Down
37 changes: 26 additions & 11 deletions src/rideables/TGraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class TGraph : public RGraph{

// Allocates data structures and pre-loads the graph
TGraph(GlobalTestConfig* gtc) {
idxToVertex = new Vertex*[numVertices];
vertexLocks = new std::atomic<bool>[numVertices];
vertexSeqs = new uint32_t[numVertices];
this->idxToVertex = new Vertex*[numVertices];
this->vertexLocks = new std::atomic<bool>[numVertices];
this->vertexSeqs = new uint32_t[numVertices];
std::mt19937_64 gen(0xDEADBEEF);
std::uniform_int_distribution<> verticesRNG(0, numVertices - 1);
std::uniform_int_distribution<> coinflipRNG(0, 100);
Expand All @@ -108,14 +108,14 @@ class TGraph : public RGraph{
idxToVertex[i] = nullptr;
}
vertexLocks[i] = false;
vertexSeqs = 0;
vertexSeqs[i] = 0;
}

std::cout << "Filled vertexLoad" << std::endl;

// Fill to mean edges per vertex
for (int i = 0; i < numVertices; i++) {
for (int i = 0; i < meanEdgesPerVertex; i++) {
for (int i = 0; i < meanEdgesPerVertex * 100 / vertexLoad; i++) {
if (idxToVertex[i] == nullptr) continue;
int j = verticesRNG(gen);
while (j == i) {
Expand Down Expand Up @@ -185,6 +185,13 @@ class TGraph : public RGraph{
lock(dest);
}

if (idxToVertex[src] == nullptr) {
idxToVertex[src] = new Vertex(src, src);
}
if (idxToVertex[dest] == nullptr) {
idxToVertex[dest] = new Vertex(dest, dest);
}

Relation r(src,dest,weight);
auto& srcSet = source(src);
auto& destSet = destination(dest);
Expand Down Expand Up @@ -220,6 +227,10 @@ class TGraph : public RGraph{

// We utilize `get_unsafe` API because the Relation destination and vertex id will not change at all.
lock(src);
if (idxToVertex[src] == nullptr) {
unlock(src);
return false;
}
Relation r(src, dest, -1);
retval = has_relation(source(src), &r);
unlock(src);
Expand All @@ -243,7 +254,7 @@ class TGraph : public RGraph{
lock(dest);
}

{
if (idxToVertex[src] != nullptr && idxToVertex[dest] != nullptr) {
Relation r(src, dest, -1);
remove_relation(source(src), &r);
remove_relation(destination(dest), &r);
Expand All @@ -266,13 +277,13 @@ class TGraph : public RGraph{
int src = -1;
int dest = -1;

if (idxToVertex[src] != nullptr) {
if (idxToVertex[vid] != nullptr) {
// Check source first
auto search = source(src).begin();
if (search == source(src).end()) {
auto search = source(vid).begin();
if (search == source(vid).end()) {
// Then destination
search = destination(src).begin();
if (search == destination(src).end()) {
search = destination(vid).begin();
if (search == destination(vid).end()) {
goto failure;
}
}
Expand All @@ -297,6 +308,10 @@ class TGraph : public RGraph{
// Step 1: Acquire vertex and collect neighbors...
std::vector<int> vertices;
lock(vid);
if (idxToVertex[vid] == nullptr) {
unlock(vid);
return false;
}
uint32_t seq = get_seq(vid);
for (auto r : source(vid)) {
vertices.push_back(r->dest);
Expand Down
12 changes: 9 additions & 3 deletions src/tests/GraphTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ class GraphTest : public Test {
// 2) clearProb = min(0, max(1, delta / 33%))
// 3) lookupProb = 100% - insertProb - removalProb - clearProb
void update_ratio(double averageDegree) {
double ratio = min(2.0, max(desiredAvgDegree / averageDegree - 1, averageDegree / desiredAvgDegree - 1));
int delta = 1650 * ratio; // 16.5% is half of 33%
int sign = averageDegree > desiredAvgDegree ? -1 : averageDegree < desiredAvgDegree ? 1 : 0;
double ratio = min(2.0, max((double) desiredAvgDegree / averageDegree - 1, averageDegree / (double) desiredAvgDegree - 1));
int delta = 1650 * ratio * sign; // 16.5% is half of 33%
insertionProb = 3300 + delta;
removalProb = 3300 - delta;
clearProb = min(0.0, max(1.0, delta / 3300.0));
clearProb = min(0.0, max(1.0, (double) delta / 3300.0)) * 100;
lookupProb = 10000 - insertionProb - removalProb - clearProb;
std::cout << "sign(" << sign << "), ratio(" << ratio << "), delta(" << delta << ")" << std::endl;
std::cout << "(" << insertionProb / 100.0 << "," << removalProb / 100.0 << "," << lookupProb / 100.0 << "," << clearProb / 100.0 << ")" << std::endl;
}

Expand Down Expand Up @@ -116,12 +118,16 @@ class GraphTest : public Test {
}
int rng = dist(gen_p);
if (rng <= insertionProb) {
// std::cout << "rng(" << rng << ") is add_edge <= " << insertionProb << std::endl;
g->add_edge(distv(gen_v), distv(gen_v), -1);
} else if (rng <= insertionProb + removalProb) {
// std::cout << "rng(" << rng << ") is remove_any_edge <= " << insertionProb + removalProb << std::endl;
g->remove_any_edge(distv(gen_v));
} else if (rng <= insertionProb + removalProb + lookupProb) {
// std::cout << "rng(" << rng << ") is has_edge <= " << insertionProb + removalProb + lookupProb << std::endl;
g->has_edge(distv(gen_v), distv(gen_v));
} else {
// std::cout << "rng(" << rng << ") is remove_vertex...";
g->remove_vertex(distv(gen_v));
}
}
Expand Down

0 comments on commit 4d41c47

Please sign in to comment.