Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
stress_model.c
Go to the documentation of this file.
1#include <sparse/general.h>
6#include <stdbool.h>
7#include <util/alloc.h>
8
9void stress_model(int dim, SparseMatrix B, double **x, int maxit_sm, int *flag) {
10 int m;
11 int i;
13
14 if (!SparseMatrix_is_symmetric(A, false) || A->type != MATRIX_TYPE_REAL){
15 if (A->type == MATRIX_TYPE_REAL){
16 A = SparseMatrix_symmetrize(A, false);
18 } else {
20 }
21 }
23
24 *flag = 0;
25 m = A->m;
26 if (!x) {
27 *x = gv_calloc(m * dim, sizeof(double));
28 srand(123);
29 for (i = 0; i < dim*m; i++) (*x)[i] = drand();
30 }
31
33 SparseStressMajorizationSmoother_new(A, dim, *x);/* weight the long distances */
34
35 if (!sm) {
36 *flag = -1;
37 goto RETURN;
38 }
39
40
41 sm->tol_cg = 0.1; /* we found that there is no need to solve the Laplacian accurately */
44 for (i = 0; i < dim*m; i++) {
45 (*x)[i] /= sm->scaling;
46 }
48
49 RETURN:
50 if (A != B) SparseMatrix_delete(A);
51}
SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, bool pattern_symmetric_only)
bool SparseMatrix_is_symmetric(SparseMatrix A, bool test_pattern_symmetry_only)
void SparseMatrix_delete(SparseMatrix A)
SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A)
SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A)
@ MATRIX_TYPE_REAL
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
#define A(n, t)
Definition expr.h:76
static double drand(void)
#define B
Definition hierarchy.c:117
static const int dim
StressMajorizationSmoother SparseStressMajorizationSmoother_new(SparseMatrix A, int dim, double *x)
void SparseStressMajorizationSmoother_delete(SparseStressMajorizationSmoother sm)
double SparseStressMajorizationSmoother_smooth(SparseStressMajorizationSmoother sm, int dim, double *x, int maxit_sm)
@ SM_SCHEME_STRESS
void stress_model(int dim, SparseMatrix B, double **x, int maxit_sm, int *flag)
Definition stress_model.c:9
#define RETURN(v)
Definition strmatch.c:144