Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
update
  • Loading branch information
akr18001 committed Dec 30, 2019
1 parent 870fdfa commit 7e70ef0
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 5 deletions.
15 changes: 15 additions & 0 deletions C Code/README.md
@@ -0,0 +1,15 @@



# Compile #

```g++ time_graph_gen.cc -o time_graph_gen -O3```


# Usage #


```./time_graph_gen <Path to graph in DIMACS 9th gr format> <Temporal Degree> <Max Time> <Path to Output file>```

```./time_graph_gen ~/hetro_map_graphs/USA-road-t.CAL.gr 10 1895126 CAL_t.gr```

File renamed without changes.
15 changes: 10 additions & 5 deletions README.md
@@ -1,15 +1,20 @@



# Compile #
# Run Python Script #

```g++ time_graph_gen.cc -o time_graph_gen -O3```
```python gen_time_graph.py```


# Usage #
# Configurations #

time_helper.py contains the configurations


```
static_graph => Path to static graph file in gr format (9th DIMACS)
```

```./time_graph_gen <Path to graph in DIMACS 9th gr format> <Temporal Degree> <Max Time> <Path to Output file>```

```./time_graph_gen ~/hetro_map_graphs/USA-road-t.CAL.gr 10 1895126 CAL_t.gr```

40 changes: 40 additions & 0 deletions gen_time_graph.py
@@ -0,0 +1,40 @@

import os
import sys
from time_helper import *

from random import seed
from random import randint

static_graph_file = open(static_graph,"r")
lines = static_graph_file.read().split("\n")
static_graph_file.close()

seed(1)

temporal_list = []
for line in lines:
if "p" in line:
nodes = line.split(" ")[2]
continue
parts = line.split(" ")
if len(parts) != 4:
break
node = parts[1]
weight = parts[3]
for t in range(0,temporal_edges,time_step):
weight = int(weight) * sample_from_distribution(int(node),int(t))
temporal_edge = parts[0] + " " + parts[1] + " " + parts[2] + " " + str(int(round(weight))) + " " + str(t)
if randint(0, 100) > p:
temporal_list = temporal_list + [temporal_edge]

temporal_graph_file = open(temporal_graph,"w")
temporal_graph_file.write("p sp " + nodes + " " + str(len(temporal_list)) + "\n")
for line in temporal_list:
temporal_graph_file.write(line + "\n")
temporal_graph_file.close()





10 changes: 10 additions & 0 deletions sample.gr
@@ -0,0 +1,10 @@
p sp 8 9
a 1 2 21
a 1 3073 26
a 1 4097 10
a 1 8192 13
a 2 1 39
a 2 2 910
a 2 3072 26
a 2 4097 10
a 2 6144 13
83 changes: 83 additions & 0 deletions sample_t.gr
@@ -0,0 +1,83 @@
p sp 8 82
a 1 2 162 0
a 1 2 1497 1
a 1 2 892 2
a 1 2 5876 3
a 1 2 43138 4
a 1 2 154547 5
a 1 2 1171732 6
a 1 2 23648537 7
a 1 2 307075565 8
a 1 3073 89 0
a 1 3073 662 1
a 1 3073 7430 2
a 1 3073 121753 4
a 1 3073 1496565 5
a 1 3073 4139387 6
a 1 3073 11463125 7
a 1 3073 2602998 8
a 1 4097 505 1
a 1 4097 4711 2
a 1 4097 72184 3
a 1 4097 541471 4
a 1 4097 320208 5
a 1 4097 29736323 7
a 1 4097 240612285 8
a 1 4097 1052248616 9
a 1 8192 137 0
a 1 8192 51 1
a 1 8192 758 2
a 1 8192 6903 3
a 1 8192 45893 4
a 1 8192 609626 6
a 1 8192 2677545 7
a 1 8192 22403455 8
a 1 8192 281286605 9
a 2 1 185 0
a 2 1 567 1
a 2 1 4741 2
a 2 1 24216 3
a 2 1 176012 4
a 2 1 838908 5
a 2 1 2889797 6
a 2 1 3945506 7
a 2 1 25173425 8
a 2 1 121471931 9
a 2 2 3994 0
a 2 2 36173 1
a 2 2 186216 2
a 2 2 3740018 3
a 2 2 9640936 4
a 2 2 64214242 5
a 2 2 4732455298 7
a 2 2 11445694958 8
a 2 2 80345625851 9
a 2 3072 210 0
a 2 3072 3242 1
a 2 3072 20929 2
a 2 3072 201289 3
a 2 3072 896423 4
a 2 3072 1851134 5
a 2 3072 1087289 6
a 2 3072 8826612 7
a 2 3072 44491087 8
a 2 3072 613050415 9
a 2 4097 122 0
a 2 4097 2493 2
a 2 4097 27564 3
a 2 4097 699216 4
a 2 4097 9112680 5
a 2 4097 27046751 6
a 2 4097 28459546 7
a 2 4097 94628187 8
a 2 4097 1320857947 9
a 2 6144 148 0
a 2 6144 1192 1
a 2 6144 10495 2
a 2 6144 39838 3
a 2 6144 402759 4
a 2 6144 5484850 5
a 2 6144 62552079 6
a 2 6144 693220773 7
a 2 6144 7609802827 8
a 2 6144 31675967567 9
46 changes: 46 additions & 0 deletions time_helper.py
@@ -0,0 +1,46 @@

import numpy as np

static_graph = "sample.gr"
temporal_graph = "sample_t.gr"
time_step = 1
temporal_edges = 10
spatial_partition = 2
temporal_partition = 2
p = 3

def prob_distribution_1():
mu, sigma = 0, 10
return np.random.normal(mu, sigma)


def prob_distribution_2():
mu, sigma = 0, 8
return np.random.normal(mu, sigma)

def prob_distribution_3():
mu, sigma = 0, 9
return np.random.normal(mu, sigma)


def prob_distribution_4():
mu, sigma = 0, 8
return np.random.normal(mu, sigma)


prob_distributions = [prob_distribution_1, prob_distribution_2, prob_distribution_3, prob_distribution_4]

def get_node_set(node):
return node % spatial_partition

def get_time_set(time_instant):
return time_instant % temporal_partition

def custom_distribution(node, time_instant):
s = get_node_set(node)
t = get_time_set(time_instant)
index = s*spatial_partition + t
return np.abs(prob_distributions[index]())

sample_from_distribution = custom_distribution
#print(sample_from_distribution(1,1))

0 comments on commit 7e70ef0

Please sign in to comment.