File: safe_coarsen.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (41 lines) | stat: -rw-r--r-- 1,790 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
function [G_coarse, A_coarse, map] = safe_coarsen(G, O, A)
%SAFE_COARSEN coarsen a graph after attempting to sanitize it.
%   safe_coarsen(G) computes a matching of vertices in the graph G
%   and then coarsens the graph by combining all matched vertices into
%   supervertices. With no option struct specified, the coarsening is done 
%   using a combination of heavy-edge matching and other more aggressive
%   techniques to avoid stalling. An optional vertex weight vector A can 
%   also be specified, and a fine-to-coarse mapping of vertices can also
%   be obtained (e.g. map(vertex_fine) = vertex_coarse).
%
%   [G_coarse, A_coarse, map] = safe_coarsen(G) sanitizes and then coarsens a
%   graph represented with sparse adjacency matrix G. G_coarse is the coarsened
%   adjacency matrix, A_coarse is the coarsened array of vertex weights, and
%   map is a mapping of original vertices to coarsened vertices.
%
%   [G_coarse, A_coarse, map] = safe_coarsen(G, O) uses the option struct O to
%   specify coarsening options (e.g. matching strategies).
%
%   [G_coarse, A_coarse, map] = safe_coarsen(G, O, A) uses the array A as
%   vertex weights, such that A(i) is the vertex weight of vertex i. If A is
%   not specified, A is assumed to be an array of all ones (all weights are 1).
%
%   Example:
%       Prob = ssget('DNVS/troll'); G = Prob.A;
%       G_coarse = safe_coarsen(G);
%       spy(G_coarse);
%
%   See also COARSEN, EDGECUT_OPTIONS.

%   Copyright (c) 2018, N. Yeralan, S. Kolodziej, T. Davis, W. Hager
%   SPDX-License-Identifier: GPL-3.0-only

G_safe = sanitize(G);

if (nargin == 1)
    [G_coarse, A_coarse, map] = coarsen(G_safe);
elseif (nargin == 2)
    [G_coarse, A_coarse, map] = coarsen(G_safe, O);
else
    [G_coarse, A_coarse, map] = coarsen(G_safe, O, A);
end