File: stress_model.c

package info (click to toggle)
graphviz 14.0.5-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 139,388 kB
  • sloc: ansic: 141,938; cpp: 11,957; python: 7,766; makefile: 4,043; yacc: 3,030; xml: 2,972; tcl: 2,495; sh: 1,388; objc: 1,159; java: 560; lex: 423; perl: 243; awk: 156; pascal: 139; php: 58; ruby: 49; cs: 31; sed: 1
file content (45 lines) | stat: -rw-r--r-- 1,217 bytes parent folder | download | duplicates (2)
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
#include <sfdpgen/post_process.h>
#include <sfdpgen/spring_electrical.h>
#include <sfdpgen/stress_model.h>
#include <sparse/SparseMatrix.h>
#include <sparse/general.h>
#include <stdbool.h>

int stress_model(int dim, SparseMatrix B, double *x, int maxit_sm) {
  SparseMatrix A = B;
  int rc = 0;

  if (!SparseMatrix_is_symmetric(A, false) || A->type != MATRIX_TYPE_REAL) {
    if (A->type == MATRIX_TYPE_REAL) {
      A = SparseMatrix_symmetrize(A, false);
      A = SparseMatrix_remove_diagonal(A);
    } else {
      A = SparseMatrix_get_real_adjacency_matrix_symmetrized(A);
    }
  }
  A = SparseMatrix_remove_diagonal(A);

  const int m = A->m;

  SparseStressMajorizationSmoother sm = SparseStressMajorizationSmoother_new(
      A, dim, x); // weight the long distances

  if (!sm) {
    rc = -1;
    goto RETURN;
  }

  sm->tol_cg = 0.1; /* we found that there is no need to solve the Laplacian
                       accurately */
  sm->scheme = SM_SCHEME_STRESS;
  SparseStressMajorizationSmoother_smooth(sm, dim, x, maxit_sm);
  for (int i = 0; i < dim * m; i++) {
    x[i] /= sm->scaling;
  }
  SparseStressMajorizationSmoother_delete(sm);

RETURN:
  if (A != B)
    SparseMatrix_delete(A);
  return rc;
}