00001
00020
00021
00022
00023 #include "matrix.h"
00024 #include "cutil.h"
00025 #include "freelist.h"
00026 #include "callcpp.h"
00027
00028
00029
00030
00031
00038 MATRIX create_matrix(int dimension) {
00039 MATRIX m;
00040 int x;
00041 int y;
00042
00043 m = (MATRIX) memalloc ((dimension * dimension + 1) * sizeof (LIST));
00044 m[0] = (LIST) dimension;
00045 for (x = 0; x < dimension; x++)
00046 for (y = 0; y < dimension; y++)
00047 matrix_put(m, x, y, NOT_CLASSIFIED);
00048 return (m);
00049 }
00050
00051
00052
00056 void free_matrix(MATRIX matrix) {
00057 int x;
00058 int y;
00059 int dimension = matrix_dimension (matrix);
00060 CHOICES matrix_cell;
00061
00062 for (x = 0; x < dimension; x++) {
00063 for (y = 0; y < dimension; y++) {
00064 matrix_cell = matrix_get (matrix, x, y);
00065 if (matrix_cell != NOT_CLASSIFIED)
00066 free_choices(matrix_cell);
00067 }
00068 }
00069 memfree(matrix);
00070 }
00071
00072
00073
00077 void print_matrix(MATRIX rating_matrix) {
00078 int x;
00079 int dimension;
00080 int spread;
00081 CHOICES rating;
00082
00083 cprintf ("Ratings Matrix (top choices)\n");
00084
00085 dimension = matrix_dimension (rating_matrix);
00086
00087 for (spread = 0; spread < dimension; spread++) {
00088
00089 for (x = 0; x < dimension - spread; x++) {
00090
00091 rating = matrix_get (rating_matrix, x, x + spread);
00092
00093 if (rating != NOT_CLASSIFIED) {
00094 cprintf ("\t[%d,%d] : ", x, x + spread);
00095 if (first (rating))
00096 cprintf ("%-10s%4.0f\t|\t",
00097 class_string (first (rating)),
00098 class_probability (first (rating)));
00099 if (second (rating))
00100 cprintf ("%-10s%4.0f\t|\t",
00101 class_string (second (rating)),
00102 class_probability (second (rating)));
00103 if (third (rating))
00104 cprintf ("%-10s%4.0f\n",
00105 class_string (third (rating)),
00106 class_probability (third (rating)));
00107 else
00108 new_line();
00109 }
00110 }
00111 }
00112 }