Skip to content
Permalink
d73c71309b
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
141 lines (116 sloc) 2.67 KB
/*
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 = 0; //atoi(argv[4]);
char *outfile = argv[4];
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);
}