/* * minimum-weight.c * * Minimum Hamming weight computation for linear codes over * finite field. * * Note that: * q=2, if the code is doubly-even then the weights of the * code satisfy 0 mod 4 * if the code is singly-even then the weights of the * code satisfy 0 mod 2 * provision for code with codewords of minimum weight * satisfies 1 mod 2 (odd) and 3 mod 4 constraints * are also taken into account * q=3, if the code is self-orthogonal (or self-dual) then * the weights of the code satisfy 0 mod 3. * In order to take these constraints into account, a parameter * 'm' or 'mod' is used as an argument to this program. * * Version Log: * 0.1 18 March 2008 (first released to public -- GUAVA 3.3) * * CJ, Tjhai * email: ctjhai@plymouth.ac.uk * Homepage: www.plymouth.ac.uk/staff/ctjhai *
*/
/*--------------------- Function prototypes -----------------------*/ int generator_matrix(char *fname, MATRIX *M); void print_usage(FILE *stream, int exitcode, char *str); int mindist(MATRIX G, int m_mod, int lower_bound); int cyclic_mindist(MATRIX G, int m_mod, int lower_bound); /*-----------------------------------------------------------------*/
/* Main entry point */ int main(int argc, char *argv[]) {
MATRIX G;
FILE *fptr; int opt, dmin; int cyclic_code, m_mod, lower_bound; char *output_file; constchar* const short_options = "hcmlo:"; /* Valid short option characters */ conststruct option long_options[] = { /* Valid long options strings */
{ "help", 0, NULL, 'h' },
{ "cyclic", 0, NULL, 'c' },
{ "mod", 1, NULL, 'm' },
{ "lower-bound", 1, NULL, 'l' },
{ "out", 1, NULL, 'o' },
{ NULL, 0, NULL, 0 } /* Required at end of array */
};
if (dmin) {
printf("Minimum weight: %d\n", dmin); fflush(stdout);
if (output_file) {
fptr = fopen(output_file, "w"); if (!fptr) {
fprintf(stderr, "Unable to open %s\n", output_file); return -1;
}
fprintf(fptr, "GUAVA_TEMP_VAR := %d;\n", dmin);
fclose(fptr);
}
}
/* Deallocate memory */
clear_popcount();
return 0;
}
/* Display options to use this program */ void print_usage(FILE *stream, int exitcode, char *str) {
fprintf(stream, "Usage: %s options [generator matrix file]\n", str);
fprintf(stream, " -h --help Display this help screen\n");
fprintf(stream, " -c --cyclic Indicate that the code is cyclic\n");
fprintf(stream, " -l --lower-bound [x] Known lower-bound on the minimum distance\n");
fprintf(stream, " -m --mod [x] Constraint on minimum weight codeword\n");
fprintf(stream, " 1 : 0 mod 2\n");
fprintf(stream, " 2 : 1 mod 2\n");
fprintf(stream, " 3 : 3 mod 4\n");
fprintf(stream, " 4 : 0 mod 4\n");
fprintf(stream, " 5 : 0 mod 3\n");
fprintf(stream, "\n"); exit(exitcode);
}
/* Read generator matrix from file */ int generator_matrix(char *fname, MATRIX *M) { int i, j;
FILE *fptr;
fptr = fopen(fname, "r"); if (!fptr) {
fprintf(stderr, "Error opening %s\n", fname); return -1;
} if ( fscanf(fptr, "%d %d %d\n", &M->rows, &M->cols, &M->q) < 0 ) {
fprintf(stderr, "Error reading header of %s\n", fname);
} if (M->rows < 32768) {
M->m = (unsignedint **)malloc(M->rows * sizeof(unsignedint *));
} else {
fprintf(stderr, "Error: max number of cols exceeded.\n"); return -1;
} for (i=0; i<M->rows; i++)
M->m[i] = (unsignedint *)malloc(M->cols * sizeof(unsignedint)); for (i=0; i<M->rows; i++) { for (j=0; j<M->cols; j++) { if ( fscanf(fptr, "%d ", &M->m[i][j]) < 0 ) {
fprintf(stderr, "Error reading data from %s\n", fname);
}
}
}
return 0;
}
/* Minimum weight for cyclic code */ int cyclic_mindist(MATRIX G, int m_mod, int lower_bound) { if (G.q == 2) /* binary field */ return cyclic_mindist_gf2(G, m_mod, lower_bound); elseif (G.q == 3) /* ternary field */ return cyclic_mindist_gf3(G, m_mod, lower_bound); else {
fprintf(stderr, "Minimum weight computation over this field is not implemented yet\n"); return -2;
}
}
/* Minimum weight for general linear code */ int mindist(MATRIX G, int m_mod, int lower_bound) { if (G.q == 2) /* binary field */ return mindist_gf2(G, m_mod, lower_bound); elseif (G.q == 3) /* ternary field */ return mindist_gf3(G, m_mod, lower_bound); else {
fprintf(stderr, "Minimum weight computation over this field is not implemented yet\n"); return -2;
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.