| 1 |
#include "config.h" |
| 2 |
|
| 3 |
#include <sfdpgen/post_process.h> |
| 4 |
#include <sfdpgen/spring_electrical.h> |
| 5 |
#include <sfdpgen/stress_model.h> |
| 6 |
#include <sparse/SparseMatrix.h> |
| 7 |
#include <sparse/general.h> |
| 8 |
#include <stdbool.h> |
| 9 |
|
| 10 |
int stress_model(int dim, SparseMatrix B, double *x, int maxit_sm) { |
| 11 |
SparseMatrix A = B; |
| 12 |
int rc = 0; |
| 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); |
| 17 |
A = SparseMatrix_remove_diagonal(A); |
| 18 |
} else { |
| 19 |
A = SparseMatrix_get_real_adjacency_matrix_symmetrized(A); |
| 20 |
} |
| 21 |
} |
| 22 |
A = SparseMatrix_remove_diagonal(A); |
| 23 |
|
| 24 |
const int m = A->m; |
| 25 |
|
| 26 |
SparseStressMajorizationSmoother sm = SparseStressMajorizationSmoother_new( |
| 27 |
A, dim, x); // weight the long distances |
| 28 |
|
| 29 |
if (!sm) { |
| 30 |
rc = -1; |
| 31 |
goto RETURN; |
| 32 |
} |
| 33 |
|
| 34 |
sm->tol_cg = 0.1; /* we found that there is no need to solve the Laplacian |
| 35 |
accurately */ |
| 36 |
sm->scheme = SM_SCHEME_STRESS; |
| 37 |
SparseStressMajorizationSmoother_smooth(sm, dim, x, maxit_sm); |
| 38 |
for (int i = 0; i < dim * m; i++) { |
| 39 |
x[i] /= sm->scaling; |
| 40 |
} |
| 41 |
SparseStressMajorizationSmoother_delete(sm); |
| 42 |
|
| 43 |
RETURN: |
| 44 |
if (A != B) |
| 45 |
SparseMatrix_delete(A); |
| 46 |
return rc; |
| 47 |
} |