Squashing warnings.
[AMDJ.git] / src / test / java / edu / ufl / cise / amd / tdouble / test / Damd_demo.java
blob2857baa6cabe52ea3f56c123b48a2b5e0dcaf274
1 /**
2 * AMD, Copyright (C) 2009-2011 by Timothy A. Davis, Patrick R. Amestoy,
3 * and Iain S. Duff. All Rights Reserved.
4 * Copyright (C) 2011 Richard Lincoln
6 * AMD is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * AMD is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with AMD; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21 package edu.ufl.cise.amd.tdouble.test;
23 import edu.ufl.cise.amd.tdouble.Damd_internal;
24 import junit.framework.TestCase;
26 import static edu.ufl.cise.amd.tdouble.Damd.AMD_CONTROL;
27 import static edu.ufl.cise.amd.tdouble.Damd.AMD_INFO;
28 import static edu.ufl.cise.amd.tdouble.Damd.AMD_VERSION;
29 import static edu.ufl.cise.amd.tdouble.Damd.AMD_MAIN_VERSION;
30 import static edu.ufl.cise.amd.tdouble.Damd.AMD_SUB_VERSION;
31 import static edu.ufl.cise.amd.tdouble.Damd.AMD_DATE;
32 import static edu.ufl.cise.amd.tdouble.Damd.AMD_OK;
33 import static edu.ufl.cise.amd.tdouble.Damd.AMD_VERSION_CODE;
35 import static edu.ufl.cise.amd.tdouble.Damd_defaults.amd_defaults;
36 import static edu.ufl.cise.amd.tdouble.Damd_control.amd_control;
37 import static edu.ufl.cise.amd.tdouble.Damd_order.amd_order;
38 import static edu.ufl.cise.amd.tdouble.Damd_info.amd_info;
40 /**
41 * A simple C main program that illustrates the use of the interface
42 * to AMD.
44 public class Damd_demo extends TestCase {
47 /* The symmetric can_24 Harwell/Boeing matrix, including upper and lower
48 * triangular parts, and the diagonal entries. Note that this matrix is
49 * 0-based, with row and column indices in the range 0 to n-1. */
50 int n = 24, nz;
51 int[] Ap = new int [] { 0, 9, 15, 21, 27, 33, 39, 48, 57, 61, 70, 76, 82, 88, 94, 100,
52 106, 110, 119, 128, 137, 143, 152, 156, 160 };
53 int[] Ai = new int [] {
54 /* column 0: */ 0, 5, 6, 12, 13, 17, 18, 19, 21,
55 /* column 1: */ 1, 8, 9, 13, 14, 17,
56 /* column 2: */ 2, 6, 11, 20, 21, 22,
57 /* column 3: */ 3, 7, 10, 15, 18, 19,
58 /* column 4: */ 4, 7, 9, 14, 15, 16,
59 /* column 5: */ 0, 5, 6, 12, 13, 17,
60 /* column 6: */ 0, 2, 5, 6, 11, 12, 19, 21, 23,
61 /* column 7: */ 3, 4, 7, 9, 14, 15, 16, 17, 18,
62 /* column 8: */ 1, 8, 9, 14,
63 /* column 9: */ 1, 4, 7, 8, 9, 13, 14, 17, 18,
64 /* column 10: */ 3, 10, 18, 19, 20, 21,
65 /* column 11: */ 2, 6, 11, 12, 21, 23,
66 /* column 12: */ 0, 5, 6, 11, 12, 23,
67 /* column 13: */ 0, 1, 5, 9, 13, 17,
68 /* column 14: */ 1, 4, 7, 8, 9, 14,
69 /* column 15: */ 3, 4, 7, 15, 16, 18,
70 /* column 16: */ 4, 7, 15, 16,
71 /* column 17: */ 0, 1, 5, 7, 9, 13, 17, 18, 19,
72 /* column 18: */ 0, 3, 7, 9, 10, 15, 17, 18, 19,
73 /* column 19: */ 0, 3, 6, 10, 17, 18, 19, 20, 21,
74 /* column 20: */ 2, 10, 19, 20, 21, 22,
75 /* column 21: */ 0, 2, 6, 10, 11, 19, 20, 21, 22,
76 /* column 22: */ 2, 20, 21, 22,
77 /* column 23: */ 6, 11, 12, 23 } ;
80 public void test_amd_demo() {
82 int[] P = new int [24] ;
83 int[] Pinv = new int [24] ;
84 int i, j, k, jnew, p, inew, result ;
85 double[] Control = new double [AMD_CONTROL] ;
86 double[] Info = new double [AMD_INFO] ;
87 char[][] A = new char[24][24] ;
89 Damd_internal.NPRINT = false;
90 //Damd_internal.NDEBUG = false;
91 //Damd.AMD_debug = 1;
93 /* here is an example of how to use AMD_VERSION. This code will work in
94 * any version of AMD. */
95 if (AMD_VERSION != 0 && AMD_VERSION >= AMD_VERSION_CODE(1,2))
97 System.out.printf ("AMD version %d.%d, date: %s\n", AMD_MAIN_VERSION,
98 AMD_SUB_VERSION, AMD_DATE) ;
99 } else {
100 System.out.printf ("AMD version: 1.1 or earlier\n") ;
103 System.out.printf ("AMD demo, with the 24-by-24 Harwell/Boeing matrix, can_24:\n") ;
105 /* get the default parameters, and print them */
106 amd_defaults (Control) ;
107 amd_control (Control) ;
109 /* print the input matrix */
110 nz = Ap [n] ;
111 System.out.printf ("\nInput matrix: %d-by-%d, with %d entries.\n" +
112 " Note that for a symmetric matrix such as this one, only the\n" +
113 " strictly lower or upper triangular parts would need to be\n" +
114 " passed to AMD, since AMD computes the ordering of A+A'. The\n" +
115 " diagonal entries are also not needed, since AMD ignores them.\n",
116 n, n, nz) ;
117 for (j = 0 ; j < n ; j++)
119 System.out.printf ("\nColumn: %d, number of entries: %d, with row indices in" +
120 " Ai [%d ... %d]:\n row indices:",
121 j, Ap [j+1] - Ap [j], Ap [j], Ap [j+1]-1) ;
122 for (p = Ap [j] ; p < Ap [j+1] ; p++)
124 i = Ai [p] ;
125 System.out.printf (" %d", i) ;
127 System.out.printf ("\n") ;
130 /* print a character plot of the input matrix. This is only reasonable
131 * because the matrix is small. */
132 System.out.printf ("\nPlot of input matrix pattern:\n") ;
133 for (j = 0 ; j < n ; j++)
135 for (i = 0 ; i < n ; i++) A [i][j] = '.' ;
136 for (p = Ap [j] ; p < Ap [j+1] ; p++)
138 i = Ai [p] ;
139 A [i][j] = 'X' ;
142 System.out.printf (" ") ;
143 for (j = 0 ; j < n ; j++) System.out.printf (" %1d", j % 10) ;
144 System.out.printf ("\n") ;
145 for (i = 0 ; i < n ; i++)
147 System.out.printf ("%2d: ", i) ;
148 for (j = 0 ; j < n ; j++)
150 System.out.printf (" %c", A [i][j]) ;
152 System.out.printf ("\n") ;
155 /* order the matrix */
156 result = amd_order (n, Ap, Ai, P, Control, Info) ;
157 System.out.printf ("return value from amd_order: %d (should be %d)\n",
158 result, AMD_OK) ;
160 /* print the statistics */
161 amd_info (Info) ;
163 if (result != AMD_OK)
165 System.out.printf ("AMD failed\n") ;
166 fail() ;
169 /* print the permutation vector, P, and compute the inverse permutation */
170 System.out.printf ("Permutation vector:\n") ;
171 for (k = 0 ; k < n ; k++)
173 /* row/column j is the kth row/column in the permuted matrix */
174 j = P [k] ;
175 Pinv [j] = k ;
176 System.out.printf (" %2d", j) ;
178 System.out.printf ("\n\n") ;
180 System.out.printf ("Inverse permutation vector:\n") ;
181 for (j = 0 ; j < n ; j++)
183 k = Pinv [j] ;
184 System.out.printf (" %2d", k) ;
186 System.out.printf ("\n\n") ;
188 /* print a character plot of the permuted matrix. */
189 System.out.printf ("\nPlot of permuted matrix pattern:\n") ;
190 for (jnew = 0 ; jnew < n ; jnew++)
192 j = P [jnew] ;
193 for (inew = 0 ; inew < n ; inew++) A [inew][jnew] = '.' ;
194 for (p = Ap [j] ; p < Ap [j+1] ; p++)
196 inew = Pinv [Ai [p]] ;
197 A [inew][jnew] = 'X' ;
200 System.out.printf (" ") ;
201 for (j = 0 ; j < n ; j++) System.out.printf (" %1d", j % 10) ;
202 System.out.printf ("\n") ;
203 for (i = 0 ; i < n ; i++)
205 System.out.printf ("%2d: ", i) ;
206 for (j = 0 ; j < n ; j++)
208 System.out.printf (" %c", A [i][j]) ;
210 System.out.printf ("\n") ;
213 assertEquals(AMD_OK, result) ;