Statistics
| Branch: | Tag: | Revision:

sssimulator / wuli.c @ 743e659d

 1 ```#include"wuli.h" ``` ```#include ``` ```#define x(n, i, j) (i+j*n + 1) ``` ```#define b(i, t, s_id) ((i == s_id) ? 1 : (i == t) ? -1 : 0) ``` ```int f(matsize n, matsize i, matsize j, int t, int source_id) ``` ```{ ``` ``` if(t < source_id) ``` ``` return (n*n + i + j*n + t*n*n + 1); ``` ``` if(t > source_id) ``` ``` return (n*n + i + j*n + (t-1)*n*n + 1); ``` ``` return -1; ``` ```} ``` ```REAL node_output(const struct matrix * A, matsize i) ``` ```{ ``` ``` matsize n; ``` ``` REAL res; ``` ``` struct matrix *u, *product; ``` ``` n = matrix_num_rows(A); // number of nodes ``` ``` u = matrix_zeros(1, n); ``` ``` matrix_element_set(u, 0, i, 1); ``` ``` product = matrix_multiply(u, A); ``` ``` res = matrix_sum_values(product); ``` ``` matrix_destroy(&u); ``` ``` matrix_destroy(&product); ``` ``` return res; ``` ```} ``` ```void overlay_matrix_wuli(struct matrix ** A, struct matrix ** x, int source_id) ``` ```{ ``` ``` lprec *lp; ``` ``` matsize n, N, i, j; ``` ``` int *var_index, k, t; ``` ``` REAL *coeff, *sol, sum; ``` ``` if(!A || !x) ``` ``` return; ``` ``` n = matrix_num_rows(*A); // number of nodes ``` ``` N = n*n + n*n*(n-1); // number of variables ``` ``` coeff = malloc(sizeof(REAL) * (N+1) ); ``` ``` var_index = malloc(sizeof(int) * (N+1) ); ``` ``` for(i=1; i < (n*n)+1; i++) ``` ``` coeff[i] = 1; ``` ``` for(i=n*n+1; i < N+1; i++) ``` ``` coeff[i] = 0; ``` ``` lp = make_lp(0, N); ``` ``` set_obj_fn(lp, coeff); ``` ``` k=0; ``` ``` for(i=0; i