Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding script
  • Loading branch information
akr18001 committed Sep 19, 2019
0 parents commit f0a9295
Showing 1 changed file with 141 additions and 0 deletions.
141 changes: 141 additions & 0 deletions time_graph_gen.cc
@@ -0,0 +1,141 @@
/*
Distributed Under the MIT license
Uses a Speculative Dijkstra Algorithm to find shortest path distances
Programs by Masab Ahmad (UConn)
*/

#include <cstdio>
#include <cstdlib>
#include <pthread.h>
#include <queue>
//#include "carbon_user.h" /*For the Graphite Simulator*/
#include <time.h>
#include <sys/timeb.h>
//#include "../../common/barrier.h"
//#include "barrier.h"
#include <string.h>
#include <set>
#include <map>
#include <iterator>


#define MAX 100000000
#define INT_MAX 100000000
#define BILLION 1E9

using namespace std;

//Thread Argument Structure
typedef struct
{
int tid;
int P;
int T;
int N;
pthread_barrier_t* barrier;
} thread_arg_t;

//Edge Task Struct
struct task {
int node;
int dist;
bool operator<(const task& rhs) const
{
return dist > rhs.dist;
}
};


int **edges;
int largest = 0;
double largest_d;
int *D;
int *D_temp;
thread_arg_t thread_arg[1024];
pthread_t thread_handle[1024];
std::priority_queue<task> pq;

int iter = 0;

typedef struct neighbor_node{
int neighbor;
int *weights;
int *time_instants;
int temporal_deg;
}neighbor_node;

typedef struct graph_node_s {
int deg;
neighbor_node *neighbors;
} graph_node_t;

graph_node_t *nodes;

typedef struct node_s{
int neighbor;
int weight;
}node_t;

typedef struct edge_t{
int weight;
int time;
}edge_t;


int main(int argc, char** argv)
{
char *filename = argv[1];
int temporal_edges = atoi(argv[2]);
int max_time = atoi(argv[3]);
int min_time = atoi(argv[4]);
char *outfile = argv[5];
int number0,number1,weig;

int step_size = (int)max_time/temporal_edges;

FILE *file0;
int f0;

multimap<int, node_t> time_instants_map;

file0 = fopen(filename,"r");
if (!file0) {
printf ("Error: Unable to open input file '%s'\n",filename);
return 1;
}
int N, E;
char p;
char sp[2];
f0 = fscanf(file0, "%c %s %d %d\n", &p, sp, &N, &E);
char a;
while(1){
f0 = fscanf(file0, "%c %d %d %d\n", &a, &number0,&number1, &weig);
if(f0 == EOF)
break;
node_t curr_edge;
curr_edge.neighbor = number1;
curr_edge.weight = weig;
time_instants_map.insert({ number0, curr_edge });
}
fclose(file0);

printf("File Read\n");
file0 = fopen(outfile,"w");
if (!file0) {
printf ("Error: Unable to open input file '%s'\n",outfile);
return 1;
}

for(auto it=time_instants_map.begin(); it!=time_instants_map.end(); it++)
{
for(int t=min_time; t<=max_time; t+=step_size)
{
node_t curr_edge = it->second;
fprintf(file0,"%d %d %d %d\n",it->first, curr_edge.neighbor, curr_edge.weight, t);
}

}
fclose(file0);

}

0 comments on commit f0a9295

Please sign in to comment.