-
Notifications
You must be signed in to change notification settings - Fork 5
/
common.h
154 lines (145 loc) · 3.57 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef COMMONH
#define COMMONH
#define MAX_INT_LEN 20
#define MAX_LINE_LEN 16*1024
#ifdef WIN_X64
#define _CRT_SECURE_NO_DEPRECATE
//#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <time.h>
#else
#include <sys/time.h>
#endif
#include <stddef.h>
typedef char LINE[MAX_LINE_LEN];
typedef long long LONG;
//node serial type
typedef unsigned int NINT;
#define fmt_n "%d"
typedef struct
{
//adjacency list i->j
NINT i;
NINT j;
} Edge;
typedef struct
{
//weighted adjacency list i->j and weight w
NINT i;
NINT j;
double w;
} Edge_w;
typedef struct
{
Edge **edge;
Edge_w **edge_w;
//number of nodes
NINT V;
//nodes start from _s, end at _e - 1
NINT _s;
NINT _e;
//edge num list for each layer
size_t *E;
//weighted flag, 0 for unweighted, otherwise weighted
int weighted;
//directed flag, 0 for undirected, otherwise directed
int directed;
//number of layers
size_t L;
//if network is sorted, index[i] is the position of the last edge oriented from node i;
NINT** index;
} Graph;
typedef struct
{
//number of compartments
size_t M;
//number of layers
size_t L;
//compartments start from _s, end at _s+M -1
size_t _s;
//2D array, (_s+M+1) by (_s+M)
//1. if nodal_trn[i][j], value is invalid if i< _s or j< _s
//2. if (i>= _s && j== _s+M)(meaning the last col for each valid row), nodal_trn[i][j]= sum(nodal_trn[i][_s]...nodal_trn[i][_s+M-1])
double **nodal_trn;
//3D array, L by (_s+M+1) by (_s+M)
//1. if nodal_trn[*][i][j], value is invalid if i< _s or j< _s
//2. if (i>= _s && j== _s+M)(meaning the last col for each valid row), nodal_trn[*][i][j]= sum(nodal_trn[*][i][_s]...nodal_trn[*][i][_s+M-1])
double ***edge_trn;
//1 by L array, inducer for each layer
size_t *inducer_lst;
} Transition;
typedef struct
{
//number of compartments
size_t M;
//compartments start from _s, end at _s+M -1
size_t _s;
//number of nodes
NINT _node_V;
//nodes start from _node_s, end at _node_e - 1
NINT _node_s;
NINT _node_e;
//1 by _node_e list, initial status for each node
size_t *init_lst;
//1 by (_s+M) array
//the population of each compartment
NINT *init_cnt;
//random number seed
int random_seed;
} Status;
typedef struct
{
//arbitrary stop time
double max_time;
//maximum events number
size_t max_events;
//number of rounds
size_t sim_rounds;
//sampling interval number for multiple simulation( histogram like)
size_t interval_num;
char *out_file;
int show_inducer;
} Run;
typedef struct{
//node of the event
NINT ns;
//status change from ni to nj
size_t ni;
size_t nj;
} Event;
typedef struct{
//time t
double t;
//node
NINT n;
} Reaction;
typedef struct{
//reactoin list
Reaction* reaction;
//index fo locate the position of each node
NINT* idx;
//nodes start from _s, end at _e-1
NINT _s;
NINT _e;
//nodes number V
NINT V;
} Heap;
double gettimenow();
extern int _LOGLVL_;
int LOG(int loglvl, const char* file, int line, char* format, ...);
//dump graph
void dump_graph(Graph* graph);
//print graph size info
void print_graph_size(Graph* graph);
int check_int_range( LONG li);
//exponential
LONG exp10( int pow);
//print with kilobit
int kilobit_print( char* prefix, LONG val, char* suffix);
//print time Hour:min:sec
int time_print( char* prefix, double val, char* suffix);
//dump transition matrices
void dump_transition( Transition* tran);
//dump status info
void dump_status( Status* sts);
#endif