[GRASS-SVN] r41684 - in grass-addons/raster/mcda: r.mcda.electre
r.mcda.fuzzy r.mcda.regime r.roughset
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Apr 3 05:29:09 EDT 2010
Author: hamish
Date: 2010-04-03 05:29:09 -0400 (Sat, 03 Apr 2010)
New Revision: 41684
Modified:
grass-addons/raster/mcda/r.mcda.electre/dominance.c
grass-addons/raster/mcda/r.mcda.electre/local_proto.h
grass-addons/raster/mcda/r.mcda.electre/main.c
grass-addons/raster/mcda/r.mcda.fuzzy/fuzzy.c
grass-addons/raster/mcda/r.mcda.fuzzy/local_proto.h
grass-addons/raster/mcda/r.mcda.fuzzy/main.c
grass-addons/raster/mcda/r.mcda.regime/local_proto.h
grass-addons/raster/mcda/r.mcda.regime/main.c
grass-addons/raster/mcda/r.mcda.regime/regime.c
grass-addons/raster/mcda/r.roughset/localproto.h
grass-addons/raster/mcda/r.roughset/main.c
grass-addons/raster/mcda/r.roughset/raccess.c
grass-addons/raster/mcda/r.roughset/raccess.h
grass-addons/raster/mcda/r.roughset/rbasic.c
grass-addons/raster/mcda/r.roughset/rbasic.h
grass-addons/raster/mcda/r.roughset/rclass.c
grass-addons/raster/mcda/r.roughset/rclass.h
grass-addons/raster/mcda/r.roughset/rcore.c
grass-addons/raster/mcda/r.roughset/rcore.h
grass-addons/raster/mcda/r.roughset/reduct1.c
grass-addons/raster/mcda/r.roughset/reduct1.h
grass-addons/raster/mcda/r.roughset/reduct2.c
grass-addons/raster/mcda/r.roughset/reduct2.h
grass-addons/raster/mcda/r.roughset/rerror.h
grass-addons/raster/mcda/r.roughset/rough.h
grass-addons/raster/mcda/r.roughset/rset.c
grass-addons/raster/mcda/r.roughset/rset.h
grass-addons/raster/mcda/r.roughset/rsystem.h
grass-addons/raster/mcda/r.roughset/rule1.c
grass-addons/raster/mcda/r.roughset/rule1.h
grass-addons/raster/mcda/r.roughset/rule2.c
grass-addons/raster/mcda/r.roughset/rule2.h
grass-addons/raster/mcda/r.roughset/rules_extr.c
Log:
run the tools/grass_indent script. rsystem.c *NOT* indented due to these errors:
indent: rsystem.c:110: Error:Unmatched 'else'
indent: rsystem.c:114: Error:Unmatched 'else'
indent: rsystem.c:375: Error:Stmt nesting error.
indent: rsystem.c:376: Error:Unmatched 'else'
indent: rsystem.c:467: Error:Unexpected end of file
Modified: grass-addons/raster/mcda/r.mcda.electre/dominance.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.electre/dominance.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.mcda.electre/dominance.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -4,100 +4,99 @@
* global function declaration
*/
-void build_weight_vect(int nrows, int ncols, int ncriteria, struct Option *weight, double *weight_vect);
+void build_weight_vect(int nrows, int ncols, int ncriteria,
+ struct Option *weight, double *weight_vect);
-void build_dominance_matrix(int nrows, int ncols, int ncriteria, double *weight_vect, double ***decision_vol);
+void build_dominance_matrix(int nrows, int ncols, int ncriteria,
+ double *weight_vect, double ***decision_vol);
/*
* function definitions
*/
-void build_weight_vect(int nrows, int ncols, int ncriteria,struct Option *weight, double *weight_vect)
+void build_weight_vect(int nrows, int ncols, int ncriteria,
+ struct Option *weight, double *weight_vect)
{
-
- int i,nweight=0;
- double weight_sum=0;
-
- while (weight->answers[nweight]!=NULL)
- {
- nweight++;
- }
-
- if(nweight!=ncriteria)
- G_fatal_error(_("criteria number and weight number are different"));
+ int i, nweight = 0;
+ double weight_sum = 0;
-
- for(i=0;i<nweight;i++)
- {
- weight_vect[i]=(atof(weight->answers[i])); /*transfer weight value in double array*/
- weight_sum=weight_sum+weight_vect[i]; /*calculate sum weight*/
- }
-
- for(i=0;i<nweight;i++)
- {
- weight_vect[i]=weight_vect[i]/weight_sum; /*normalize vector weight*/
+ while (weight->answers[nweight] != NULL) {
+ nweight++;
+ }
- }
+ if (nweight != ncriteria)
+ G_fatal_error(_("criteria number and weight number are different"));
+
+
+ for (i = 0; i < nweight; i++) {
+ weight_vect[i] = (atof(weight->answers[i])); /*transfer weight value in double array */
+ weight_sum = weight_sum + weight_vect[i]; /*calculate sum weight */
+ }
+
+ for (i = 0; i < nweight; i++) {
+ weight_vect[i] = weight_vect[i] / weight_sum; /*normalize vector weight */
+
+ }
+
}
-void build_dominance_matrix(int nrows, int ncols, int ncriteria,double *weight_vect, double ***decision_vol)
+void build_dominance_matrix(int nrows, int ncols, int ncriteria,
+ double *weight_vect, double ***decision_vol)
{
- int row1, col1, row2, col2;
- int i, j, k, cont;
- double *row_sum_conc = G_alloc_vector(nrows * ncols);
- double *col_sum_conc = G_alloc_vector(nrows * ncols);
- double *row_sum_disc = G_alloc_vector(nrows * ncols);
- double *col_sum_disc = G_alloc_vector(nrows * ncols);
+ int row1, col1, row2, col2;
+ int i, j, k, cont;
+ double *row_sum_conc = G_alloc_vector(nrows * ncols);
+ double *col_sum_conc = G_alloc_vector(nrows * ncols);
+ double *row_sum_disc = G_alloc_vector(nrows * ncols);
+ double *col_sum_disc = G_alloc_vector(nrows * ncols);
- k = 0; /* make pairwise comparation and build concordance/discordance matrix */
- for (row1 = 0; row1 < nrows; row1++)
- {
- G_percent(row1, nrows, 2);
- for (col1 = 0; col1 < ncols; col1++)
- {
- j = 0;
- for (row2 = 0; row2 < nrows; row2++)
- {
- for (col2 = 0; col2 < ncols; col2++)
- {
- double conc = 0, disc = 0;
- for (i = 0; i < ncriteria; i++)
- {
- double d = decision_vol[row1][col1][i] - decision_vol[row2][col2][i];
- if (d >= 0)
- conc += weight_vect[i];
- if (d < disc) /*WARNING: if(d>conc)*//**/
- disc = -d;
- }
- row_sum_conc[k] += conc;
- col_sum_conc[j] += conc;
- row_sum_disc[k] += disc;
- col_sum_disc[j] += disc;
+ k = 0; /* make pairwise comparation and build concordance/discordance matrix */
+ for (row1 = 0; row1 < nrows; row1++) {
+ G_percent(row1, nrows, 2);
+ for (col1 = 0; col1 < ncols; col1++) {
+ j = 0;
+ for (row2 = 0; row2 < nrows; row2++) {
+ for (col2 = 0; col2 < ncols; col2++) {
+ double conc = 0, disc = 0;
- j++; /* increase rows index up to nrows*ncols */
- }
- }
- k++; /* increase columns index up to nrows*ncols */
- }
+ for (i = 0; i < ncriteria; i++) {
+ double d =
+ decision_vol[row1][col1][i] -
+ decision_vol[row2][col2][i];
+ if (d >= 0)
+ conc += weight_vect[i];
+ if (d < disc) /*WARNING: if(d>conc) */
+ /**/ disc = -d;
+ }
+ row_sum_conc[k] += conc;
+ col_sum_conc[j] += conc;
+ row_sum_disc[k] += disc;
+ col_sum_disc[j] += disc;
+
+ j++; /* increase rows index up to nrows*ncols */
}
+ }
+ k++; /* increase columns index up to nrows*ncols */
+ }
+ }
- /*calculate concordance and discordance index and storage in decision_vol */
- cont = 0; /*variabile progressiva per riga/colonna della concordance_map */
- for (row1 = 0; row1 < nrows; row1++) {
- G_percent(row1, nrows, 2);
- for (col1 = 0; col1 < ncols; col1++) {
-
- /*fill matrix with concordance index for each DCELL */
- decision_vol[row1][col1][ncriteria] = row_sum_conc[cont] - col_sum_conc[cont];
- /*fill matrix with discordance index for each DCELL */
- decision_vol[row1][col1][ncriteria + 1] = row_sum_disc[cont] - col_sum_disc[cont];
- cont++;
- }
- }
-}
+ /*calculate concordance and discordance index and storage in decision_vol */
+ cont = 0; /*variabile progressiva per riga/colonna della concordance_map */
+ for (row1 = 0; row1 < nrows; row1++) {
+ G_percent(row1, nrows, 2);
+ for (col1 = 0; col1 < ncols; col1++) {
-
+ /*fill matrix with concordance index for each DCELL */
+ decision_vol[row1][col1][ncriteria] =
+ row_sum_conc[cont] - col_sum_conc[cont];
+ /*fill matrix with discordance index for each DCELL */
+ decision_vol[row1][col1][ncriteria + 1] =
+ row_sum_disc[cont] - col_sum_disc[cont];
+ cont++;
+ }
+ }
+}
Modified: grass-addons/raster/mcda/r.mcda.electre/local_proto.h
===================================================================
--- grass-addons/raster/mcda/r.mcda.electre/local_proto.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.mcda.electre/local_proto.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -9,7 +9,7 @@
struct input
{
- char *name, *mapset; /* input raster name and mapset name*/
- int infd;
- void *inrast; /* input buffer */
+ char *name, *mapset; /* input raster name and mapset name */
+ int infd;
+ void *inrast; /* input buffer */
};
Modified: grass-addons/raster/mcda/r.mcda.electre/main.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.electre/main.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.mcda.electre/main.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.mcda.electre
@@ -23,15 +24,15 @@
int main(int argc, char *argv[])
{
struct Cell_head cellhd; /* it stores region information, and header information of rasters */
- char *result_concordance, *result_discordance; /* outputs raster name */
+ char *result_concordance, *result_discordance; /* outputs raster name */
char *mapset; /* mapset name */
unsigned char *outrast_concordance, *outrast_discordance; /* output buffer */
char *message;
- int i,j, ncriteria=0; /* index and files number*/
+ int i, j, ncriteria = 0; /* index and files number */
int nrows, ncols;
int row1, row2, col1, col2;
- int outfd_concordance, outfd_discordance; /* output file descriptor */
- double *weight_vect, ***decision_vol;/* vector and matrix */
+ int outfd_concordance, outfd_discordance; /* output file descriptor */
+ double *weight_vect, ***decision_vol; /* vector and matrix */
struct History history; /* holds meta-data (title, comments,..) */
@@ -40,7 +41,7 @@
struct Option *criteria, *weight, *discordance, *concordance; /* options */
- struct input *attributes; /*storage alla input criteria GRID files and output concordance and discordance GRID files*/
+ struct input *attributes; /*storage alla input criteria GRID files and output concordance and discordance GRID files */
/* initialize GIS environment */
@@ -49,38 +50,40 @@
/* initialize module */
module = G_define_module();
module->keywords = _("raster,MCDA");
- module->description = _("Multicirtieria decision analysis based on ELECTRE method");
+ module->description =
+ _("Multicirtieria decision analysis based on ELECTRE method");
/* Define the different options as defined in gis.h */
- criteria = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory*/
- criteria->key = "criteria";
- criteria->type = TYPE_STRING;
- criteria->required = YES;
- criteria->multiple = YES;
- criteria->gisprompt = "old,cell,raster" ;
- criteria->description = "Input geographics criteria in information system";
+ criteria = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ criteria->key = "criteria";
+ criteria->type = TYPE_STRING;
+ criteria->required = YES;
+ criteria->multiple = YES;
+ criteria->gisprompt = "old,cell,raster";
+ criteria->description =
+ "Input geographics criteria in information system";
- weight = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory*/
- weight->key = "weight";
- weight->type = TYPE_DOUBLE;
- weight->required = YES;
- weight->multiple = YES;
+ weight = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ weight->key = "weight";
+ weight->type = TYPE_DOUBLE;
+ weight->required = YES;
+ weight->multiple = YES;
weight->description = _("Criteria weight(s) (w1,w2,..)");
- concordance = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
- concordance->key = "concordance";
+ concordance = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ concordance->key = "concordance";
concordance->type = TYPE_STRING;
concordance->required = YES;
concordance->gisprompt = "new,cell,raster";
- concordance->answer ="concordance";
+ concordance->answer = "concordance";
concordance->description = "concordance output map";
- discordance = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
- discordance->key = "discordance";
+ discordance = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ discordance->key = "discordance";
discordance->type = TYPE_STRING;
discordance->required = YES;
discordance->gisprompt = "new,cell,raster";
- discordance->answer ="discordance";
+ discordance->answer = "discordance";
discordance->description = "discordance output map";
/* options and flags parser */
@@ -88,134 +91,137 @@
exit(EXIT_FAILURE);
- G_message("Start: %s",G_date()); /*write calculation start time*/
+ G_message("Start: %s", G_date()); /*write calculation start time */
- /* number of file (=criteria) */
- while (criteria->answers[ncriteria]!=NULL)
- {
- ncriteria++;
- }
+ /* number of file (=criteria) */
+ while (criteria->answers[ncriteria] != NULL) {
+ ncriteria++;
+ }
- /* process the input maps: stores options and flags to variables */
+ /* process the input maps: stores options and flags to variables */
/* CRITERIA grid */
- attributes = G_malloc(ncriteria * sizeof(struct input)); /*attributes is input struct defined in top file and store alla criteria files*/
- weight_vect=G_malloc(ncriteria * sizeof(double)); /*allocate memory fron vector weight*/
+ attributes = G_malloc(ncriteria * sizeof(struct input)); /*attributes is input struct defined in top file and store alla criteria files */
+ weight_vect = G_malloc(ncriteria * sizeof(double)); /*allocate memory fron vector weight */
- build_weight_vect(nrows,ncols,ncriteria,weight,weight_vect); /*calcolate weight vector*/
+ build_weight_vect(nrows, ncols, ncriteria, weight, weight_vect); /*calcolate weight vector */
- for (i = 0; i < ncriteria; i++)
- {
- struct input *p = &attributes[i];
- p->name = criteria->answers[i];
- p->mapset = G_find_cell2(p->name,""); /* G_find_cell: Looks for the raster map "name" in the database. */
- if (p->mapset==NULL) /* returns NULL if the map was not found in any mapset, mapset name otherwise */
- G_fatal_error(_("Raster file <%s> not found"), p->name);
+ for (i = 0; i < ncriteria; i++) {
+ struct input *p = &attributes[i];
- if((p->infd = G_open_cell_old(p->name, p->mapset))<0) /* G_open_cell_old - returns file destriptor (>0) */
- G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),p->name, p->mapset);
+ p->name = criteria->answers[i];
+ p->mapset = G_find_cell2(p->name, ""); /* G_find_cell: Looks for the raster map "name" in the database. */
+ if (p->mapset == NULL) /* returns NULL if the map was not found in any mapset, mapset name otherwise */
+ G_fatal_error(_("Raster file <%s> not found"), p->name);
- if(G_get_cellhd(p->name,p->mapset,&cellhd)<0)/* controlling, if we can open input raster */
- G_fatal_error(_("Unable to read file header of <%s>"), p->name);
+ if ((p->infd = G_open_cell_old(p->name, p->mapset)) < 0) /* G_open_cell_old - returns file destriptor (>0) */
+ G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
+ p->name, p->mapset);
- p->inrast = G_allocate_d_raster_buf(); /* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL */
- }
+ if (G_get_cellhd(p->name, p->mapset, &cellhd) < 0) /* controlling, if we can open input raster */
+ G_fatal_error(_("Unable to read file header of <%s>"), p->name);
- result_concordance=concordance->answer; /* store outputn name in variables*/
- result_discordance=discordance->answer;
+ p->inrast = G_allocate_d_raster_buf(); /* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL */
+ }
+ result_concordance = concordance->answer; /* store outputn name in variables */
+ result_discordance = discordance->answer;
- if (G_legal_filename(result_concordance) < 0) /* check for legal database file names */
- G_fatal_error(_("<%s> is an illegal file name"), result_concordance);
- if (G_legal_filename(result_discordance) < 0) /* check for legal database file names */
- G_fatal_error(_("<%s> is an illegal file name"), result_discordance);
+ if (G_legal_filename(result_concordance) < 0) /* check for legal database file names */
+ G_fatal_error(_("<%s> is an illegal file name"), result_concordance);
- /*values = G_malloc(ncriteria * sizeof(DCELL));*/
+ if (G_legal_filename(result_discordance) < 0) /* check for legal database file names */
+ G_fatal_error(_("<%s> is an illegal file name"), result_discordance);
- nrows = G_window_rows();
- ncols = G_window_cols();
+ /*values = G_malloc(ncriteria * sizeof(DCELL)); */
- /*memory allocation for-three dimensional matrix*/
- decision_vol=G_malloc(nrows * sizeof(double*));
- for (i=0; i<nrows; ++i)
- {
- decision_vol[i]=G_malloc(ncols * sizeof(double*));
- for (j=0; j<ncols; ++j)
- {
- decision_vol[i][j]=G_malloc((ncriteria+2) * sizeof(double)); /****NOTE: it's storage enven concordance and discordance index map****/
- }
- }
+ nrows = G_window_rows();
+ ncols = G_window_cols();
+ /*memory allocation for-three dimensional matrix */
+ decision_vol = G_malloc(nrows * sizeof(double *));
+ for (i = 0; i < nrows; ++i) {
+ decision_vol[i] = G_malloc(ncols * sizeof(double *));
+ for (j = 0; j < ncols; ++j) {
+
+ decision_vol[i][j] = G_malloc((ncriteria + 2) * sizeof(double)); /****NOTE: it's storage enven concordance and discordance index map****/
+ }
+ }
+
/* Allocate output buffer, use DCELL_TYPE */
- outrast_concordance = G_allocate_raster_buf(DCELL_TYPE); /* Allocate memory for a raster map of type DCELL_TYPE. */
- outrast_discordance = G_allocate_raster_buf(DCELL_TYPE);
+ outrast_concordance = G_allocate_raster_buf(DCELL_TYPE); /* Allocate memory for a raster map of type DCELL_TYPE. */
+ outrast_discordance = G_allocate_raster_buf(DCELL_TYPE);
/* controlling, if we can write the raster */
- if ((outfd_concordance = G_open_raster_new(result_concordance, DCELL_TYPE)) < 0)
- G_fatal_error(_("Unable to create raster map <%s>"), result_concordance);
+ if ((outfd_concordance =
+ G_open_raster_new(result_concordance, DCELL_TYPE)) < 0)
+ G_fatal_error(_("Unable to create raster map <%s>"),
+ result_concordance);
- if ((outfd_discordance = G_open_raster_new(result_discordance, DCELL_TYPE)) < 0)
- G_fatal_error(_("Unable to create raster map <%s>"), result_discordance);
+ if ((outfd_discordance =
+ G_open_raster_new(result_discordance, DCELL_TYPE)) < 0)
+ G_fatal_error(_("Unable to create raster map <%s>"),
+ result_discordance);
- /*build a three dimensional matrix for storage all critera maps*/
- for(i=0;i<ncriteria;i++)
- {
- for (row1 = 0; row1 < nrows;row1++)
- {
- G_get_raster_row(attributes[i].infd, attributes[i].inrast, row1,DCELL_TYPE);/* Reads appropriate information into the buffer buf associated with the requested row*/
- /*G_fatal_error(_("Unable to read raster map <%s> row %d"), criteria->answers[i], row);*/
- for (col1 = 0; col1 < ncols; col1++)
- {
- /* viene letto il valore di cella e lo si attribuisce ad una variabile di tipo DCELL e poi ad un array*/
- DCELL v1 = ((DCELL *)attributes[i].inrast)[col1];
- decision_vol[row1][col1][i]=(double)(v1);
+ /*build a three dimensional matrix for storage all critera maps */
+ for (i = 0; i < ncriteria; i++) {
+ for (row1 = 0; row1 < nrows; row1++) {
+ G_get_raster_row(attributes[i].infd, attributes[i].inrast, row1, DCELL_TYPE); /* Reads appropriate information into the buffer buf associated with the requested row */
+ /*G_fatal_error(_("Unable to read raster map <%s> row %d"), criteria->answers[i], row); */
+ for (col1 = 0; col1 < ncols; col1++) {
+ /* viene letto il valore di cella e lo si attribuisce ad una variabile di tipo DCELL e poi ad un array */
+ DCELL v1 = ((DCELL *) attributes[i].inrast)[col1];
- }
- }
- }
+ decision_vol[row1][col1][i] = (double)(v1);
+ }
+ }
+ }
- build_dominance_matrix(nrows,ncols,ncriteria,weight_vect,decision_vol); /*scan all DCELL, make a pairwise comparatione, buil concordance and discordance matrix and relative index*/
+ build_dominance_matrix(nrows, ncols, ncriteria, weight_vect, decision_vol); /*scan all DCELL, make a pairwise comparatione, buil concordance and discordance matrix and relative index */
- for(row1 = 0; row1 < nrows; row1++)
- {
- for (col1 = 0; col1 < ncols; col1++)
- {
- ((DCELL *) outrast_concordance)[col1] = (DCELL)decision_vol[row1][col1][ncriteria];/*write concordance map*/
- ((DCELL *) outrast_discordance)[col1] = (DCELL)decision_vol[row1][col1][ncriteria+1];/*write discordance map*/
- }
- if (G_put_raster_row(outfd_concordance, outrast_concordance, DCELL_TYPE) < 0)
- G_fatal_error(_("Failed writing raster map <%s>"), result_concordance);
- if (G_put_raster_row(outfd_discordance, outrast_discordance, DCELL_TYPE) < 0)
- G_fatal_error(_("Failed writing raster map <%s>"), result_discordance);
- }
+ for (row1 = 0; row1 < nrows; row1++) {
+ for (col1 = 0; col1 < ncols; col1++) {
+ ((DCELL *) outrast_concordance)[col1] = (DCELL) decision_vol[row1][col1][ncriteria]; /*write concordance map */
+ ((DCELL *) outrast_discordance)[col1] = (DCELL) decision_vol[row1][col1][ncriteria + 1]; /*write discordance map */
+ }
+ if (G_put_raster_row
+ (outfd_concordance, outrast_concordance, DCELL_TYPE) < 0)
+ G_fatal_error(_("Failed writing raster map <%s>"),
+ result_concordance);
+ if (G_put_raster_row
+ (outfd_discordance, outrast_discordance, DCELL_TYPE) < 0)
+ G_fatal_error(_("Failed writing raster map <%s>"),
+ result_discordance);
+ }
- G_message("End: %s",G_date());
+ G_message("End: %s", G_date());
+
/* memory cleanup */
- for (i = 0; i<ncriteria; i++)
- G_free(attributes[i].inrast);
+ for (i = 0; i < ncriteria; i++)
+ G_free(attributes[i].inrast);
G_free(outrast_concordance);
- G_free(outrast_discordance);
- G_free(decision_vol);
+ G_free(outrast_discordance);
+ G_free(decision_vol);
/* closing raster maps */
- for (i = 0; i<ncriteria; i++)
- G_close_cell(attributes[i].infd);
+ for (i = 0; i < ncriteria; i++)
+ G_close_cell(attributes[i].infd);
G_close_cell(outfd_concordance);
- G_close_cell(outfd_discordance);
+ G_close_cell(outfd_discordance);
/* add command line incantation to history concordance file */
G_short_history(result_concordance, "raster", &history);
@@ -229,5 +235,3 @@
exit(EXIT_SUCCESS);
}
-
-
Modified: grass-addons/raster/mcda/r.mcda.fuzzy/fuzzy.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.fuzzy/fuzzy.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.mcda.fuzzy/fuzzy.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -4,116 +4,109 @@
* global function declaration
*/
-void build_weight_vect(int nrows, int ncols, int ncriteria, struct Option *weight, double *weight_vect);
+void build_weight_vect(int nrows, int ncols, int ncriteria,
+ struct Option *weight, double *weight_vect);
-void build_fuzzy_matrix(int nrows, int ncols, int ncriteria, double *weight_vect, double ***decision_vol);
+void build_fuzzy_matrix(int nrows, int ncols, int ncriteria,
+ double *weight_vect, double ***decision_vol);
/*
* function definitions
*/
-void build_weight_vect(int nrows, int ncols, int ncriteria,struct Option *weight, double *weight_vect)
+void build_weight_vect(int nrows, int ncols, int ncriteria,
+ struct Option *weight, double *weight_vect)
{
-
- int i,nweight=0;
- double weight_sum=0;
-
- while (weight->answers[nweight]!=NULL)
- {
- nweight++;
- }
-
- if(nweight!=ncriteria)
- G_fatal_error(_("criteria number and weight number are different"));
+ int i, nweight = 0;
+ double weight_sum = 0;
-
- for(i=0;i<nweight;i++)
- {
- weight_vect[i]=(atof(weight->answers[i])); /*transfer weight value in double array*/
- weight_sum=weight_sum+weight_vect[i]; /*calculate sum weight*/
- }
-
- for(i=0;i<nweight;i++)
- {
- weight_vect[i]=weight_vect[i]/weight_sum; /*normalize vector weight*/
+ while (weight->answers[nweight] != NULL) {
+ nweight++;
+ }
- }
+ if (nweight != ncriteria)
+ G_fatal_error(_("criteria number and weight number are different"));
+
+
+ for (i = 0; i < nweight; i++) {
+ weight_vect[i] = (atof(weight->answers[i])); /*transfer weight value in double array */
+ weight_sum = weight_sum + weight_vect[i]; /*calculate sum weight */
+ }
+
+ for (i = 0; i < nweight; i++) {
+ weight_vect[i] = weight_vect[i] / weight_sum; /*normalize vector weight */
+
+ }
+
}
-void build_fuzzy_matrix(int nrows, int ncols, int ncriteria, double *weight_vect, double ***decision_vol)
-{
- int row1,col1,row2,col2;
- int i,j,k,cont;
- double row_sum_conc, col_sum_conc,row_sum_disc, col_sum_disc;
- double value;
-
- /* apply linguistic modifier -*/
- for (row1=0;row1<nrows;row1++)
- {
- G_percent(row1, nrows, 2);
- for (col1=0;col1<ncols;col1++)
- {
- for(i=0;i<ncriteria;i++)
- {
- decision_vol[row1][col1][i]=pow(decision_vol[row1][col1][i],weight_vect[i]);
- }
- }
- }
+void build_fuzzy_matrix(int nrows, int ncols, int ncriteria,
+ double *weight_vect, double ***decision_vol)
+{
+ int row1, col1, row2, col2;
+ int i, j, k, cont;
+ double row_sum_conc, col_sum_conc, row_sum_disc, col_sum_disc;
+ double value;
- /* operate intersection - AND logic (find min value -)*/
- for(row1=0;row1<nrows;row1++)
- {
- G_percent(row1, nrows, 2);
- for(col1=0;col1<ncols;col1++)
- {
- value=decision_vol[row1][col1][0]; /* set value to firsth matrix i-value*/
- for(i=0;i<ncriteria;i++)
- {
- if (decision_vol[row1][col1][i]>=value)
- {value=value;}
- else
- {value=decision_vol[row1][col1][i];}
- }
- decision_vol[row1][col1][ncriteria]=value;
- }
+ /* apply linguistic modifier - */
+ for (row1 = 0; row1 < nrows; row1++) {
+ G_percent(row1, nrows, 2);
+ for (col1 = 0; col1 < ncols; col1++) {
+ for (i = 0; i < ncriteria; i++) {
+ decision_vol[row1][col1][i] =
+ pow(decision_vol[row1][col1][i], weight_vect[i]);
+ }
+ }
+ }
+
+ /* operate intersection - AND logic (find min value -) */
+ for (row1 = 0; row1 < nrows; row1++) {
+ G_percent(row1, nrows, 2);
+ for (col1 = 0; col1 < ncols; col1++) {
+ value = decision_vol[row1][col1][0]; /* set value to firsth matrix i-value */
+ for (i = 0; i < ncriteria; i++) {
+ if (decision_vol[row1][col1][i] >= value) {
+ value = value;
}
-
- /* operate union - OR logic (find max value -)*/
- for(row1=0;row1<nrows;row1++)
- {
- G_percent(row1, nrows, 2);
- for(col1=0;col1<ncols;col1++)
- {
- value=decision_vol[row1][col1][0]; /* set value to firsth matrix i-value*/
- for(i=0;i<ncriteria;i++)
- {
- if (decision_vol[row1][col1][i]<=value)
- {value=value;}
- else
- {value=decision_vol[row1][col1][i];}
- }
- decision_vol[row1][col1][ncriteria+1]=value;
- }
+ else {
+ value = decision_vol[row1][col1][i];
}
-
- /* operate OWA (find average value -)*/
- for(row1=0;row1<nrows;row1++)
- {
- G_percent(row1, nrows, 2);
- for(col1=0;col1<ncols;col1++)
- {
- value=decision_vol[row1][col1][0]; /* set value to firsth matrix i-value*/
- for(i=0;i<ncriteria;i++)
- {
- value=value+decision_vol[row1][col1][i];
- }
- decision_vol[row1][col1][ncriteria+2]=value/ncriteria;
- }
+ }
+ decision_vol[row1][col1][ncriteria] = value;
+ }
+ }
+
+ /* operate union - OR logic (find max value -) */
+ for (row1 = 0; row1 < nrows; row1++) {
+ G_percent(row1, nrows, 2);
+ for (col1 = 0; col1 < ncols; col1++) {
+ value = decision_vol[row1][col1][0]; /* set value to firsth matrix i-value */
+ for (i = 0; i < ncriteria; i++) {
+ if (decision_vol[row1][col1][i] <= value) {
+ value = value;
}
-
-}
+ else {
+ value = decision_vol[row1][col1][i];
+ }
+ }
+ decision_vol[row1][col1][ncriteria + 1] = value;
+ }
+ }
+ /* operate OWA (find average value -) */
+ for (row1 = 0; row1 < nrows; row1++) {
+ G_percent(row1, nrows, 2);
+ for (col1 = 0; col1 < ncols; col1++) {
+ value = decision_vol[row1][col1][0]; /* set value to firsth matrix i-value */
+ for (i = 0; i < ncriteria; i++) {
+ value = value + decision_vol[row1][col1][i];
+ }
+ decision_vol[row1][col1][ncriteria + 2] = value / ncriteria;
+ }
+ }
+
+}
Modified: grass-addons/raster/mcda/r.mcda.fuzzy/local_proto.h
===================================================================
--- grass-addons/raster/mcda/r.mcda.fuzzy/local_proto.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.mcda.fuzzy/local_proto.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -9,7 +9,7 @@
struct input
{
- char *name, *mapset; /* input raster name and mapset name*/
- int infd;
- void *inrast; /* input buffer */
+ char *name, *mapset; /* input raster name and mapset name */
+ int infd;
+ void *inrast; /* input buffer */
};
Modified: grass-addons/raster/mcda/r.mcda.fuzzy/main.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.fuzzy/main.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.mcda.fuzzy/main.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.mcda.electre
@@ -23,14 +24,14 @@
int main(int argc, char *argv[])
{
struct Cell_head cellhd; /* it stores region information, and header information of rasters */
- char *result_and, *result_or, *result_owa; /* outputs raster name */
+ char *result_and, *result_or, *result_owa; /* outputs raster name */
char *mapset; /* mapset name */
unsigned char *outrast_and, *outrast_or, *outrast_owa; /* output buffer */
- int i,j, ncriteria=0; /* index and files number*/
+ int i, j, ncriteria = 0; /* index and files number */
int nrows, ncols;
int row1, row2, col1, col2;
- int outfd_and, outfd_or,outfd_owa; /* output file descriptor */
- double *weight_vect, ***decision_vol;
+ int outfd_and, outfd_or, outfd_owa; /* output file descriptor */
+ double *weight_vect, ***decision_vol;
struct History history; /* holds meta-data (title, comments,..) */
@@ -39,7 +40,7 @@
struct Option *criteria, *weight, *and, *or, *owa; /* options */
- struct input *attributes; /*storage alla input criteria GRID files and output concordance and discordance GRID files*/
+ struct input *attributes; /*storage alla input criteria GRID files and output concordance and discordance GRID files */
/* initialize GIS environment */
@@ -48,192 +49,191 @@
/* initialize module */
module = G_define_module();
module->keywords = _("raster,fuzzy,MCDA");
- module->description = _("Multicirtieria decision analysis based on Yager fuzzy method");
+ module->description =
+ _("Multicirtieria decision analysis based on Yager fuzzy method");
/* Define the different options as defined in gis.h */
- criteria = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory*/
- criteria->key = "criteria";
- criteria->type = TYPE_STRING;
- criteria->required = YES;
- criteria->multiple = YES;
- criteria->gisprompt = "old,cell,raster" ;
+ criteria = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ criteria->key = "criteria";
+ criteria->type = TYPE_STRING;
+ criteria->required = YES;
+ criteria->multiple = YES;
+ criteria->gisprompt = "old,cell,raster";
criteria->description = "Input geographics criteria in evaluation table";
- weight = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory*/
- weight->key = "weight";
- weight->type = TYPE_DOUBLE;
- weight->required = YES;
- weight->multiple = YES;
+ weight = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ weight->key = "weight";
+ weight->type = TYPE_DOUBLE;
+ weight->required = YES;
+ weight->multiple = YES;
weight->description = _("Linguistic modifier (w1,w2,..)");
- and = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
- and->key = "AND";
+ and = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ and->key = "AND";
and->type = TYPE_STRING;
and->required = YES;
and->gisprompt = "new,cell,raster";
- and->answer ="intersect";
+ and->answer = "intersect";
and->description = "Intersection output map";
- or = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
- or->key = "OR";
+ or = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ or->key = "OR";
or->type = TYPE_STRING;
or->required = YES;
or->gisprompt = "new,cell,raster";
- or->answer ="union";
+ or->answer = "union";
or->description = "Union output map";
- owa = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
- owa->key = "OWA";
+ owa = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ owa->key = "OWA";
owa->type = TYPE_STRING;
owa->required = YES;
owa->gisprompt = "new,cell,raster";
- owa->answer ="OWA";
+ owa->answer = "OWA";
owa->description = "OWA output map";
/* options and flags parser */
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
- G_message("\n\nstart: %s",G_date()); /*write calculation start time*/
+ G_message("\n\nstart: %s", G_date()); /*write calculation start time */
- /* number of file (=criteria) */
- while (criteria->answers[ncriteria]!=NULL)
- {
- ncriteria++;
- }
+ /* number of file (=criteria) */
+ while (criteria->answers[ncriteria] != NULL) {
+ ncriteria++;
+ }
- /* process the input maps: stores options and flags to variables */
+ /* process the input maps: stores options and flags to variables */
/* CRITERIA grid */
- attributes = G_malloc(ncriteria * sizeof(struct input)); /*attributes is input struct defined in top file and store alla criteria files*/
- weight_vect=G_malloc(ncriteria * sizeof(double)); /*allocate memory fron vector weight*/
+ attributes = G_malloc(ncriteria * sizeof(struct input)); /*attributes is input struct defined in top file and store alla criteria files */
+ weight_vect = G_malloc(ncriteria * sizeof(double)); /*allocate memory fron vector weight */
- build_weight_vect(nrows,ncols,ncriteria,weight,weight_vect); /*calcolate weight vector*/
+ build_weight_vect(nrows, ncols, ncriteria, weight, weight_vect); /*calcolate weight vector */
- for (i = 0; i < ncriteria; i++)
- {
- struct input *p = &attributes[i];
- p->name = criteria->answers[i];
- p->mapset = G_find_cell2(p->name,""); /* G_find_cell: Looks for the raster map "name" in the database. */
- if (p->mapset==NULL) /* returns NULL if the map was not found in any mapset, mapset name otherwise */
- G_fatal_error(_("Raster file <%s> not found"), p->name);
+ for (i = 0; i < ncriteria; i++) {
+ struct input *p = &attributes[i];
- if((p->infd = G_open_cell_old(p->name, p->mapset))<0) /* G_open_cell_old - returns file destriptor (>0) */
- G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),p->name, p->mapset);
+ p->name = criteria->answers[i];
+ p->mapset = G_find_cell2(p->name, ""); /* G_find_cell: Looks for the raster map "name" in the database. */
+ if (p->mapset == NULL) /* returns NULL if the map was not found in any mapset, mapset name otherwise */
+ G_fatal_error(_("Raster file <%s> not found"), p->name);
- if(G_get_cellhd(p->name,p->mapset,&cellhd)<0)/* controlling, if we can open input raster */
- G_fatal_error(_("Unable to read file header of <%s>"), p->name);
+ if ((p->infd = G_open_cell_old(p->name, p->mapset)) < 0) /* G_open_cell_old - returns file destriptor (>0) */
+ G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
+ p->name, p->mapset);
- p->inrast = G_allocate_d_raster_buf(); /* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL */
- }
+ if (G_get_cellhd(p->name, p->mapset, &cellhd) < 0) /* controlling, if we can open input raster */
+ G_fatal_error(_("Unable to read file header of <%s>"), p->name);
- result_and=and->answer; /* store outputn name in variables*/
- result_or=or->answer;
- result_owa=owa->answer;
+ p->inrast = G_allocate_d_raster_buf(); /* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL */
+ }
+ result_and = and->answer; /* store outputn name in variables */
+ result_or = or->answer;
+ result_owa = owa->answer;
- if (G_legal_filename(result_and) < 0) /* check for legal database file names */
- G_fatal_error(_("<%s> is an illegal file name"), result_and);
- if (G_legal_filename(result_or) < 0) /* check for legal database file names */
- G_fatal_error(_("<%s> is an illegal file name"), result_or);
+ if (G_legal_filename(result_and) < 0) /* check for legal database file names */
+ G_fatal_error(_("<%s> is an illegal file name"), result_and);
- if (G_legal_filename(result_owa) < 0) /* check for legal database file names */
- G_fatal_error(_("<%s> is an illegal file name"), result_owa);
+ if (G_legal_filename(result_or) < 0) /* check for legal database file names */
+ G_fatal_error(_("<%s> is an illegal file name"), result_or);
- /*values = G_malloc(ncriteria * sizeof(DCELL));*/
+ if (G_legal_filename(result_owa) < 0) /* check for legal database file names */
+ G_fatal_error(_("<%s> is an illegal file name"), result_owa);
- nrows = G_window_rows();
+ /*values = G_malloc(ncriteria * sizeof(DCELL)); */
+
+ nrows = G_window_rows();
ncols = G_window_cols();
- /*memory allocation for-three dimensional matrix*/
- decision_vol=G_malloc(nrows * sizeof(double*));
- for (i=0; i<nrows; ++i)
- {
- decision_vol[i]=G_malloc(ncols * sizeof(double*));
- for (j=0; j<ncols; ++j)
- {
- decision_vol[i][j]=G_malloc((ncriteria+3) * sizeof(double)); /****NOTE: it's storage enven and, or, owa map*/
- }
- }
+ /*memory allocation for-three dimensional matrix */
+ decision_vol = G_malloc(nrows * sizeof(double *));
+ for (i = 0; i < nrows; ++i) {
+ decision_vol[i] = G_malloc(ncols * sizeof(double *));
+ for (j = 0; j < ncols; ++j) {
+ decision_vol[i][j] = G_malloc((ncriteria + 3) * sizeof(double)); /****NOTE: it's storage enven and, or, owa map*/
+ }
+ }
+
/* Allocate output buffer, use DCELL_TYPE */
- outrast_and = G_allocate_raster_buf(DCELL_TYPE); /* Allocate memory for a raster map of type DCELL_TYPE. */
- outrast_or = G_allocate_raster_buf(DCELL_TYPE);
- outrast_owa = G_allocate_raster_buf(DCELL_TYPE);
+ outrast_and = G_allocate_raster_buf(DCELL_TYPE); /* Allocate memory for a raster map of type DCELL_TYPE. */
+ outrast_or = G_allocate_raster_buf(DCELL_TYPE);
+ outrast_owa = G_allocate_raster_buf(DCELL_TYPE);
/* controlling, if we can write the raster */
if ((outfd_and = G_open_raster_new(result_and, DCELL_TYPE)) < 0)
- G_fatal_error(_("Unable to create raster map <%s>"), result_and);
+ G_fatal_error(_("Unable to create raster map <%s>"), result_and);
- if ((outfd_or = G_open_raster_new(result_or, DCELL_TYPE)) < 0)
- G_fatal_error(_("Unable to create raster map <%s>"), result_or);
+ if ((outfd_or = G_open_raster_new(result_or, DCELL_TYPE)) < 0)
+ G_fatal_error(_("Unable to create raster map <%s>"), result_or);
- if ((outfd_owa = G_open_raster_new(result_owa, DCELL_TYPE)) < 0)
- G_fatal_error(_("Unable to create raster map <%s>"), result_owa);
+ if ((outfd_owa = G_open_raster_new(result_owa, DCELL_TYPE)) < 0)
+ G_fatal_error(_("Unable to create raster map <%s>"), result_owa);
- /*build a three dimensional matrix for storage all critera maps*/
- for(i=0;i<ncriteria;i++)
- {
- for (row1 = 0; row1 < nrows;row1++)
- {
- G_get_raster_row(attributes[i].infd, attributes[i].inrast, row1,DCELL_TYPE);/* Reads appropriate information into the buffer buf associated with the requested row*/
- /*G_fatal_error(_("Unable to read raster map <%s> row %d"), criteria->answers[i], row);*/
- for (col1 = 0; col1 < ncols; col1++)
- {
- /* viene letto il valore di cella e lo si attribuisce ad una variabile di tipo DCELL e poi ad un array*/
- DCELL v1 = ((DCELL *)attributes[i].inrast)[col1];
- decision_vol[row1][col1][i]=(double)(v1);
- }
- }
- }
- build_fuzzy_matrix(nrows,ncols,ncriteria,weight_vect,decision_vol); /*scan all DCELL, make a pairwise comparatione, buil concordance and discordance matrix and relative index*/
+ /*build a three dimensional matrix for storage all critera maps */
+ for (i = 0; i < ncriteria; i++) {
+ for (row1 = 0; row1 < nrows; row1++) {
+ G_get_raster_row(attributes[i].infd, attributes[i].inrast, row1, DCELL_TYPE); /* Reads appropriate information into the buffer buf associated with the requested row */
+ /*G_fatal_error(_("Unable to read raster map <%s> row %d"), criteria->answers[i], row); */
+ for (col1 = 0; col1 < ncols; col1++) {
+ /* viene letto il valore di cella e lo si attribuisce ad una variabile di tipo DCELL e poi ad un array */
+ DCELL v1 = ((DCELL *) attributes[i].inrast)[col1];
- for(row1 = 0; row1 < nrows; row1++)
- {
- G_percent(row1, nrows, 2);
- for (col1 = 0; col1 < ncols; col1++)
- {
- ((DCELL *) outrast_and)[col1] = (DCELL)decision_vol[row1][col1][ncriteria];
- ((DCELL *) outrast_or)[col1] = (DCELL)decision_vol[row1][col1][ncriteria+1];
- ((DCELL *) outrast_owa)[col1] = (DCELL)decision_vol[row1][col1][ncriteria+2];
- }
+ decision_vol[row1][col1][i] = (double)(v1);
+ }
+ }
+ }
+ build_fuzzy_matrix(nrows, ncols, ncriteria, weight_vect, decision_vol); /*scan all DCELL, make a pairwise comparatione, buil concordance and discordance matrix and relative index */
- if (G_put_raster_row(outfd_and, outrast_and, DCELL_TYPE) < 0)
- G_fatal_error(_("Failed writing raster map <%s>"), result_and);
+ for (row1 = 0; row1 < nrows; row1++) {
+ G_percent(row1, nrows, 2);
+ for (col1 = 0; col1 < ncols; col1++) {
+ ((DCELL *) outrast_and)[col1] =
+ (DCELL) decision_vol[row1][col1][ncriteria];
+ ((DCELL *) outrast_or)[col1] =
+ (DCELL) decision_vol[row1][col1][ncriteria + 1];
+ ((DCELL *) outrast_owa)[col1] =
+ (DCELL) decision_vol[row1][col1][ncriteria + 2];
+ }
- if (G_put_raster_row(outfd_or, outrast_or, DCELL_TYPE) < 0)
- G_fatal_error(_("Failed writing raster map <%s>"), result_or);
+ if (G_put_raster_row(outfd_and, outrast_and, DCELL_TYPE) < 0)
+ G_fatal_error(_("Failed writing raster map <%s>"), result_and);
- if (G_put_raster_row(outfd_owa, outrast_owa, DCELL_TYPE) < 0)
- G_fatal_error(_("Failed writing raster map <%s>"), result_owa);
- }
+ if (G_put_raster_row(outfd_or, outrast_or, DCELL_TYPE) < 0)
+ G_fatal_error(_("Failed writing raster map <%s>"), result_or);
+ if (G_put_raster_row(outfd_owa, outrast_owa, DCELL_TYPE) < 0)
+ G_fatal_error(_("Failed writing raster map <%s>"), result_owa);
+ }
- G_message("end: %s, by!",G_date());
+ G_message("end: %s, by!", G_date());
+
/* memory cleanup */
- for (i = 0; i<ncriteria; i++)
- G_free(attributes[i].inrast);
+ for (i = 0; i < ncriteria; i++)
+ G_free(attributes[i].inrast);
G_free(outrast_and);
- G_free(outrast_or);
- G_free(outrast_owa);
+ G_free(outrast_or);
+ G_free(outrast_owa);
- G_free(decision_vol);
+ G_free(decision_vol);
/* closing raster maps */
- for (i = 0; i<ncriteria; i++)
- G_close_cell(attributes[i].infd);
+ for (i = 0; i < ncriteria; i++)
+ G_close_cell(attributes[i].infd);
G_close_cell(outfd_and);
- G_close_cell(outfd_or);
- G_close_cell(outfd_owa);
+ G_close_cell(outfd_or);
+ G_close_cell(outfd_owa);
/* add command line incantation to history AND file */
G_short_history(result_and, "raster", &history);
@@ -252,5 +252,3 @@
exit(EXIT_SUCCESS);
}
-
-
Modified: grass-addons/raster/mcda/r.mcda.regime/local_proto.h
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/local_proto.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.mcda.regime/local_proto.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -9,7 +9,7 @@
struct input
{
- char *name, *mapset; /* input raster name and mapset name*/
- int infd;
- void *inrast; /* input buffer */
+ char *name, *mapset; /* input raster name and mapset name */
+ int infd;
+ void *inrast; /* input buffer */
};
Modified: grass-addons/raster/mcda/r.mcda.regime/main.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/main.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.mcda.regime/main.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.mcda.electre
@@ -23,15 +24,15 @@
int main(int argc, char *argv[])
{
struct Cell_head cellhd; /* it stores region information, and header information of rasters */
- char *result_preference; /* outputs raster name */
+ char *result_preference; /* outputs raster name */
char *mapset; /* mapset name */
unsigned char *outrast_preference; /* output buffer */
char *message;
- int i,j, ncriteria=0; /* index and files number*/
+ int i, j, ncriteria = 0; /* index and files number */
int nrows, ncols;
int row1, row2, col1, col2;
- int outfd_preference; /* output file descriptor */
- double *weight_vect, ***decision_vol;
+ int outfd_preference; /* output file descriptor */
+ double *weight_vect, ***decision_vol;
struct History history; /* holds meta-data (title, comments,..) */
@@ -40,7 +41,7 @@
struct Option *criteria, *weight, *preference; /* options */
- struct input *attributes; /*storage alla input criteria GRID files and output concordance and discordance GRID files*/
+ struct input *attributes; /*storage alla input criteria GRID files and output concordance and discordance GRID files */
/* initialize GIS environment */
@@ -49,30 +50,32 @@
/* initialize module */
module = G_define_module();
module->keywords = _("raster,MCDA");
- module->description = _("Multicirtieria decision analysis based on REGIME method");
+ module->description =
+ _("Multicirtieria decision analysis based on REGIME method");
/* Define the different options as defined in gis.h */
- criteria = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory*/
- criteria->key = "criteria";
- criteria->type = TYPE_STRING;
- criteria->required = YES;
- criteria->multiple = YES;
- criteria->gisprompt = "old,cell,raster" ;
- criteria->description = "Input geographics criteria in information system";
+ criteria = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ criteria->key = "criteria";
+ criteria->type = TYPE_STRING;
+ criteria->required = YES;
+ criteria->multiple = YES;
+ criteria->gisprompt = "old,cell,raster";
+ criteria->description =
+ "Input geographics criteria in information system";
- weight = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory*/
- weight->key = "weight";
- weight->type = TYPE_DOUBLE;
- weight->required = YES;
- weight->multiple = YES;
+ weight = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ weight->key = "weight";
+ weight->type = TYPE_DOUBLE;
+ weight->required = YES;
+ weight->multiple = YES;
weight->description = _("Criteria weight(s) (w1,w2,..)");
- preference = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
- preference->key = "preference";
+ preference = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ preference->key = "preference";
preference->type = TYPE_STRING;
preference->required = YES;
preference->gisprompt = "new,cell,raster";
- preference->answer ="regime_map";
+ preference->answer = "regime_map";
preference->description = "regime preference output map";
@@ -81,115 +84,113 @@
exit(EXIT_FAILURE);
- G_message("start: %s",G_date()); /*write calculation start time*/
+ G_message("start: %s", G_date()); /*write calculation start time */
- /* number of file (=criteria) */
- while (criteria->answers[ncriteria]!=NULL)
- {
- ncriteria++;
- }
+ /* number of file (=criteria) */
+ while (criteria->answers[ncriteria] != NULL) {
+ ncriteria++;
+ }
- /* process the input maps: stores options and flags to variables */
+ /* process the input maps: stores options and flags to variables */
/* CRITERIA grid */
- attributes = G_malloc(ncriteria * sizeof(struct input)); /*attributes is input struct defined in top file and store alla criteria files*/
- weight_vect=G_malloc(ncriteria * sizeof(double)); /*allocate memory fron vector weight*/
+ attributes = G_malloc(ncriteria * sizeof(struct input)); /*attributes is input struct defined in top file and store alla criteria files */
+ weight_vect = G_malloc(ncriteria * sizeof(double)); /*allocate memory fron vector weight */
- build_weight_vect(nrows,ncols,ncriteria,weight,weight_vect); /*calcolate weight vector*/
+ build_weight_vect(nrows, ncols, ncriteria, weight, weight_vect); /*calcolate weight vector */
- for (i = 0; i < ncriteria; i++)
- {
- struct input *p = &attributes[i];
- p->name = criteria->answers[i];
- p->mapset = G_find_cell2(p->name,""); /* G_find_cell: Looks for the raster map "name" in the database. */
- if (p->mapset==NULL) /* returns NULL if the map was not found in any mapset, mapset name otherwise */
- G_fatal_error(_("Raster file <%s> not found"), p->name);
+ for (i = 0; i < ncriteria; i++) {
+ struct input *p = &attributes[i];
- if((p->infd = G_open_cell_old(p->name, p->mapset))<0) /* G_open_cell_old - returns file destriptor (>0) */
- G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),p->name, p->mapset);
+ p->name = criteria->answers[i];
+ p->mapset = G_find_cell2(p->name, ""); /* G_find_cell: Looks for the raster map "name" in the database. */
+ if (p->mapset == NULL) /* returns NULL if the map was not found in any mapset, mapset name otherwise */
+ G_fatal_error(_("Raster file <%s> not found"), p->name);
- if(G_get_cellhd(p->name,p->mapset,&cellhd)<0)/* controlling, if we can open input raster */
- G_fatal_error(_("Unable to read file header of <%s>"), p->name);
+ if ((p->infd = G_open_cell_old(p->name, p->mapset)) < 0) /* G_open_cell_old - returns file destriptor (>0) */
+ G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
+ p->name, p->mapset);
- p->inrast = G_allocate_d_raster_buf(); /* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL*/
- }
+ if (G_get_cellhd(p->name, p->mapset, &cellhd) < 0) /* controlling, if we can open input raster */
+ G_fatal_error(_("Unable to read file header of <%s>"), p->name);
- result_preference=preference->answer; /* store outputn name in variables*/
+ p->inrast = G_allocate_d_raster_buf(); /* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL */
+ }
+ result_preference = preference->answer; /* store outputn name in variables */
- if (G_legal_filename(result_preference) < 0) /* check for legal database file names */
- G_fatal_error(_("<%s> is an illegal file name"), result_preference);
- /*values = G_malloc(ncriteria * sizeof(DCELL));*/
+ if (G_legal_filename(result_preference) < 0) /* check for legal database file names */
+ G_fatal_error(_("<%s> is an illegal file name"), result_preference);
- nrows = G_window_rows();
+ /*values = G_malloc(ncriteria * sizeof(DCELL)); */
+
+ nrows = G_window_rows();
ncols = G_window_cols();
- /*memory allocation for-three dimensional matrix*/
- decision_vol=G_malloc(nrows * sizeof(double*));
- for (i=0; i<nrows; ++i)
- {
- decision_vol[i]=G_malloc(ncols * sizeof(double*));
- for (j=0; j<ncols; ++j)
- {
- decision_vol[i][j]=G_malloc((ncriteria+1) * sizeof(double)); /*NOTE: it's storage enven preference regime index map*/
- }
- }
+ /*memory allocation for-three dimensional matrix */
+ decision_vol = G_malloc(nrows * sizeof(double *));
+ for (i = 0; i < nrows; ++i) {
+ decision_vol[i] = G_malloc(ncols * sizeof(double *));
+ for (j = 0; j < ncols; ++j) {
+ decision_vol[i][j] = G_malloc((ncriteria + 1) * sizeof(double)); /*NOTE: it's storage enven preference regime index map */
+ }
+ }
/* Allocate output buffer, use DCELL_TYPE */
- outrast_preference = G_allocate_raster_buf(DCELL_TYPE); /* Allocate memory for a raster map of type DCELL_TYPE. */
+ outrast_preference = G_allocate_raster_buf(DCELL_TYPE); /* Allocate memory for a raster map of type DCELL_TYPE. */
/* controlling, if we can write the raster */
- if ((outfd_preference = G_open_raster_new(result_preference, DCELL_TYPE)) < 0)
- G_fatal_error(_("Unable to create raster map <%s>"), result_preference);
+ if ((outfd_preference =
+ G_open_raster_new(result_preference, DCELL_TYPE)) < 0)
+ G_fatal_error(_("Unable to create raster map <%s>"),
+ result_preference);
- /*build a three dimensional matrix for storage all critera maps*/
- for(i=0;i<ncriteria;i++)
- {
- for (row1 = 0; row1 < nrows; row1++)
- {
- G_get_raster_row(attributes[i].infd, attributes[i].inrast, row1,DCELL_TYPE);/* Reads appropriate information into the buffer buf associated with the requested row*/
- /*G_fatal_error(_("Unable to read raster map <%s> row %d"), criteria->answers[i], row);*/
- for (col1 = 0; col1 < ncols; col1++)
- {
- /* viene letto il valore di cella e lo si attribuisce ad una variabile di tipo DCELL e poi ad un array*/
- DCELL v1 = ((DCELL *)attributes[i].inrast)[col1];
- decision_vol[row1][col1][i]=(double)(v1);
- }
- }
- }
+ /*build a three dimensional matrix for storage all critera maps */
+ for (i = 0; i < ncriteria; i++) {
+ for (row1 = 0; row1 < nrows; row1++) {
+ G_get_raster_row(attributes[i].infd, attributes[i].inrast, row1, DCELL_TYPE); /* Reads appropriate information into the buffer buf associated with the requested row */
+ /*G_fatal_error(_("Unable to read raster map <%s> row %d"), criteria->answers[i], row); */
+ for (col1 = 0; col1 < ncols; col1++) {
+ /* viene letto il valore di cella e lo si attribuisce ad una variabile di tipo DCELL e poi ad un array */
+ DCELL v1 = ((DCELL *) attributes[i].inrast)[col1];
- G_message("build matrix: %s",G_date());
+ decision_vol[row1][col1][i] = (double)(v1);
+ }
+ }
+ }
- build_regime_matrix(nrows,ncols,ncriteria,weight_vect,decision_vol); /*scan all DCELL, make a pairwise comparatione, buil regime index matrix */
+ G_message("build matrix: %s", G_date());
+ build_regime_matrix(nrows, ncols, ncriteria, weight_vect, decision_vol); /*scan all DCELL, make a pairwise comparatione, buil regime index matrix */
- for(row1 = 0; row1 < nrows; row1++)
- {
- for (col1 = 0; col1 < ncols; col1++)
- {
- ((DCELL *) outrast_preference)[col1] = (DCELL)decision_vol[row1][col1][ncriteria];/*write concordance map*/
- }
- if (G_put_raster_row(outfd_preference, outrast_preference, DCELL_TYPE) < 0)
- G_fatal_error(_("Failed writing raster map <%s>"), result_preference);
- }
- G_message("end: %s",G_date());
+ for (row1 = 0; row1 < nrows; row1++) {
+ for (col1 = 0; col1 < ncols; col1++) {
+ ((DCELL *) outrast_preference)[col1] = (DCELL) decision_vol[row1][col1][ncriteria]; /*write concordance map */
+ }
+ if (G_put_raster_row(outfd_preference, outrast_preference, DCELL_TYPE)
+ < 0)
+ G_fatal_error(_("Failed writing raster map <%s>"),
+ result_preference);
+ }
+ G_message("end: %s", G_date());
+
/* memory cleanup */
- for (i = 0; i<ncriteria; i++)
- G_free(attributes[i].inrast);
+ for (i = 0; i < ncriteria; i++)
+ G_free(attributes[i].inrast);
G_free(outrast_preference);
- G_free(decision_vol);
+ G_free(decision_vol);
/* closing raster maps */
- for (i = 0; i<ncriteria; i++)
- G_close_cell(attributes[i].infd);
+ for (i = 0; i < ncriteria; i++)
+ G_close_cell(attributes[i].infd);
G_close_cell(outfd_preference);
@@ -200,5 +201,3 @@
exit(EXIT_SUCCESS);
}
-
-
Modified: grass-addons/raster/mcda/r.mcda.regime/regime.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/regime.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.mcda.regime/regime.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -4,89 +4,85 @@
* global function declaration
*/
-void build_weight_vect(int nrows, int ncols, int ncriteria, struct Option *weight, double *weight_vect);
+void build_weight_vect(int nrows, int ncols, int ncriteria,
+ struct Option *weight, double *weight_vect);
-void build_regime_matrix(int nrows, int ncols, int ncriteria, double *weight_vect, double ***decision_vol);
+void build_regime_matrix(int nrows, int ncols, int ncriteria,
+ double *weight_vect, double ***decision_vol);
/*
* function definitions
*/
-void build_weight_vect(int nrows, int ncols, int ncriteria,struct Option *weight, double *weight_vect)
+void build_weight_vect(int nrows, int ncols, int ncriteria,
+ struct Option *weight, double *weight_vect)
{
-
- int i,nweight=0;
- double weight_sum=0;
-
- while (weight->answers[nweight]!=NULL)
- {
- nweight++;
- }
-
- if(nweight!=ncriteria)
- G_fatal_error(_("criteria number and weight number are different"));
-
- for(i=0;i<nweight;i++)
- {
- weight_vect[i]=(atof(weight->answers[i])); /*transfer weight value in double array*/
- weight_sum=weight_sum+weight_vect[i]; /*calculate sum weight*/
- }
-
- for(i=0;i<nweight;i++)
- {
- weight_vect[i]=weight_vect[i]/weight_sum; /*normalize vector weight*/
+ int i, nweight = 0;
+ double weight_sum = 0;
- }
+ while (weight->answers[nweight] != NULL) {
+ nweight++;
+ }
+ if (nweight != ncriteria)
+ G_fatal_error(_("criteria number and weight number are different"));
+
+
+ for (i = 0; i < nweight; i++) {
+ weight_vect[i] = (atof(weight->answers[i])); /*transfer weight value in double array */
+ weight_sum = weight_sum + weight_vect[i]; /*calculate sum weight */
+ }
+
+ for (i = 0; i < nweight; i++) {
+ weight_vect[i] = weight_vect[i] / weight_sum; /*normalize vector weight */
+
+ }
+
}
-void build_regime_matrix(int nrows, int ncols, int ncriteria, double *weight_vect, double ***decision_vol)
-{
- int row1,col1,row2,col2;
- int i,j,k,cont;
- double *row_sum_regime = G_alloc_vector(nrows * ncols);
-
- j=0; /* make pairwise comparation and built regime matrix*/
- for (row1 = 0; row1 < nrows; row1++)
- {
- for (col1 = 0; col1 < ncols; col1++)
- {
- for (row2 = 0; row2 < nrows; row2++)
- {
- for (col2 = 0; col2 < ncols; col2++)
- {
- double reg = 0;
- for(i=0;i<ncriteria;i++)
- {
- double d=decision_vol[row1][col1][i]-decision_vol[row2][col2][i];
- if(d>0)
- reg += (1*weight_vect[i]);
- else if(d<0)
- reg += (-1*weight_vect[i]);
- else
- reg += 0;
- }
- row_sum_regime[j] += reg;
- }
- }
- j++;/* increase rows index up to nrows*ncols*/
- }
- G_percent(row1, nrows, 1);
- }
+void build_regime_matrix(int nrows, int ncols, int ncriteria,
+ double *weight_vect, double ***decision_vol)
+{
+ int row1, col1, row2, col2;
+ int i, j, k, cont;
+ double *row_sum_regime = G_alloc_vector(nrows * ncols);
- /*calculate concordance and discordance index and storage in decision_vol*/
- cont=0;
- for(row1=0;row1<nrows;row1++)
- {
- for(col1=0;col1<ncols;col1++)
- {
- decision_vol[row1][col1][ncriteria]=row_sum_regime[cont]/(nrows*ncols-1);/*fill matrix with regime index for each DCELL*/
- cont++;
- }
- G_percent(row1, nrows, 2);
+ j = 0; /* make pairwise comparation and built regime matrix */
+ for (row1 = 0; row1 < nrows; row1++) {
+ for (col1 = 0; col1 < ncols; col1++) {
+ for (row2 = 0; row2 < nrows; row2++) {
+ for (col2 = 0; col2 < ncols; col2++) {
+ double reg = 0;
+
+ for (i = 0; i < ncriteria; i++) {
+ double d =
+ decision_vol[row1][col1][i] -
+ decision_vol[row2][col2][i];
+ if (d > 0)
+ reg += (1 * weight_vect[i]);
+ else if (d < 0)
+ reg += (-1 * weight_vect[i]);
+ else
+ reg += 0;
+ }
+ row_sum_regime[j] += reg;
}
-}
+ }
+ j++; /* increase rows index up to nrows*ncols */
+ }
+ G_percent(row1, nrows, 1);
+ }
+ /*calculate concordance and discordance index and storage in decision_vol */
+ cont = 0;
+ for (row1 = 0; row1 < nrows; row1++) {
+ for (col1 = 0; col1 < ncols; col1++) {
+ decision_vol[row1][col1][ncriteria] = row_sum_regime[cont] / (nrows * ncols - 1); /*fill matrix with regime index for each DCELL */
+ cont++;
+ }
+ G_percent(row1, nrows, 2);
+ }
+}
Modified: grass-addons/raster/mcda/r.roughset/localproto.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/localproto.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/localproto.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -9,12 +9,7 @@
struct input
{
- char *name, *mapset;
- int fd;
- CELL *buf;
+ char *name, *mapset;
+ int fd;
+ CELL *buf;
};
-
-
-
-
-
Modified: grass-addons/raster/mcda/r.roughset/main.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/main.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/main.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -21,29 +22,31 @@
int main(int argc, char *argv[])
{
- struct Cell_head cellhd; /* it stores region information, and header of rasters */
- char *mapset; /* mapset name */
- int i,j; /* index and files number*/
- int row,col,nrows, ncols;
- int nattributes; /*attributes numer*/
- int strgy, cls; /* strategy rules extraction and classifiy index*/
-
- char *result; /* output raster name */
- int *classify_vect; /* matrix for classified value storage*/
- int outfd; /* output file descriptor */
- unsigned char *outrast; /* output buffer */
-
+ struct Cell_head cellhd; /* it stores region information, and header of rasters */
+ char *mapset; /* mapset name */
+ int i, j; /* index and files number */
+ int row, col, nrows, ncols;
+ int nattributes; /*attributes numer */
+ int strgy, cls; /* strategy rules extraction and classifiy index */
+
+ char *result; /* output raster name */
+ int *classify_vect; /* matrix for classified value storage */
+ int outfd; /* output file descriptor */
+ unsigned char *outrast; /* output buffer */
+
RASTER_MAP_TYPE data_type; /* type of the map (CELL/DCELL/...) */
- /*int value, decvalue;*/ /*single attribute and decision value*/
+ /*int value, decvalue; *//*single attribute and decision value */
+
struct input *attributes;
struct History history; /* holds meta-data (title, comments,..) */
struct GModule *module; /* GRASS module for parsing arguments */
struct Option *attr_map, *dec_map, *dec_txt, *genrules, *clssfy, *output_txt, *output_map; /* options */
- /*struct Flag *flagQuiet flags */
+ /*struct Flag *flagQuiet flags */
+
/* initialize GIS environment */
G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */
@@ -54,209 +57,214 @@
/* Define the different options as defined in gis.h */
- attr_map = G_define_option() ; /* Allocates memory for the Option structure and returns a pointer to this memory */
- attr_map->key = "attributes";
- attr_map->type = TYPE_STRING;
- attr_map->required = YES;
- attr_map->multiple = YES;
- attr_map->gisprompt = "old,cell,raster" ;
- attr_map->description = _("Input geographics ATTRIBUTES in information system");
-
- dec_map = G_define_option() ;
- dec_map->key = "decision";
- dec_map->type = TYPE_STRING;
- dec_map->required = NO;
- dec_map->gisprompt = "old,cell,raster" ;
- dec_map->description = _("Input geographics DECISION in information system");
+ attr_map = G_define_option(); /* Allocates memory for the Option structure and returns a pointer to this memory */
+ attr_map->key = "attributes";
+ attr_map->type = TYPE_STRING;
+ attr_map->required = YES;
+ attr_map->multiple = YES;
+ attr_map->gisprompt = "old,cell,raster";
+ attr_map->description =
+ _("Input geographics ATTRIBUTES in information system");
- genrules = G_define_option() ;
- genrules->key = "strgy";
- genrules->type = TYPE_STRING;
- genrules->required = YES;
- genrules->options = "Very fast,Fast,Medium,Best,All,Low,Upp,Normal";
- genrules->answer = "Very fast";
+ dec_map = G_define_option();
+ dec_map->key = "decision";
+ dec_map->type = TYPE_STRING;
+ dec_map->required = NO;
+ dec_map->gisprompt = "old,cell,raster";
+ dec_map->description =
+ _("Input geographics DECISION in information system");
+
+ genrules = G_define_option();
+ genrules->key = "strgy";
+ genrules->type = TYPE_STRING;
+ genrules->required = YES;
+ genrules->options = "Very fast,Fast,Medium,Best,All,Low,Upp,Normal";
+ genrules->answer = "Very fast";
genrules->description = _("Strategies for generating rules");
-
- dec_txt = G_define_option();
- dec_txt->key = "sample";
- dec_txt->type = TYPE_STRING;
- dec_txt->required = NO;
- dec_txt->gisprompt = "old_file,file,input";
- dec_txt->description = _("Input text file with data and decision sample");
-
- clssfy = G_define_option() ;
- clssfy->key = "clssfy";
- clssfy->type = TYPE_STRING;
- clssfy->required = YES;
- clssfy->options = "Classify1,Classify2,Classify3";
- clssfy->answer ="Classify1";
- clssfy->description = _("Strategies for classified map (conflict resolution)");
-
+
+ dec_txt = G_define_option();
+ dec_txt->key = "sample";
+ dec_txt->type = TYPE_STRING;
+ dec_txt->required = NO;
+ dec_txt->gisprompt = "old_file,file,input";
+ dec_txt->description =
+ _("Input text file with data and decision sample");
+
+ clssfy = G_define_option();
+ clssfy->key = "clssfy";
+ clssfy->type = TYPE_STRING;
+ clssfy->required = YES;
+ clssfy->options = "Classify1,Classify2,Classify3";
+ clssfy->answer = "Classify1";
+ clssfy->description =
+ _("Strategies for classified map (conflict resolution)");
+
output_txt = G_define_option();
output_txt->key = "outTXT";
output_txt->type = TYPE_STRING;
output_txt->required = YES;
- // output_txt->gisprompt = "new_file,file,output";
- output_txt->answer ="InfoSys";
+ // output_txt->gisprompt = "new_file,file,output";
+ output_txt->answer = "InfoSys";
output_txt->description = _("Output information system file");
- output_map = G_define_option();
- output_map->key = "outMAP";
+ output_map = G_define_option();
+ output_map->key = "outMAP";
output_map->type = TYPE_STRING;
output_map->required = YES;
- output_map->answer ="classify";
+ output_map->answer = "classify";
output_map->description = _("Output classified map");
-
+
/* options and flags parser */
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
- /* Either decision map or sample file are necesary*/
- if (dec_map->answer==NULL && dec_txt->answer==NULL)
- G_fatal_error(_("Either decision map or sample file are necessary!"));
+ /* Either decision map or sample file are necesary */
+ if (dec_map->answer == NULL && dec_txt->answer == NULL)
+ G_fatal_error(_("Either decision map or sample file are necessary!"));
/***********************************************************************/
+
/********Prepare and controlling Information System files **************/
+
/***********************************************************************/
- /* number of file (=attributes) */
- nattributes=0;
- while (attr_map->answers[nattributes]!=NULL)
- {
- nattributes++;
- }
+ /* number of file (=attributes) */
+ nattributes = 0;
+ while (attr_map->answers[nattributes] != NULL) {
+ nattributes++;
+ }
-/* store output classified MAP name in variable*/
- result=output_map->answer;
+ /* store output classified MAP name in variable */
+ result = output_map->answer;
-/*Convert strategy rules extraction answer in index. strcmp return 0 if answer is the passed string*/
- if(strcmp(genrules->answer,"Very fast")==0)
- strgy=0;
- else if(strcmp(genrules->answer,"Fast")==0)
- strgy=1;
- else if(strcmp(genrules->answer,"Medium")==0)
- strgy=2;
- else if(strcmp(genrules->answer,"Best")==0)
- strgy=3;
- else if(strcmp(genrules->answer,"All")==0)
- strgy=4;
- else if(strcmp(genrules->answer,"Low")==0)
- strgy=5;
- else if(strcmp(genrules->answer,"Upp")==0)
- strgy=6;
+ /*Convert strategy rules extraction answer in index. strcmp return 0 if answer is the passed string */
+ if (strcmp(genrules->answer, "Very fast") == 0)
+ strgy = 0;
+ else if (strcmp(genrules->answer, "Fast") == 0)
+ strgy = 1;
+ else if (strcmp(genrules->answer, "Medium") == 0)
+ strgy = 2;
+ else if (strcmp(genrules->answer, "Best") == 0)
+ strgy = 3;
+ else if (strcmp(genrules->answer, "All") == 0)
+ strgy = 4;
+ else if (strcmp(genrules->answer, "Low") == 0)
+ strgy = 5;
+ else if (strcmp(genrules->answer, "Upp") == 0)
+ strgy = 6;
else
- strgy=7;
+ strgy = 7;
- /*Convert strategy map lassify answer in index. strcmp return 0 if answer is the passed string*/
+ /*Convert strategy map lassify answer in index. strcmp return 0 if answer is the passed string */
- if(strcmp(clssfy->answer,"Classify1")==0)
- cls=0;
- else if(strcmp(clssfy->answer,"Classify2")==0)
- cls=1;
- else if(strcmp(clssfy->answer,"Classify3")==0)
- cls=2;
- else
- cls=0;
+ if (strcmp(clssfy->answer, "Classify1") == 0)
+ cls = 0;
+ else if (strcmp(clssfy->answer, "Classify2") == 0)
+ cls = 1;
+ else if (strcmp(clssfy->answer, "Classify3") == 0)
+ cls = 2;
+ else
+ cls = 0;
- /* process the input maps:*/
+ /* process the input maps: */
/* ATTRIBUTES grid */
- attributes = G_malloc((nattributes+1) * sizeof(struct input)); /*attributes is input struct defined in localproto.h*/
+ attributes = G_malloc((nattributes + 1) * sizeof(struct input)); /*attributes is input struct defined in localproto.h */
- for (i = 0; i < nattributes; i++)
- {
- struct input *p = &attributes[i];
- p->name = attr_map->answers[i];
- p->mapset = G_find_cell(p->name,""); /* G_find_cell: Looks for the raster map "name" in the database. */
-
- p->fd = G_open_cell_old(p->name, p->mapset);
-
- if (!p->mapset)
- G_fatal_error(_("Raster file <%s> not found"), p->name);
-
- if (p->fd < 0)
- G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),p->name, p->mapset);
-
- if (CELL_TYPE!=G_raster_map_type(p->name, p->mapset))
- G_fatal_error(_("Input map <%s> in mapset <%s> isn't CELL type"),p->name, p->mapset);
-
- p->buf = G_allocate_c_raster_buf(); /* Allocate an array of CELL based on the number of columns in the current region. Return DCELL * */
+ for (i = 0; i < nattributes; i++) {
+ struct input *p = &attributes[i];
- }
-
-
- /* define the inputmap DECISION type (CELL) */
- data_type = CELL_TYPE; //
- /* Allocate output buffer, use input map data_type */
- nrows = G_window_rows();
- ncols = G_window_cols();
- outrast = G_allocate_raster_buf(data_type);
-
-
- /* DECISION grid (at last column in Information System matrix) */
- if(dec_map->answer!=NULL)
- {
- struct input *p = &attributes[nattributes];
- p->name = dec_map->answer;
- p->mapset = G_find_cell(p->name,""); /* G_find_cell: Looks for the raster map "name" in the database. */
- if (!p->mapset)
- G_fatal_error(_("Raster file <%s> not found"), p->name);
- p->fd = G_open_cell_old(p->name, p->mapset);/*opens the raster file name in mapset for reading. A nonnegative file descriptor is returned if the open is successful.*/
- if (p->fd < 0)
- G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),p->name, p->mapset);
- p->buf = G_allocate_raster_buf(data_type); /* Allocate an array of DCELL based on the number of columns in the current region.
- Return DCELL * */
- rough_set_library_out(nrows, ncols, nattributes, attributes, output_txt->answer);/*build RSL standard file*/
- }
-
-
- classify_vect = G_malloc(sizeof(int) * (nrows*ncols)); /* memory allocation*/
-
- rough_analysis(nrows, ncols, output_txt->answer, classify_vect, attributes, dec_txt->answer, strgy,cls); /* extract rules from RSL and generate classified vectpr*/
-
- /* controlling, if we can write the raster */
+ p->name = attr_map->answers[i];
+ p->mapset = G_find_cell(p->name, ""); /* G_find_cell: Looks for the raster map "name" in the database. */
+
+ p->fd = G_open_cell_old(p->name, p->mapset);
+
+ if (!p->mapset)
+ G_fatal_error(_("Raster file <%s> not found"), p->name);
+
+ if (p->fd < 0)
+ G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
+ p->name, p->mapset);
+
+ if (CELL_TYPE != G_raster_map_type(p->name, p->mapset))
+ G_fatal_error(_("Input map <%s> in mapset <%s> isn't CELL type"),
+ p->name, p->mapset);
+
+ p->buf = G_allocate_c_raster_buf(); /* Allocate an array of CELL based on the number of columns in the current region. Return DCELL * */
+
+ }
+
+
+ /* define the inputmap DECISION type (CELL) */
+ data_type = CELL_TYPE; //
+ /* Allocate output buffer, use input map data_type */
+ nrows = G_window_rows();
+ ncols = G_window_cols();
+ outrast = G_allocate_raster_buf(data_type);
+
+
+ /* DECISION grid (at last column in Information System matrix) */
+ if (dec_map->answer != NULL) {
+ struct input *p = &attributes[nattributes];
+
+ p->name = dec_map->answer;
+ p->mapset = G_find_cell(p->name, ""); /* G_find_cell: Looks for the raster map "name" in the database. */
+ if (!p->mapset)
+ G_fatal_error(_("Raster file <%s> not found"), p->name);
+ p->fd = G_open_cell_old(p->name, p->mapset); /*opens the raster file name in mapset for reading. A nonnegative file descriptor is returned if the open is successful. */
+ if (p->fd < 0)
+ G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),
+ p->name, p->mapset);
+ p->buf = G_allocate_raster_buf(data_type); /* Allocate an array of DCELL based on the number of columns in the current region.
+ Return DCELL * */
+ rough_set_library_out(nrows, ncols, nattributes, attributes, output_txt->answer); /*build RSL standard file */
+ }
+
+
+ classify_vect = G_malloc(sizeof(int) * (nrows * ncols)); /* memory allocation */
+
+ rough_analysis(nrows, ncols, output_txt->answer, classify_vect, attributes, dec_txt->answer, strgy, cls); /* extract rules from RSL and generate classified vectpr */
+
+ /* controlling, if we can write the raster */
if ((outfd = G_open_raster_new(result, CELL_TYPE)) < 0)
G_fatal_error(_("Unable to create raster map <%s>"), result);
-
- /* generate classified map*/
- G_message("Building calssified map...");
- j=0; /* builder map index*/
- for(row = 0; row < nrows; row++)
- {
- CELL c;
- G_percent(row, nrows, 2);
- for (col = 0; col < ncols; col++)
- {
- c=((CELL *) classify_vect[j]);
- ((CELL *) outrast)[col] = c;
- j++;
- }
- if (G_put_raster_row(outfd, outrast, data_type) < 0)
- G_fatal_error(_("Failed writing raster map <%s>"), result);
- }
+ /* generate classified map */
+ G_message("Building calssified map...");
+ j = 0; /* builder map index */
+ for (row = 0; row < nrows; row++) {
+ CELL c;
+ G_percent(row, nrows, 2);
+ for (col = 0; col < ncols; col++) {
+ c = ((CELL *) classify_vect[j]);
+ ((CELL *) outrast)[col] = c;
+ j++;
+ }
- /* memory cleanup */
- for (i = 0; i<=nattributes; i++)
- G_close_cell(attributes[i].fd);
- G_close_cell(outfd);
-
- for (i = 0; i<nattributes; i++)
- G_free(attributes[i].buf);
-
- //G_free(outrast);
-
- G_message("End: %s, with %d cells.",G_date(),j);
- /* add command line incantation to history file */
+ if (G_put_raster_row(outfd, outrast, data_type) < 0)
+ G_fatal_error(_("Failed writing raster map <%s>"), result);
+ }
+
+
+ /* memory cleanup */
+ for (i = 0; i <= nattributes; i++)
+ G_close_cell(attributes[i].fd);
+ G_close_cell(outfd);
+
+ for (i = 0; i < nattributes; i++)
+ G_free(attributes[i].buf);
+
+ //G_free(outrast);
+
+ G_message("End: %s, with %d cells.", G_date(), j);
+ /* add command line incantation to history file */
G_short_history(result, "raster", &history);
G_command_history(&history);
G_write_history(result, &history);
-
- exit(EXIT_SUCCESS);
+
+ exit(EXIT_SUCCESS);
}
-/* dom 07 dic 2008 07:05:15 CET */
-
-
+/* dom 07 dic 2008 07:05:15 CET */
Modified: grass-addons/raster/mcda/r.roughset/raccess.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/raccess.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/raccess.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,160 +16,213 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** FUNCTION OF ACCESS TO SYSTEM TABLES ***/
+
/*** ***/
+
/*** part of the ROUGH system written by M.Gawrys J. Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
#include "rough.h"
-setA _table_element=NULL;
-setA _table_end=NULL;
-int _table_row;
-int _table_column;
-int _table_no;
+setA _table_element = NULL;
+setA _table_end = NULL;
+int _table_row;
+int _table_column;
+int _table_no;
-static void (*_current_next)(void);
+static void (*_current_next) (void);
void next_of_d(void)
-{ if (++_table_column>=_table_row)
- _table_column=0, _table_row++;
- _table_element=(_mainsys->matD)+(_mainsys->setAsize*++_table_no);
+{
+ if (++_table_column >= _table_row)
+ _table_column = 0, _table_row++;
+ _table_element = (_mainsys->matD) + (_mainsys->setAsize * ++_table_no);
}
void next_of_x(void)
-{ _table_element+=_mainsys->setAsize;
- ++_table_no;
+{
+ _table_element += _mainsys->setAsize;
+ ++_table_no;
}
void next_of_a(void)
- { ++_table_no;
- if (++_table_column>=_table_row)
- { _table_column=0;
- if (++_table_row>=_mainsys->objects_num)
- { CloseSetA(_table_element);
- _table_end=_table_element;
- _table_row=0;
- return;
- }
+{
+ ++_table_no;
+ if (++_table_column >= _table_row) {
+ _table_column = 0;
+ if (++_table_row >= _mainsys->objects_num) {
+ CloseSetA(_table_element);
+ _table_end = _table_element;
+ _table_row = 0;
+ return;
+ }
}
- GetDfromA(_table_element,_table_row,_table_column);
- return;
+ GetDfromA(_table_element, _table_row, _table_column);
+ return;
}
int start_of_tab(int matrix_type)
-{
- if (matrix_type==MATD)
- { _table_no=0;
- _table_row=1;
- _table_column=0;
- _table_element=_mainsys->matD;
- _table_end=_table_element+Dsize(_mainsys);
- _current_next=next_of_d;
- }
- else if (matrix_type==MATX)
- { START_OF_X;
- _table_no=0;
- _current_next=next_of_x;
- }
- else if (matrix_type==MATA)
- { _table_no=0;
- _table_row=0;
- _table_column=0;
- _table_element=InitEmptySetA();
- _table_end=_table_element+1;
- _current_next=next_of_a;
- next_of_a();
- }
- if (_table_element==NULL) ERROR(3)
- return(1);
+{
+ if (matrix_type == MATD) {
+ _table_no = 0;
+ _table_row = 1;
+ _table_column = 0;
+ _table_element = _mainsys->matD;
+ _table_end = _table_element + Dsize(_mainsys);
+ _current_next = next_of_d;
+ }
+ else if (matrix_type == MATX) {
+ START_OF_X;
+ _table_no = 0;
+ _current_next = next_of_x;
+ }
+ else if (matrix_type == MATA) {
+ _table_no = 0;
+ _table_row = 0;
+ _table_column = 0;
+ _table_element = InitEmptySetA();
+ _table_end = _table_element + 1;
+ _current_next = next_of_a;
+ next_of_a();
+ }
+ if (_table_element == NULL)
+ ERROR(3)
+ return (1);
}
int end_of_tab(void)
-{ return (_table_element<_table_end);
+{
+ return (_table_element < _table_end);
}
void next_of_tab(void)
-{ (*_current_next)();
+{
+ (*_current_next) ();
}
-setA GetD(int ob1,int ob2)
- { int pom;
- if(ob2>ob1) { pom=ob1; ob1=ob2; ob2=pom; }
- return (_mainsys->matD)+((ob1-1)*ob1/2+ob2)*_mainsys->setAsize;
- }
+setA GetD(int ob1, int ob2)
+{
+ int pom;
- value_type GetA(int ob,int atr)
- { return (_mainsys->matA)[ob*(_mainsys->attributes_num)+atr]; }
+ if (ob2 > ob1) {
+ pom = ob1;
+ ob1 = ob2;
+ ob2 = pom;
+ }
+ return (_mainsys->matD) + ((ob1 - 1) * ob1 / 2 +
+ ob2) * _mainsys->setAsize;
+}
-int GetDfromA(setA elem,int obj1,int obj2)
- { int nby=(_mainsys->attributes_num)/_cluster_bits; /* number of full clusters in element */
- int nbi=_mainsys->attributes_num%_cluster_bits; /* number of bits in the last cluster */
- int atrnum=_mainsys->attributes_num; /* number of attributes */
- value_type *A=_mainsys->matA;
- cluster_type val;
- int cluster,bit;
- for(cluster=0;cluster<nby;cluster++)
- { val=0;
- for(bit=0;bit<_cluster_bits;bit++)
- if(A[obj1*atrnum+_cluster_bits*cluster+bit]!=A[obj2*atrnum+_cluster_bits*cluster+bit] &&
- A[obj1*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1 &&
- A[obj2*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1 )
- val=val|_mask[bit];
- elem[cluster]=val;
+value_type GetA(int ob, int atr)
+{
+ return (_mainsys->matA)[ob * (_mainsys->attributes_num) + atr];
+}
+
+int GetDfromA(setA elem, int obj1, int obj2)
+{
+ int nby = (_mainsys->attributes_num) / _cluster_bits; /* number of full clusters in element */
+ int nbi = _mainsys->attributes_num % _cluster_bits; /* number of bits in the last cluster */
+ int atrnum = _mainsys->attributes_num; /* number of attributes */
+ value_type *A = _mainsys->matA;
+ cluster_type val;
+ int cluster, bit;
+
+ for (cluster = 0; cluster < nby; cluster++) {
+ val = 0;
+ for (bit = 0; bit < _cluster_bits; bit++)
+ if (A[obj1 * atrnum + _cluster_bits * cluster + bit] !=
+ A[obj2 * atrnum + _cluster_bits * cluster + bit] &&
+ A[obj1 * atrnum + _cluster_bits * cluster + bit] !=
+ (value_type) - 1 &&
+ A[obj2 * atrnum + _cluster_bits * cluster + bit] !=
+ (value_type) - 1)
+ val = val | _mask[bit];
+ elem[cluster] = val;
}
- if(nbi)
- { val=0;
- for(bit=0;bit<nbi;bit++)
- if(A[obj1*atrnum+_cluster_bits*cluster+bit]!=A[obj2*atrnum+_cluster_bits*cluster+bit] &&
- A[obj1*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1 &&
- A[obj2*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1 )
- val=val|_mask[bit];
- elem[cluster]=val;
- }
- return 1;
- }
-
-int CompareA(int ob1,int ob2,setA P)
- { int attr;
- for(attr=0;attr<_mainsys->attributes_num;attr++)
- if(ContSetA(P,attr))
- if((_mainsys->matA)[ob1*(_mainsys->attributes_num)+attr]==(value_type)-1 ||
- (_mainsys->matA)[ob2*(_mainsys->attributes_num)+attr]==(value_type)-1 )
- continue;
- else if((_mainsys->matA)[ob1*(_mainsys->attributes_num)+attr]!=
- (_mainsys->matA)[ob2*(_mainsys->attributes_num)+attr])
+ if (nbi) {
+ val = 0;
+ for (bit = 0; bit < nbi; bit++)
+ if (A[obj1 * atrnum + _cluster_bits * cluster + bit] !=
+ A[obj2 * atrnum + _cluster_bits * cluster + bit] &&
+ A[obj1 * atrnum + _cluster_bits * cluster + bit] !=
+ (value_type) - 1 &&
+ A[obj2 * atrnum + _cluster_bits * cluster + bit] !=
+ (value_type) - 1)
+ val = val | _mask[bit];
+ elem[cluster] = val;
+ }
+ return 1;
+}
+
+int CompareA(int ob1, int ob2, setA P)
+{
+ int attr;
+
+ for (attr = 0; attr < _mainsys->attributes_num; attr++)
+ if (ContSetA(P, attr))
+ if ((_mainsys->matA)[ob1 * (_mainsys->attributes_num) + attr] ==
+ (value_type) - 1 ||
+ (_mainsys->matA)[ob2 * (_mainsys->attributes_num) + attr] ==
+ (value_type) - 1)
+ continue;
+ else if ((_mainsys->matA)[ob1 * (_mainsys->attributes_num) +
+ attr] !=
+ (_mainsys->matA)[ob2 * (_mainsys->attributes_num) +
+ attr])
+ return 0;
+ return 1;
+}
+
+int CompareD(int ob1, int ob2, setA P)
+{
+ int pom;
+ int cluster;
+ setA elem;
+
+ if (ob2 > ob1) {
+ pom = ob1;
+ ob1 = ob2;
+ ob2 = pom;
+ }
+ elem =
+ (_mainsys->matD) + ((ob1 - 1) * ob1 / 2 + ob2) * (_mainsys->setAsize);
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+ if (elem[cluster] & P[cluster])
return 0;
- return 1;
- }
+ return 1;
+}
-int CompareD(int ob1,int ob2,setA P)
- { int pom;
- int cluster;
- setA elem;
- if(ob2>ob1) { pom=ob1; ob1=ob2; ob2=pom; }
- elem=(_mainsys->matD)+((ob1-1)*ob1/2+ob2)*(_mainsys->setAsize);
- for (cluster=_mainsys->setAsize-1;cluster>=0;cluster--)
- if (elem[cluster] & P[cluster]) return 0;
- return 1;
- }
+int SingCompA(int ob1, int ob2, int atr)
+{
+ return ((_mainsys->matA)[ob1 * (_mainsys->attributes_num) + atr] ==
+ (_mainsys->matA)[ob2 * (_mainsys->attributes_num) + atr] ||
+ (_mainsys->matA)[ob1 * (_mainsys->attributes_num) + atr] ==
+ (value_type) - 1 ||
+ (_mainsys->matA)[ob2 * (_mainsys->attributes_num) + atr] ==
+ (value_type) - 1);
+}
-int SingCompA(int ob1,int ob2,int atr)
- { return ((_mainsys->matA)[ob1*(_mainsys->attributes_num)+atr]==
- (_mainsys->matA)[ob2*(_mainsys->attributes_num)+atr] ||
- (_mainsys->matA)[ob1*(_mainsys->attributes_num)+atr]==(value_type)-1 ||
- (_mainsys->matA)[ob2*(_mainsys->attributes_num)+atr]==(value_type)-1 );
- }
+int SingCompD(int ob1, int ob2, int atr)
+{
+ int pom;
-int SingCompD(int ob1,int ob2,int atr)
- { int pom;
- if(ob2>ob1) { pom=ob1; ob1=ob2; ob2=pom; }
- return !( (_mainsys->matD)[((ob1-1)*ob1/2+ob2)
- *(_mainsys->setAsize) + atr/_cluster_bits
- ] & _mask[atr%_cluster_bits] );
- }
+ if (ob2 > ob1) {
+ pom = ob1;
+ ob1 = ob2;
+ ob2 = pom;
+ }
+ return !((_mainsys->matD)[((ob1 - 1) * ob1 / 2 + ob2)
+ * (_mainsys->setAsize) +
+ atr / _cluster_bits] & _mask[atr %
+ _cluster_bits]);
+}
Modified: grass-addons/raster/mcda/r.roughset/raccess.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/raccess.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/raccess.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,11 +16,17 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** FUNCTIONS OF ACCESS TO SYSTEM TABLES ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J. Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
@@ -31,35 +38,40 @@
#define ELEM_OF_MAT _table_element
#define ElemOfRule(rules,num,attr) (rules)[(num)*(_mainsys->attributes_num)+(attr)]
-extern setA _table_element;
-extern setA _table_end;
-extern int _table_row;
-extern int _table_column;
-extern int _table_no;
+extern setA _table_element;
+extern setA _table_end;
+extern int _table_row;
+extern int _table_column;
+extern int _table_no;
-int start_of_tab(int matrix_type);
+int start_of_tab(int matrix_type);
void next_of_tab(void);
-int end_of_tab(void);
+int end_of_tab(void);
-int CompareA(int ob1,int ob2,setA P);
-int CompareD(int ob1,int ob2,setA P);
+int CompareA(int ob1, int ob2, setA P);
+int CompareD(int ob1, int ob2, setA P);
+
/* compares two objects, returns 1 if all attributes from */
/* the set P are identical, otherwise returns 0 */
-int SingCompA(int ob1,int ob2,int atr);
-int SingCompD(int ob1,int ob2,int atr);
+int SingCompA(int ob1, int ob2, int atr);
+int SingCompD(int ob1, int ob2, int atr);
+
/* compares two objects on the sigle attribute atr */
/* returns 1 if identical, otherwise returns 0 */
-setA GetD(int ob1,int ob2);
+setA GetD(int ob1, int ob2);
+
/* returns a single element of matrix D, if this set */
/* is going to be changed, it has to be first copied */
-value_type GetA(int obj,int atr);
+value_type GetA(int obj, int atr);
+
/* returns value of attribute atr of object obj */
/* from matrix A */
-int GetDfromA(setA elem,int ob1,int ob2);
+int GetDfromA(setA elem, int ob1, int ob2);
+
/* generate a single element of matrix D into elem */
Modified: grass-addons/raster/mcda/r.roughset/rbasic.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rbasic.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rbasic.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,473 +16,592 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** BASIC QUERIES FOR ACTIVE SYSTEM ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
#include "rough.h"
-int LowAppr( setO lowappr, setO X, setA P,int matrix_type)
- { switch(matrix_type)
- { case MATA : return LowApprA(lowappr,X,P);
- case MATD : return LowApprD(lowappr,X,P);
- default : ERROR(8)
- }
- }
+int LowAppr(setO lowappr, setO X, setA P, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return LowApprA(lowappr, X, P);
+ case MATD:
+ return LowApprD(lowappr, X, P);
+ default:
+ ERROR(8)
+ }
+}
-int LowApprA( setO lowappr, setO X, setA P)
- { setO notX;
- int ob1,ob2,disc;
- if(_mainsys->matA==NULL) ERROR(5);
- notX=InitEmptySetO();
- ClearSetO(lowappr);
- NotSetO(notX,X);
- for(ob1=0;ob1<_mainsys->objects_num;ob1++)
- if(ContSetO(X,ob1))
- { disc=1;
- for(ob2=0;ob2<_mainsys->objects_num;ob2++)
- if(ContSetO(notX,ob2))
- if(CompareA(ob1,ob2,P)) {disc=0; break;}
- if(disc) AddSetO(lowappr,ob1);
- }
- CloseSetO(notX);
- return 0;
- }
+int LowApprA(setO lowappr, setO X, setA P)
+{
+ setO notX;
+ int ob1, ob2, disc;
-int LowApprD( setO lowappr, setO X, setA P)
- { setO notX;
- int ob1,ob2,disc;
- if(_mainsys->matD==NULL) ERROR(6);
- notX=InitEmptySetO();
- ClearSetO(lowappr);
- NotSetO(notX,X);
- for(ob1=0;ob1<_mainsys->objects_num;ob1++)
- if(ContSetO(X,ob1))
- { disc=1;
- for(ob2=0;ob2<_mainsys->objects_num;ob2++)
- if(ContSetO(notX,ob2))
- if(CompareD(ob1,ob2,P)) { disc=0; break; }
- if(disc) AddSetO(lowappr,ob1);
- }
- CloseSetO(notX);
- return 0;
- }
+ if (_mainsys->matA == NULL)
+ ERROR(5);
+ notX = InitEmptySetO();
+ ClearSetO(lowappr);
+ NotSetO(notX, X);
+ for (ob1 = 0; ob1 < _mainsys->objects_num; ob1++)
+ if (ContSetO(X, ob1)) {
+ disc = 1;
+ for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
+ if (ContSetO(notX, ob2))
+ if (CompareA(ob1, ob2, P)) {
+ disc = 0;
+ break;
+ }
+ if (disc)
+ AddSetO(lowappr, ob1);
+ }
+ CloseSetO(notX);
+ return 0;
+}
-int UppAppr( setO uppappr, setO X, setA P, int matrix_type)
- { switch(matrix_type)
- { case MATA : return UppApprA(uppappr,X,P);
- case MATD : return UppApprD(uppappr,X,P);
- default : ERROR(8)
- }
- }
+int LowApprD(setO lowappr, setO X, setA P)
+{
+ setO notX;
+ int ob1, ob2, disc;
-int UppApprA( setO uppappr, setO X, setA P)
- { setO notX;
- int ob1,ob2;
- if(_mainsys->matA==NULL) ERROR(5);
- CopySetO(uppappr,X);
- notX=InitEmptySetO();
- NotSetO(notX,X);
- for(ob1=0;ob1<_mainsys->objects_num;ob1++)
- if(ContSetO(X,ob1))
- for(ob2=0;ob2<_mainsys->objects_num;ob2++)
- if(ContSetO(notX,ob2))
- if(CompareA(ob1,ob2,P)) AddSetO(uppappr,ob2);
- CloseSetO(notX);
- return 0;
- }
+ if (_mainsys->matD == NULL)
+ ERROR(6);
+ notX = InitEmptySetO();
+ ClearSetO(lowappr);
+ NotSetO(notX, X);
+ for (ob1 = 0; ob1 < _mainsys->objects_num; ob1++)
+ if (ContSetO(X, ob1)) {
+ disc = 1;
+ for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
+ if (ContSetO(notX, ob2))
+ if (CompareD(ob1, ob2, P)) {
+ disc = 0;
+ break;
+ }
+ if (disc)
+ AddSetO(lowappr, ob1);
+ }
+ CloseSetO(notX);
+ return 0;
+}
-int UppApprD( setO uppappr, setO X, setA P)
- { setO notX;
- int ob1,ob2;
- if(_mainsys->matD==NULL) ERROR(6);
- CopySetO(uppappr,X);
- notX=InitEmptySetO();
- NotSetO(notX,X);
- for(ob1=0;ob1<_mainsys->objects_num;ob1++)
- if(ContSetO(X,ob1))
- for(ob2=0;ob2<_mainsys->objects_num;ob2++)
- if(ContSetO(notX,ob2))
- if(CompareD(ob1,ob2,P)) AddSetO(uppappr,ob2);
- CloseSetO(notX);
- return 0;
- }
+int UppAppr(setO uppappr, setO X, setA P, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return UppApprA(uppappr, X, P);
+ case MATD:
+ return UppApprD(uppappr, X, P);
+ default:
+ ERROR(8)
+ }
+}
-int Bound( setO bound, setO X, setA P, int matrix_type)
- { switch(matrix_type)
- { case MATA : return BoundA(bound,X,P);
- case MATD : return BoundD(bound,X,P);
- default : ERROR(8)
- }
- }
+int UppApprA(setO uppappr, setO X, setA P)
+{
+ setO notX;
+ int ob1, ob2;
-int BoundA( setO bound, setO X, setA P)
- { setO lower,upper;
- if(_mainsys->matA==NULL) ERROR(5);
- lower=InitEmptySetO();
- upper=InitEmptySetO();
- LowApprA(lower,X,P);
- UppApprA(upper,X,P);
- DifSetO(bound,upper,lower);
+ if (_mainsys->matA == NULL)
+ ERROR(5);
+ CopySetO(uppappr, X);
+ notX = InitEmptySetO();
+ NotSetO(notX, X);
+ for (ob1 = 0; ob1 < _mainsys->objects_num; ob1++)
+ if (ContSetO(X, ob1))
+ for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
+ if (ContSetO(notX, ob2))
+ if (CompareA(ob1, ob2, P))
+ AddSetO(uppappr, ob2);
+ CloseSetO(notX);
+ return 0;
+}
+
+int UppApprD(setO uppappr, setO X, setA P)
+{
+ setO notX;
+ int ob1, ob2;
+
+ if (_mainsys->matD == NULL)
+ ERROR(6);
+ CopySetO(uppappr, X);
+ notX = InitEmptySetO();
+ NotSetO(notX, X);
+ for (ob1 = 0; ob1 < _mainsys->objects_num; ob1++)
+ if (ContSetO(X, ob1))
+ for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
+ if (ContSetO(notX, ob2))
+ if (CompareD(ob1, ob2, P))
+ AddSetO(uppappr, ob2);
+ CloseSetO(notX);
+ return 0;
+}
+
+int Bound(setO bound, setO X, setA P, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return BoundA(bound, X, P);
+ case MATD:
+ return BoundD(bound, X, P);
+ default:
+ ERROR(8)
+ }
+}
+
+int BoundA(setO bound, setO X, setA P)
+{
+ setO lower, upper;
+
+ if (_mainsys->matA == NULL)
+ ERROR(5);
+ lower = InitEmptySetO();
+ upper = InitEmptySetO();
+ LowApprA(lower, X, P);
+ UppApprA(upper, X, P);
+ DifSetO(bound, upper, lower);
CloseSetO(lower);
CloseSetO(upper);
return 0;
- }
+}
-int BoundD( setO bound, setO X, setA P)
- { setO lower,upper;
- if(_mainsys->matD==NULL) ERROR(6);
- lower=InitEmptySetO();
- upper=InitEmptySetO();
- LowApprD(lower,X,P);
- UppApprD(upper,X,P);
- DifSetO(bound,upper,lower);
+int BoundD(setO bound, setO X, setA P)
+{
+ setO lower, upper;
+
+ if (_mainsys->matD == NULL)
+ ERROR(6);
+ lower = InitEmptySetO();
+ upper = InitEmptySetO();
+ LowApprD(lower, X, P);
+ UppApprD(upper, X, P);
+ DifSetO(bound, upper, lower);
CloseSetO(lower);
CloseSetO(upper);
return 0;
- }
+}
-float AccurCoef( setO X, setA P, int matrix_type)
- { switch(matrix_type)
- { case MATA : return AccurCoefA(X,P);
- case MATD : return AccurCoefD(X,P);
- default : ERROR(8)
- }
- }
+float AccurCoef(setO X, setA P, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return AccurCoefA(X, P);
+ case MATD:
+ return AccurCoefD(X, P);
+ default:
+ ERROR(8)
+ }
+}
-float AccurCoefA( setO X, setA P)
- { setO lower,upper;
- float coef;
- if(_mainsys->matA==NULL) ERROR(5);
- lower=InitEmptySetO();
- upper=InitEmptySetO();
- LowApprA(lower,X,P);
- UppApprA(upper,X,P);
- coef= (float)CardSetO(lower) / (float)CardSetO(upper);
- CloseSetO(lower);
- CloseSetO(upper);
- return coef;
- }
+float AccurCoefA(setO X, setA P)
+{
+ setO lower, upper;
+ float coef;
-float AccurCoefD( setO X, setA P)
- { setO lower,upper;
- float coef;
- if(_mainsys->matD==NULL) ERROR(6);
- lower=InitEmptySetO();
- upper=InitEmptySetO();
- LowApprD(lower,X,P);
- UppApprD(upper,X,P);
- coef= (float)CardSetO(lower) / (float)CardSetO(upper);
- CloseSetO(lower);
- CloseSetO(upper);
- return coef;
- }
+ if (_mainsys->matA == NULL)
+ ERROR(5);
+ lower = InitEmptySetO();
+ upper = InitEmptySetO();
+ LowApprA(lower, X, P);
+ UppApprA(upper, X, P);
+ coef = (float)CardSetO(lower) / (float)CardSetO(upper);
+ CloseSetO(lower);
+ CloseSetO(upper);
+ return coef;
+}
-float ClassCoef( setO X, setA P, int matrix_type)
- { switch(matrix_type)
- { case MATA : return ClassCoefA(X,P);
- case MATD : return ClassCoefD(X,P);
- default : ERROR(8)
- }
- }
+float AccurCoefD(setO X, setA P)
+{
+ setO lower, upper;
+ float coef;
-float ClassCoefA( setO X, setA P)
- { float coef;
- setO notX,pos;
- int ob1,ob2;
- if(_mainsys->matA==NULL) ERROR(5);
- notX=InitEmptySetO();
- pos=InitFullSetO();
- NotSetO(notX,X);
- for(ob1=0;ob1<_mainsys->objects_num;ob1++)
- for(ob2=0;ob2<_mainsys->objects_num;ob2++)
- if(ContSetO(X,ob1) && ContSetO(notX,ob2) && CompareA(ob1,ob2,P))
- { DelSetO(pos,ob1);
- DelSetO(pos,ob2);
- }
- coef= (float)CardSetO(pos) / _mainsys->objects_num;
- CloseSetO(notX);
- CloseSetO(pos);
- return coef;
- }
+ if (_mainsys->matD == NULL)
+ ERROR(6);
+ lower = InitEmptySetO();
+ upper = InitEmptySetO();
+ LowApprD(lower, X, P);
+ UppApprD(upper, X, P);
+ coef = (float)CardSetO(lower) / (float)CardSetO(upper);
+ CloseSetO(lower);
+ CloseSetO(upper);
+ return coef;
+}
-float ClassCoefD( setO X, setA P)
- { float coef;
- setO notX,pos;
- int ob1,ob2;
- if(_mainsys->matD==NULL) ERROR(6);
- notX=InitEmptySetO();
- pos=InitFullSetO();
- NotSetO(notX,X);
- for(ob1=0;ob1<_mainsys->objects_num;ob1++)
- for(ob2=0;ob2<_mainsys->objects_num;ob2++)
- if(ContSetO(X,ob1) && ContSetO(notX,ob2) && CompareD(ob1,ob2,P))
- { DelSetO(pos,ob1);
- DelSetO(pos,ob2);
- }
- CloseSetO(notX);
- coef= (float)CardSetO(pos) / _mainsys->objects_num;
- CloseSetO(pos);
- return coef;
- }
+float ClassCoef(setO X, setA P, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return ClassCoefA(X, P);
+ case MATD:
+ return ClassCoefD(X, P);
+ default:
+ ERROR(8)
+ }
+}
-int Pos( setO pos, setA P, setA Q, int matrix_type)
- { switch(matrix_type)
- { case MATA : return PosA(pos,P,Q);
- case MATD : return PosD(pos,P,Q);
- default : ERROR(8)
- }
- }
+float ClassCoefA(setO X, setA P)
+{
+ float coef;
+ setO notX, pos;
+ int ob1, ob2;
-int PosA( setO pos, setA P, setA Q)
- { int i,j;
- setA redQ;
- if(_mainsys->matA==NULL) ERROR(5);
- if(IsEmptySetA(P))
- { ClearSetO(pos);
+ if (_mainsys->matA == NULL)
+ ERROR(5);
+ notX = InitEmptySetO();
+ pos = InitFullSetO();
+ NotSetO(notX, X);
+ for (ob1 = 0; ob1 < _mainsys->objects_num; ob1++)
+ for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
+ if (ContSetO(X, ob1) && ContSetO(notX, ob2) &&
+ CompareA(ob1, ob2, P)) {
+ DelSetO(pos, ob1);
+ DelSetO(pos, ob2);
+ }
+ coef = (float)CardSetO(pos) / _mainsys->objects_num;
+ CloseSetO(notX);
+ CloseSetO(pos);
+ return coef;
+}
+
+float ClassCoefD(setO X, setA P)
+{
+ float coef;
+ setO notX, pos;
+ int ob1, ob2;
+
+ if (_mainsys->matD == NULL)
+ ERROR(6);
+ notX = InitEmptySetO();
+ pos = InitFullSetO();
+ NotSetO(notX, X);
+ for (ob1 = 0; ob1 < _mainsys->objects_num; ob1++)
+ for (ob2 = 0; ob2 < _mainsys->objects_num; ob2++)
+ if (ContSetO(X, ob1) && ContSetO(notX, ob2) &&
+ CompareD(ob1, ob2, P)) {
+ DelSetO(pos, ob1);
+ DelSetO(pos, ob2);
+ }
+ CloseSetO(notX);
+ coef = (float)CardSetO(pos) / _mainsys->objects_num;
+ CloseSetO(pos);
+ return coef;
+}
+
+int Pos(setO pos, setA P, setA Q, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return PosA(pos, P, Q);
+ case MATD:
+ return PosD(pos, P, Q);
+ default:
+ ERROR(8)
+ }
+}
+
+int PosA(setO pos, setA P, setA Q)
+{
+ int i, j;
+ setA redQ;
+
+ if (_mainsys->matA == NULL)
+ ERROR(5);
+ if (IsEmptySetA(P)) {
+ ClearSetO(pos);
return 0;
- }
- redQ=InitEmptySetA();
- DifSetA(redQ,Q,P);
- FillSetO(pos);
- if(IsEmptySetA(redQ))
- return 0;
- for(i=_mainsys->objects_num-1;i>0;i--)
- for(j=i-1;j>=0;j--)
- if(!CompareA(i,j,redQ) && CompareA(i,j,P))
- { DelSetO(pos,i);
- DelSetO(pos,j);
- }
- return 0;
- }
+ }
+ redQ = InitEmptySetA();
+ DifSetA(redQ, Q, P);
+ FillSetO(pos);
+ if (IsEmptySetA(redQ))
+ return 0;
+ for (i = _mainsys->objects_num - 1; i > 0; i--)
+ for (j = i - 1; j >= 0; j--)
+ if (!CompareA(i, j, redQ) && CompareA(i, j, P)) {
+ DelSetO(pos, i);
+ DelSetO(pos, j);
+ }
+ return 0;
+}
-int PosD(setO pos,setA P,setA Q)
- { int i,j;
- setA elem,redQ;
- if(_mainsys->matD==NULL) ERROR(6);
- if(IsEmptySetA(P))
- { ClearSetO(pos);
+int PosD(setO pos, setA P, setA Q)
+{
+ int i, j;
+ setA elem, redQ;
+
+ if (_mainsys->matD == NULL)
+ ERROR(6);
+ if (IsEmptySetA(P)) {
+ ClearSetO(pos);
return 0;
- }
- redQ=InitEmptySetA();
- DifSetA(redQ,Q,P);
- FillSetO(pos);
- if(IsEmptySetA(redQ))
- return 0;
- for(i=_mainsys->objects_num-1;i>0;i--)
- for(j=i-1;j>=0;j--)
- { elem=GetD(i,j);
- if(InterSetA(elem,redQ) && !InterSetA(elem,P))
- { DelSetO(pos,i);
- DelSetO(pos,j);
- }
+ }
+ redQ = InitEmptySetA();
+ DifSetA(redQ, Q, P);
+ FillSetO(pos);
+ if (IsEmptySetA(redQ))
+ return 0;
+ for (i = _mainsys->objects_num - 1; i > 0; i--)
+ for (j = i - 1; j >= 0; j--) {
+ elem = GetD(i, j);
+ if (InterSetA(elem, redQ) && !InterSetA(elem, P)) {
+ DelSetO(pos, i);
+ DelSetO(pos, j);
+ }
}
- CloseSetA(redQ);
- return 0;
- }
+ CloseSetA(redQ);
+ return 0;
+}
-float DependCoef(setA P,setA Q,int matrix_type)
- { switch(matrix_type)
- { case MATA : return DependCoefA(P,Q);
- case MATD : return DependCoefD(P,Q);
- default : ERROR(8)
- }
- }
+float DependCoef(setA P, setA Q, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return DependCoefA(P, Q);
+ case MATD:
+ return DependCoefD(P, Q);
+ default:
+ ERROR(8)
+ }
+}
-float DependCoefA(setA P,setA Q)
- { setO pos;
- float coef;
- if(_mainsys->matA==NULL) ERROR(5);
- pos=InitEmptySetO();
- PosA(pos,P,Q);
- coef= (float)CardSetO(pos) / (float)_mainsys->objects_num;
- CloseSetO(pos);
- return coef;
- }
+float DependCoefA(setA P, setA Q)
+{
+ setO pos;
+ float coef;
-float DependCoefD(setA P,setA Q)
- { setO pos;
- float coef;
- if(_mainsys->matD==NULL) ERROR(6);
- pos=InitEmptySetO();
- PosD(pos,P,Q);
- coef= (float)CardSetO(pos) / (float)_mainsys->objects_num;
- CloseSetO(pos);
- return coef;
- }
+ if (_mainsys->matA == NULL)
+ ERROR(5);
+ pos = InitEmptySetO();
+ PosA(pos, P, Q);
+ coef = (float)CardSetO(pos) / (float)_mainsys->objects_num;
+ CloseSetO(pos);
+ return coef;
+}
-float SignifCoef(int attr,setA P,int matrix_type)
- { switch(matrix_type)
- { case MATA : return SignifCoefA(attr,P);
- case MATD : return SignifCoefD(attr,P);
- default : ERROR(8)
- }
- }
+float DependCoefD(setA P, setA Q)
+{
+ setO pos;
+ float coef;
-float SignifCoefA(int attr,setA P)
- { setO pos1,pos2;
- setA Pprim;
- int i,j;
- float coef;
- if(_mainsys->matA==NULL) ERROR(5);
- if( IsEmptySetA(P) || !ContSetA(P,attr) ) return 0;
- pos1=InitFullSetO();
- pos2=InitFullSetO();
- Pprim=InitEmptySetA();
- CopySetA(Pprim,P);
- DelSetA(Pprim,attr);
- for(i=_mainsys->objects_num-1;i>0;i--)
- for(j=i-1;j>=0;j--)
- if(CompareA(i,j,P))
- { DelSetO(pos1,i);
- DelSetO(pos2,i);
- DelSetO(pos1,j);
- DelSetO(pos2,j);
- continue;
- }
- else if(CompareA(i,j,Pprim))
- { DelSetO(pos2,i);
- DelSetO(pos2,j);
- }
- DifSetO(pos1,pos1,pos2);
- coef=(float)CardSetO(pos1) / (float)_mainsys->objects_num;
- CloseSetO(pos1);
- CloseSetO(pos2);
- CloseSetA(Pprim);
- return coef;
- }
+ if (_mainsys->matD == NULL)
+ ERROR(6);
+ pos = InitEmptySetO();
+ PosD(pos, P, Q);
+ coef = (float)CardSetO(pos) / (float)_mainsys->objects_num;
+ CloseSetO(pos);
+ return coef;
+}
-float SignifCoefD(int attr,setA P)
- { setO pos1,pos2;
- setA Pprim,elem;
- int i,j;
- float coef;
- if(_mainsys->matD==NULL) ERROR(6);
- if( IsEmptySetA(P) || !ContSetA(P,attr) ) return 0;
- pos1=InitFullSetO();
- pos2=InitFullSetO();
- Pprim=InitEmptySetA();
- CopySetA(Pprim,P);
- DelSetA(Pprim,attr);
- for(i=_mainsys->objects_num-1;i>0;i--)
- for(j=i-1;j>=0;j--)
- { elem=GetD(i,j);
- if(!InterSetA(elem,P))
- { DelSetO(pos1,i);
- DelSetO(pos2,i);
- DelSetO(pos1,j);
- DelSetO(pos2,j);
- continue;
- }
- if(!InterSetA(elem,Pprim))
- { DelSetO(pos2,i);
- DelSetO(pos2,j);
- }
- }
- DifSetO(pos1,pos1,pos2);
- coef=(float)CardSetO(pos1) / (float)_mainsys->objects_num;
- CloseSetO(pos1);
- CloseSetO(pos2);
- CloseSetA(Pprim);
- return coef;
- }
+float SignifCoef(int attr, setA P, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return SignifCoefA(attr, P);
+ case MATD:
+ return SignifCoefD(attr, P);
+ default:
+ ERROR(8)
+ }
+}
-float SignifRelCoef(int attr,setA P,setA Q,int matrix_type)
- { switch(matrix_type)
- { case MATA : return SignifRelCoefA(attr,P,Q);
- case MATD : return SignifRelCoefD(attr,P,Q);
- default : ERROR(8)
- }
- }
+float SignifCoefA(int attr, setA P)
+{
+ setO pos1, pos2;
+ setA Pprim;
+ int i, j;
+ float coef;
-float SignifRelCoefA(int attr,setA P,setA Q)
- { setO pos1,pos2;
- setA Pprim,redQ;
- int i,j;
- float coef;
- if(_mainsys->matA==NULL) ERROR(5);
- Pprim=InitEmptySetA();
- redQ=InitEmptySetA();
- CopySetA(Pprim,P);
- DelSetA(Pprim,attr);
- DifSetA(redQ,Q,Pprim);
- if( IsEmptySetA(P) || !ContSetA(P,attr) ) return 0;
- if( IsEmptySetA(redQ) ) return 1;
- pos1=InitFullSetO();
- pos2=InitFullSetO();
- for(i=_mainsys->objects_num-1;i>0;i--)
- for(j=i-1;j>=0;j--)
- if(CompareA(i,j,redQ)) continue;
- else if(CompareA(i,j,P))
- { DelSetO(pos1,i);
- DelSetO(pos2,i);
- DelSetO(pos1,j);
- DelSetO(pos2,j);
- continue;
- }
- else if(CompareA(i,j,Pprim))
- { DelSetO(pos2,i);
- DelSetO(pos2,j);
- }
- DifSetO(pos1,pos1,pos2);
- coef=(float)CardSetO(pos1) / (float)_mainsys->objects_num;
- CloseSetO(pos1);
- CloseSetO(pos2);
- CloseSetA(Pprim);
- CloseSetA(redQ);
- return coef;
- }
+ if (_mainsys->matA == NULL)
+ ERROR(5);
+ if (IsEmptySetA(P) || !ContSetA(P, attr))
+ return 0;
+ pos1 = InitFullSetO();
+ pos2 = InitFullSetO();
+ Pprim = InitEmptySetA();
+ CopySetA(Pprim, P);
+ DelSetA(Pprim, attr);
+ for (i = _mainsys->objects_num - 1; i > 0; i--)
+ for (j = i - 1; j >= 0; j--)
+ if (CompareA(i, j, P)) {
+ DelSetO(pos1, i);
+ DelSetO(pos2, i);
+ DelSetO(pos1, j);
+ DelSetO(pos2, j);
+ continue;
+ }
+ else if (CompareA(i, j, Pprim)) {
+ DelSetO(pos2, i);
+ DelSetO(pos2, j);
+ }
+ DifSetO(pos1, pos1, pos2);
+ coef = (float)CardSetO(pos1) / (float)_mainsys->objects_num;
+ CloseSetO(pos1);
+ CloseSetO(pos2);
+ CloseSetA(Pprim);
+ return coef;
+}
-float SignifRelCoefD(int attr,setA P,setA Q)
- { setO pos1,pos2;
- setA Pprim,redQ,elem;
- int i,j;
- float coef;
- if(_mainsys->matD==NULL) ERROR(6);
- Pprim=InitEmptySetA();
- redQ=InitEmptySetA();
- CopySetA(Pprim,P);
- DelSetA(Pprim,attr);
- DifSetA(redQ,Q,Pprim);
- if( IsEmptySetA(P) || !ContSetA(P,attr) ) return 0;
- if( IsEmptySetA(redQ) ) return 1;
- pos1=InitFullSetO();
- pos2=InitFullSetO();
- for(i=_mainsys->objects_num-1;i>0;i--)
- for(j=i-1;j>=0;j--)
- { elem=GetD(i,j);
- if(!InterSetA(elem,redQ)) continue;
- if(!InterSetA(elem,P))
- { DelSetO(pos1,i);
- DelSetO(pos2,i);
- DelSetO(pos1,j);
- DelSetO(pos2,j);
- continue;
- }
- if(!InterSetA(elem,Pprim))
- { DelSetO(pos2,i);
- DelSetO(pos2,j);
- }
- }
- DifSetO(pos1,pos1,pos2);
- coef=(float)CardSetO(pos1) / (float)_mainsys->objects_num;
- CloseSetO(pos1);
- CloseSetO(pos2);
- CloseSetA(Pprim);
- CloseSetA(redQ);
- return coef;
- }
+float SignifCoefD(int attr, setA P)
+{
+ setO pos1, pos2;
+ setA Pprim, elem;
+ int i, j;
+ float coef;
+ if (_mainsys->matD == NULL)
+ ERROR(6);
+ if (IsEmptySetA(P) || !ContSetA(P, attr))
+ return 0;
+ pos1 = InitFullSetO();
+ pos2 = InitFullSetO();
+ Pprim = InitEmptySetA();
+ CopySetA(Pprim, P);
+ DelSetA(Pprim, attr);
+ for (i = _mainsys->objects_num - 1; i > 0; i--)
+ for (j = i - 1; j >= 0; j--) {
+ elem = GetD(i, j);
+ if (!InterSetA(elem, P)) {
+ DelSetO(pos1, i);
+ DelSetO(pos2, i);
+ DelSetO(pos1, j);
+ DelSetO(pos2, j);
+ continue;
+ }
+ if (!InterSetA(elem, Pprim)) {
+ DelSetO(pos2, i);
+ DelSetO(pos2, j);
+ }
+ }
+ DifSetO(pos1, pos1, pos2);
+ coef = (float)CardSetO(pos1) / (float)_mainsys->objects_num;
+ CloseSetO(pos1);
+ CloseSetO(pos2);
+ CloseSetA(Pprim);
+ return coef;
+}
+float SignifRelCoef(int attr, setA P, setA Q, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return SignifRelCoefA(attr, P, Q);
+ case MATD:
+ return SignifRelCoefD(attr, P, Q);
+ default:
+ ERROR(8)
+ }
+}
+
+float SignifRelCoefA(int attr, setA P, setA Q)
+{
+ setO pos1, pos2;
+ setA Pprim, redQ;
+ int i, j;
+ float coef;
+
+ if (_mainsys->matA == NULL)
+ ERROR(5);
+ Pprim = InitEmptySetA();
+ redQ = InitEmptySetA();
+ CopySetA(Pprim, P);
+ DelSetA(Pprim, attr);
+ DifSetA(redQ, Q, Pprim);
+ if (IsEmptySetA(P) || !ContSetA(P, attr))
+ return 0;
+ if (IsEmptySetA(redQ))
+ return 1;
+ pos1 = InitFullSetO();
+ pos2 = InitFullSetO();
+ for (i = _mainsys->objects_num - 1; i > 0; i--)
+ for (j = i - 1; j >= 0; j--)
+ if (CompareA(i, j, redQ))
+ continue;
+ else if (CompareA(i, j, P)) {
+ DelSetO(pos1, i);
+ DelSetO(pos2, i);
+ DelSetO(pos1, j);
+ DelSetO(pos2, j);
+ continue;
+ }
+ else if (CompareA(i, j, Pprim)) {
+ DelSetO(pos2, i);
+ DelSetO(pos2, j);
+ }
+ DifSetO(pos1, pos1, pos2);
+ coef = (float)CardSetO(pos1) / (float)_mainsys->objects_num;
+ CloseSetO(pos1);
+ CloseSetO(pos2);
+ CloseSetA(Pprim);
+ CloseSetA(redQ);
+ return coef;
+}
+
+float SignifRelCoefD(int attr, setA P, setA Q)
+{
+ setO pos1, pos2;
+ setA Pprim, redQ, elem;
+ int i, j;
+ float coef;
+
+ if (_mainsys->matD == NULL)
+ ERROR(6);
+ Pprim = InitEmptySetA();
+ redQ = InitEmptySetA();
+ CopySetA(Pprim, P);
+ DelSetA(Pprim, attr);
+ DifSetA(redQ, Q, Pprim);
+ if (IsEmptySetA(P) || !ContSetA(P, attr))
+ return 0;
+ if (IsEmptySetA(redQ))
+ return 1;
+ pos1 = InitFullSetO();
+ pos2 = InitFullSetO();
+ for (i = _mainsys->objects_num - 1; i > 0; i--)
+ for (j = i - 1; j >= 0; j--) {
+ elem = GetD(i, j);
+ if (!InterSetA(elem, redQ))
+ continue;
+ if (!InterSetA(elem, P)) {
+ DelSetO(pos1, i);
+ DelSetO(pos2, i);
+ DelSetO(pos1, j);
+ DelSetO(pos2, j);
+ continue;
+ }
+ if (!InterSetA(elem, Pprim)) {
+ DelSetO(pos2, i);
+ DelSetO(pos2, j);
+ }
+ }
+ DifSetO(pos1, pos1, pos2);
+ coef = (float)CardSetO(pos1) / (float)_mainsys->objects_num;
+ CloseSetO(pos1);
+ CloseSetO(pos2);
+ CloseSetA(Pprim);
+ CloseSetA(redQ);
+ return coef;
+}
+
+
int CardCoef(setA P, int matrix_type)
- { int res = 0;
- for( start_of_tab( matrix_type ); end_of_tab(); next_of_tab() )
- if ( InterSetA( P, _table_element ) )
- res++;
- if ( _rerror>0 ) return -_rerror;
- return res;
- }
+{
+ int res = 0;
+
+ for (start_of_tab(matrix_type); end_of_tab(); next_of_tab())
+ if (InterSetA(P, _table_element))
+ res++;
+ if (_rerror > 0)
+ return -_rerror;
+ return res;
+}
Modified: grass-addons/raster/mcda/r.roughset/rbasic.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rbasic.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rbasic.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,11 +16,17 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** BASIC QUERRIES FOR SYSTEM ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
@@ -27,56 +34,66 @@
/* first initialized and then given to the function as a first */
/* argument. Functions from this group does not work on matrix X. */
-int LowAppr (setO appr,setO X,setA P,int matrix_type);
-int LowApprA(setO appr,setO X,setA P);
-int LowApprD(setO appr,setO X,setA P);
+int LowAppr(setO appr, setO X, setA P, int matrix_type);
+int LowApprA(setO appr, setO X, setA P);
+int LowApprD(setO appr, setO X, setA P);
+
/* P-lower approximation of X */
-int UppAppr (setO appr,setO X,setA P,int matrix_type);
-int UppApprA(setO appr,setO X,setA P);
-int UppApprD(setO appr,setO X,setA P);
+int UppAppr(setO appr, setO X, setA P, int matrix_type);
+int UppApprA(setO appr, setO X, setA P);
+int UppApprD(setO appr, setO X, setA P);
+
/* P-upper appriximation of X */
-int Bound (setO bound,setO X,setA P,int matrix_type);
-int BoundA(setO bound,setO X,setA P);
-int BoundD(setO bound,setO X,setA P);
+int Bound(setO bound, setO X, setA P, int matrix_type);
+int BoundA(setO bound, setO X, setA P);
+int BoundD(setO bound, setO X, setA P);
+
/* P-boundary of X */
-float AccurCoef (setO X,setA P,int matrix_type);
-float AccurCoefA(setO X,setA P);
-float AccurCoefD(setO X,setA P);
+float AccurCoef(setO X, setA P, int matrix_type);
+float AccurCoefA(setO X, setA P);
+float AccurCoefD(setO X, setA P);
+
/* Accuracy coefficient of X with respect to P */
-float ClassCoef (setO X,setA P,int matrix_type);
-float ClassCoefA(setO X,setA P);
-float ClassCoefD(setO X,setA P);
+float ClassCoef(setO X, setA P, int matrix_type);
+float ClassCoefA(setO X, setA P);
+float ClassCoefD(setO X, setA P);
+
/* quality of classification (X,not X) */
/* with respect to P */
-int Pos (setO pos,setA P,setA Q,int matrix_type);
-int PosA(setO pos,setA P,setA Q);
-int PosD(setO pos,setA P,setA Q);
+int Pos(setO pos, setA P, setA Q, int matrix_type);
+int PosA(setO pos, setA P, setA Q);
+int PosD(setO pos, setA P, setA Q);
+
/* P-positive region of Q */
-float DependCoef (setA P,setA Q,int matrix_type);
-float DependCoefA(setA P,setA Q);
-float DependCoefD(setA P,setA Q);
+float DependCoef(setA P, setA Q, int matrix_type);
+float DependCoefA(setA P, setA Q);
+float DependCoefD(setA P, setA Q);
+
/* degree of dependency Q from P */
-float SignifCoef (int attr,setA P,int matrix_type);
-float SignifCoefA(int attr,setA P);
-float SignifCoefD(int attr,setA P);
+float SignifCoef(int attr, setA P, int matrix_type);
+float SignifCoefA(int attr, setA P);
+float SignifCoefD(int attr, setA P);
+
/* significance of attribute attr */
/* in the set P */
-float SignifRelCoef (int attr,setA P,setA Q,int matrix_type);
-float SignifRelCoefA(int attr,setA P,setA Q);
-float SignifRelCoefD(int attr,setA P,setA Q);
+float SignifRelCoef(int attr, setA P, setA Q, int matrix_type);
+float SignifRelCoefA(int attr, setA P, setA Q);
+float SignifRelCoefD(int attr, setA P, setA Q);
+
/* significance of attribute attr */
/* in the set P, relatively to Q */
-int CardCoef(setA P,int matrix_type);
+int CardCoef(setA P, int matrix_type);
+
/* returns number of matrix fields */
/* covered by P (MATA is treated as MATD) */
/* but elements are evaluated "on-line" */
Modified: grass-addons/raster/mcda/r.roughset/rclass.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rclass.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rclass.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,12 +16,19 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SOME MORE QUERIES FOR SYSTEM ***/
+
/*** ( CLASSIFICATION ) ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
@@ -28,190 +36,207 @@
#include "rough.h"
-int DecisionEQ( value_type *rule1, value_type *rule2, setA Q)
- { int i;
- for (i=0; i<_mainsys->attributes_num; i++ )
- if ( ContSetA( Q, i ) )
- if ( rule1[i] != rule2[i] )
- return 0;
- return 1;
- }
+int DecisionEQ(value_type * rule1, value_type * rule2, setA Q)
+{
+ int i;
+ for (i = 0; i < _mainsys->attributes_num; i++)
+ if (ContSetA(Q, i))
+ if (rule1[i] != rule2[i])
+ return 0;
+ return 1;
+}
-int StrengthOfRule( value_type *rule )
-{ int obj,attr,
- find,
- result=0,
- size=_mainsys->attributes_num;
- for (obj=0;obj<_mainsys->objects_num;obj++)
- { find = 1;
- for (attr=0;attr<size;attr++)
- if ( rule[attr] != GetA(obj,attr) )
- if ( rule[attr]!=MINUS && GetA(obj,attr)!=MINUS )
- { find=0; break; }
- if (find)
+
+int StrengthOfRule(value_type * rule)
+{
+ int obj, attr, find, result = 0, size = _mainsys->attributes_num;
+
+ for (obj = 0; obj < _mainsys->objects_num; obj++) {
+ find = 1;
+ for (attr = 0; attr < size; attr++)
+ if (rule[attr] != GetA(obj, attr))
+ if (rule[attr] != MINUS && GetA(obj, attr) != MINUS) {
+ find = 0;
+ break;
+ }
+ if (find)
result++;
- }
- return result;
+ }
+ return result;
}
-int *StrengthOfRules( value_type *rules, int N )
-{ int *result;
- int i,size=_mainsys->attributes_num;
-
- if ( N <= 0 ) return NULL;
- result = (int *) calloc( N, sizeof(int) );
- for (i=0;i<N;i++)
- result[i] = StrengthOfRule( rules+i*size );
- return result;
+int *StrengthOfRules(value_type * rules, int N)
+{
+ int *result;
+ int i, size = _mainsys->attributes_num;
+
+ if (N <= 0)
+ return NULL;
+ result = (int *)calloc(N, sizeof(int));
+ for (i = 0; i < N; i++)
+ result[i] = StrengthOfRule(rules + i * size);
+ return result;
}
-int ObjectsForRule( setO set, value_type *rule )
-{ int i,j,
- find,
- size=_mainsys->attributes_num;
-
- for (i=0;i<_mainsys->objects_num;i++)
- { find = 1;
- for (j=0;j<size;j++)
- if ( rule[j] != GetA(i,j) )
- if ( rule[j]!=MINUS && GetA(i,j)!=MINUS )
- { find=0; break; }
- if (find)
- AddSetO( set, i );
+int ObjectsForRule(setO set, value_type * rule)
+{
+ int i, j, find, size = _mainsys->attributes_num;
+
+ for (i = 0; i < _mainsys->objects_num; i++) {
+ find = 1;
+ for (j = 0; j < size; j++)
+ if (rule[j] != GetA(i, j))
+ if (rule[j] != MINUS && GetA(i, j) != MINUS) {
+ find = 0;
+ break;
+ }
+ if (find)
+ AddSetO(set, i);
}
- return CardSetO( set );
+ return CardSetO(set);
}
-int CompareToRule( value_type *sample, value_type *rule, setA P )
-{ int j,
- result=0,
- size=_mainsys->attributes_num;
- for (j=0;j<size;j++)
- { if ( !ContSetA(P,j) ) continue;
- if ( rule[j] != sample[j] )
- if ( rule[j]!=MINUS && sample[j]!=MINUS )
- result++;
- }
- return result;
-}
+int CompareToRule(value_type * sample, value_type * rule, setA P)
+{
+ int j, result = 0, size = _mainsys->attributes_num;
+ for (j = 0; j < size; j++) {
+ if (!ContSetA(P, j))
+ continue;
+ if (rule[j] != sample[j])
+ if (rule[j] != MINUS && sample[j] != MINUS)
+ result++;
+ }
+ return result;
+}
-int *CompareToRules( value_type *sample, value_type *rules, int N, setA P )
-{ int *result;
- int i,size=_mainsys->attributes_num;
-
- if ( N <= 0 ) return NULL;
- result = (int *)calloc( N, sizeof(int) );
- for (i=0;i<N;i++)
- result[i] = CompareToRule( sample, rules+i*size, P );
- return result;
+
+int *CompareToRules(value_type * sample, value_type * rules, int N, setA P)
+{
+ int *result;
+ int i, size = _mainsys->attributes_num;
+
+ if (N <= 0)
+ return NULL;
+ result = (int *)calloc(N, sizeof(int));
+ for (i = 0; i < N; i++)
+ result[i] = CompareToRule(sample, rules + i * size, P);
+ return result;
}
-int Classify1( value_type *sample, value_type *rules, int N, setA P, setA Q )
-{ int done=0,
- result=-1,
- count=0,
- *diff, minDiff=_mainsys->attributes_num,
- i, j=0, max=0,
- size=_mainsys->attributes_num;
- diff = CompareToRules( sample, rules, N, P );
- for (i=0; i<N; i++)
- if ( diff[i]<minDiff ) minDiff = diff[i];
- while ( !done ) /* while there is an unprocessed rule */
- { while ( diff[j]!= minDiff ) j++; /* to find the rule with new decision */
- done = 1;
- diff[j]++;
- count = 1;
- for (i=j; i<N; i++)
- if ( diff[i] == minDiff )
- if ( DecisionEQ( rules+i*size,rules+j*size,Q ) )
- { diff[j]++; /* to protect from next use */
- count++;
- }
- else done = 0;
- if ( count>max ) max=count, result=j;
- }
- free( diff );
- return result;
+int Classify1(value_type * sample, value_type * rules, int N, setA P, setA Q)
+{
+ int done = 0,
+ result = -1,
+ count = 0,
+ *diff, minDiff = _mainsys->attributes_num,
+ i, j = 0, max = 0, size = _mainsys->attributes_num;
+ diff = CompareToRules(sample, rules, N, P);
+ for (i = 0; i < N; i++)
+ if (diff[i] < minDiff)
+ minDiff = diff[i];
+ while (!done) { /* while there is an unprocessed rule */
+ while (diff[j] != minDiff)
+ j++; /* to find the rule with new decision */
+ done = 1;
+ diff[j]++;
+ count = 1;
+ for (i = j; i < N; i++)
+ if (diff[i] == minDiff)
+ if (DecisionEQ(rules + i * size, rules + j * size, Q)) {
+ diff[j]++; /* to protect from next use */
+ count++;
+ }
+ else
+ done = 0;
+ if (count > max)
+ max = count, result = j;
+ }
+ free(diff);
+ return result;
}
-int Classify2( value_type *sample, value_type *rules, int N, setA P, setA Q )
-{ int i,
- *diff,
- first=0,maxindex,
- size=_mainsys->attributes_num,
- minDiff=_mainsys->attributes_num,
- done=0;
- setO cover, maxcover, rulecover;
-
- cover = InitEmptySetO();
- maxcover = InitEmptySetO();
- rulecover = InitEmptySetO();
- diff = CompareToRules( sample, rules, N, P );
- for (i=0; i<N; i++)
- if ( diff[i]<minDiff ) minDiff = diff[i];
- while ( !done ) /* while there is an unprocessed rule */
- { while ( diff[first]!= minDiff ) first++; /* to find the rule with new decision */
- done = 1;
- diff[first]++; /* to protect from next use */
- ObjectsForRule( cover, rules+first*size );
- for (i=first; i<N; i++)
- if ( diff[i]==minDiff )
- if ( DecisionEQ( rules+first*size, rules+i*size, Q ) )
- { diff[i]++;
- ObjectsForRule( rulecover, rules+i*size );
- OrSetO( cover, cover, rulecover );
- }
- else
- done = 0;
- if ( CardSetO( maxcover ) < CardSetO( cover ) )
- { CopySetO( maxcover, cover );
- maxindex = first;
- }
- }
- free( diff );
- CloseSetO( cover );
- CloseSetO( maxcover );
- CloseSetO( rulecover );
- return maxindex;
+int Classify2(value_type * sample, value_type * rules, int N, setA P, setA Q)
+{
+ int i,
+ *diff,
+ first = 0, maxindex,
+ size = _mainsys->attributes_num,
+ minDiff = _mainsys->attributes_num, done = 0;
+ setO cover, maxcover, rulecover;
+
+ cover = InitEmptySetO();
+ maxcover = InitEmptySetO();
+ rulecover = InitEmptySetO();
+ diff = CompareToRules(sample, rules, N, P);
+ for (i = 0; i < N; i++)
+ if (diff[i] < minDiff)
+ minDiff = diff[i];
+ while (!done) { /* while there is an unprocessed rule */
+ while (diff[first] != minDiff)
+ first++; /* to find the rule with new decision */
+ done = 1;
+ diff[first]++; /* to protect from next use */
+ ObjectsForRule(cover, rules + first * size);
+ for (i = first; i < N; i++)
+ if (diff[i] == minDiff)
+ if (DecisionEQ(rules + first * size, rules + i * size, Q)) {
+ diff[i]++;
+ ObjectsForRule(rulecover, rules + i * size);
+ OrSetO(cover, cover, rulecover);
+ }
+ else
+ done = 0;
+ if (CardSetO(maxcover) < CardSetO(cover)) {
+ CopySetO(maxcover, cover);
+ maxindex = first;
+ }
+ }
+ free(diff);
+ CloseSetO(cover);
+ CloseSetO(maxcover);
+ CloseSetO(rulecover);
+ return maxindex;
}
-int Classify3( value_type *sample, value_type *rules, int N,
- int *strength, setA P, setA Q )
-{ int i,
- *diff,
- first=0,maxindex,
- size=_mainsys->attributes_num,
- minDiff=_mainsys->attributes_num,
- done=0;
- int cover, maxcover=0;
-
- diff = CompareToRules( sample, rules, N, P );
- for (i=0; i<N; i++)
- if ( diff[i]<minDiff ) minDiff = diff[i];
- while ( !done ) /* while there is an unprocessed rule */
- { while ( diff[first]!= minDiff ) first++; /* to find the rule with new decision */
- done = 1;
- diff[first]++; /* to protect from next use */
- cover = strength[first];
- for (i=first; i<N; i++)
- if ( diff[i]==minDiff )
- if ( DecisionEQ( rules+first*size, rules+i*size, Q ) )
- { diff[i]++;
- cover += strength[i];
- }
- else
- done = 0;
- if ( maxcover < cover )
- { maxcover = cover;
- maxindex = first;
- }
- }
- free( diff );
- return maxindex;
+int Classify3(value_type * sample, value_type * rules, int N,
+ int *strength, setA P, setA Q)
+{
+ int i,
+ *diff,
+ first = 0, maxindex,
+ size = _mainsys->attributes_num,
+ minDiff = _mainsys->attributes_num, done = 0;
+ int cover, maxcover = 0;
+
+ diff = CompareToRules(sample, rules, N, P);
+ for (i = 0; i < N; i++)
+ if (diff[i] < minDiff)
+ minDiff = diff[i];
+ while (!done) { /* while there is an unprocessed rule */
+ while (diff[first] != minDiff)
+ first++; /* to find the rule with new decision */
+ done = 1;
+ diff[first]++; /* to protect from next use */
+ cover = strength[first];
+ for (i = first; i < N; i++)
+ if (diff[i] == minDiff)
+ if (DecisionEQ(rules + first * size, rules + i * size, Q)) {
+ diff[i]++;
+ cover += strength[i];
+ }
+ else
+ done = 0;
+ if (maxcover < cover) {
+ maxcover = cover;
+ maxindex = first;
+ }
+ }
+ free(diff);
+ return maxindex;
}
Modified: grass-addons/raster/mcda/r.roughset/rclass.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rclass.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rclass.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,51 +16,66 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SOME MORE QUERIES FOR SYSTEM ***/
+
/*** ( CLASSIFICATION ) ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
-int DecisionEQ(value_type *rule1,value_type *rule2,setA Q);
+int DecisionEQ(value_type * rule1, value_type * rule2, setA Q);
+
/* compares decisions of two rules */
/* returns 1 if equal */
-int StrengthOfRule( value_type *rule );
+int StrengthOfRule(value_type * rule);
+
/* return a number of objects covered by rule (strength) */
-int *StrengthOfRules( value_type *rules, int N );
+int *StrengthOfRules(value_type * rules, int N);
+
/* creates a table of rules strengths */
/* allocates memory, size = N * sizeof(int) */
-int ObjectsForRule( setO set, value_type *rule );
+int ObjectsForRule(setO set, value_type * rule);
+
/* finds a set of objects covered by rule */
-int CompareToRule( value_type *sample, value_type *rule, setA P );
+int CompareToRule(value_type * sample, value_type * rule, setA P);
+
/* compares a sample with rule on a set of attributes */
/* returns a number of dissimilar attributes (distance) */
-
-int *CompareToRules( value_type *sample, value_type *rules, int N, setA P );
+
+int *CompareToRules(value_type * sample, value_type * rules, int N, setA P);
+
/* compares a sample with rules on a set of attributes */
/* creates a table of distances (number of dissimilar attributes) */
/* allocates memory, size = N * sizeof(int) */
-int Classify1( value_type *sample, value_type *rules, int N, setA P, setA Q );
+int Classify1(value_type * sample, value_type * rules, int N, setA P, setA Q);
+
/* chooses the best rule to cover sample, strategy no. 1 */
/* finds the most frequent decision among rules with minimal */
/* distances from a given sample, returns index of a proper rule */
-int Classify2( value_type *sample, value_type *rules, int N, setA P, setA Q );
+int Classify2(value_type * sample, value_type * rules, int N, setA P, setA Q);
+
/* chooses the best rule to cover sample, strategy no. 2 */
/* finds a decision that covers the largerst number of objects */
/* among rules with minimal distances from a given sample */
/* returns index of a proper rule */
-int Classify3( value_type *sample, value_type *rules, int N,
- int *strength, setA P, setA Q );
+int Classify3(value_type * sample, value_type * rules, int N,
+ int *strength, setA P, setA Q);
/* chooses the best rule to cover sample, strategy no. 3 */
/* finds a decision with the largest total strength among */
/* rules with minimal distances from a given sample */
Modified: grass-addons/raster/mcda/r.roughset/rcore.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rcore.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rcore.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,12 +16,19 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SOME MORE QUERIES FOR SYSTEM ***/
+
/*** ( FINDING CORES AND CHECKING REDUCTS ) ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
@@ -28,241 +36,312 @@
#include <stdlib.h>
-int Core(setA core,int matrix_type)
- { switch(matrix_type)
- { case MATA : return CoreA(core);
- case MATD : return CoreDX(core,matrix_type);
- case MATX : return CoreDX(core,matrix_type);
- default : ERROR(8)
- }
- }
+int Core(setA core, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return CoreA(core);
+ case MATD:
+ return CoreDX(core, matrix_type);
+ case MATX:
+ return CoreDX(core, matrix_type);
+ default:
+ ERROR(8)
+ }
+}
int CoreA(setA core)
- { int ob1,ob2,attr,no1,pattr;
- if (_mainsys->matA==NULL) ERROR(5)
- ClearSetA(core);
- for(ob1=_mainsys->objects_num-1;ob1>0;ob1--)
- for(ob2=ob1-1;ob2>=0;ob2--)
- { no1=0;
- for(attr=_mainsys->attributes_num-1;attr>=0;attr--)
- if(!SingCompA(ob1,ob2,attr))
- { no1++;
- if (no1>1) break;
- else pattr=attr;
- }
- if (no1==1) AddSetA(core,pattr);
+{
+ int ob1, ob2, attr, no1, pattr;
+
+ if (_mainsys->matA == NULL)
+ ERROR(5)
+ ClearSetA(core);
+ for (ob1 = _mainsys->objects_num - 1; ob1 > 0; ob1--)
+ for (ob2 = ob1 - 1; ob2 >= 0; ob2--) {
+ no1 = 0;
+ for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
+ if (!SingCompA(ob1, ob2, attr)) {
+ no1++;
+ if (no1 > 1)
+ break;
+ else
+ pattr = attr;
+ }
+ if (no1 == 1)
+ AddSetA(core, pattr);
}
- return 0;
- }
+ return 0;
+}
int CoreDX(setA core, int matrix_type)
- { int cluster,bit,flag,no1,pcluster;
- ClearSetA(core);
- if(matrix_type==MATD)
- { if (_mainsys->matD==NULL) ERROR(6)
- START_OF_D;
- }
- else
- { if (_mainsys->matX==NULL) ERROR(7)
- START_OF_X;
- }
- for(;END_OF_MAT;NEXT_OF_MAT)
- { flag=0;no1=0;
- for(cluster=_mainsys->setAsize-1;cluster>=0;cluster--)
- { for(bit=0;bit<_cluster_bits;bit++)
- if(_mask[bit] & ELEM_OF_MAT[cluster])
- { no1++;
- if (no1>1) { flag=1; break; }
- else pcluster=cluster;
+{
+ int cluster, bit, flag, no1, pcluster;
+
+ ClearSetA(core);
+ if (matrix_type == MATD) {
+ if (_mainsys->matD == NULL)
+ ERROR(6)
+ START_OF_D;
+ }
+ else {
+ if (_mainsys->matX == NULL)
+ ERROR(7)
+ START_OF_X;
+ }
+ for (; END_OF_MAT; NEXT_OF_MAT) {
+ flag = 0;
+ no1 = 0;
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--) {
+ for (bit = 0; bit < _cluster_bits; bit++)
+ if (_mask[bit] & ELEM_OF_MAT[cluster]) {
+ no1++;
+ if (no1 > 1) {
+ flag = 1;
+ break;
+ }
+ else
+ pcluster = cluster;
}
- if(flag) break;
- }
- if (no1==1) core[pcluster] |= ELEM_OF_MAT[pcluster];
+ if (flag)
+ break;
+ }
+ if (no1 == 1)
+ core[pcluster] |= ELEM_OF_MAT[pcluster];
}
- return 0;
- }
+ return 0;
+}
-int CoreRel(setA core,setA P,setA Q,int matrix_type)
- { switch(matrix_type)
- { case MATA : return CoreRelA(core,P,Q);
- case MATD : return CoreRelD(core,P,Q);
- default : ERROR(8)
- }
- }
+int CoreRel(setA core, setA P, setA Q, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return CoreRelA(core, P, Q);
+ case MATD:
+ return CoreRelD(core, P, Q);
+ default:
+ ERROR(8)
+ }
+}
-int CoreRelA(setA core,setA P,setA Q)
- { int ob1,ob2,attr,no1,pattr;
- if (_mainsys->matA==NULL) ERROR(5)
- ClearSetA(core);
- for(ob1=_mainsys->objects_num-1;ob1>0;ob1--)
- for(ob2=ob1-1;ob2>=0;ob2--)
- if(!CompareA(ob1,ob2,Q))
- { no1=0;
- for(attr=_mainsys->attributes_num-1;attr>=0;attr--)
- if(ContSetA(P,attr))
- if(!SingCompA(ob1,ob2,attr))
- { no1++;
- if (no1>1) break;
- else pattr=attr;
- }
- if (no1==1) AddSetA(core,pattr);
- }
- return 0;
- }
+int CoreRelA(setA core, setA P, setA Q)
+{
+ int ob1, ob2, attr, no1, pattr;
-int CoreRelD(setA core,setA P,setA Q)
- { int cluster,bit,flag,no1,pcluster;
- setA elem;
- if (_mainsys->matD==NULL) ERROR(6)
- ClearSetA(core);
- elem=InitEmptySetA();
- for(START_OF_D;END_OF_MAT;NEXT_OF_MAT)
- { AndSetA(elem,ELEM_OF_MAT,P);
- flag=0;no1=0;
- if (!InterSetA(Q,ELEM_OF_MAT)) continue;
- for(cluster=_mainsys->setAsize-1;cluster>=0;cluster--)
- { for(bit=0;bit<_cluster_bits;bit++)
- if(_mask[bit] & elem[cluster])
- { no1++;
- if (no1>1) { flag=1; break; }
- else pcluster=cluster;
- }
- if(flag) break;
- }
- if (no1==1) core[pcluster] |= elem[pcluster];
- }
- CloseSetA(elem);
- return 0;
- }
+ if (_mainsys->matA == NULL)
+ ERROR(5)
+ ClearSetA(core);
+ for (ob1 = _mainsys->objects_num - 1; ob1 > 0; ob1--)
+ for (ob2 = ob1 - 1; ob2 >= 0; ob2--)
+ if (!CompareA(ob1, ob2, Q)) {
+ no1 = 0;
+ for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
+ if (ContSetA(P, attr))
+ if (!SingCompA(ob1, ob2, attr)) {
+ no1++;
+ if (no1 > 1)
+ break;
+ else
+ pattr = attr;
+ }
+ if (no1 == 1)
+ AddSetA(core, pattr);
+ }
+ return 0;
+}
-int IsOrtho(setA red,setA over,int matrix_type)
- { setA and, redprim;
- and=InitEmptySetA();
- redprim=InitEmptySetA();
- for(start_of_tab(matrix_type); end_of_tab(); next_of_tab())
- { AndSetA( and, _table_element, red );
- if ( CardSetA( and ) == 1 )
- OrSetA( redprim, redprim, and );
- }
- CloseSetA(and);
- DifSetA( over, red, redprim );
- CloseSetA( redprim );
- return IsEmptySetA( over );
- }
+int CoreRelD(setA core, setA P, setA Q)
+{
+ int cluster, bit, flag, no1, pcluster;
+ setA elem;
+ if (_mainsys->matD == NULL)
+ ERROR(6)
+ ClearSetA(core);
+ elem = InitEmptySetA();
+ for (START_OF_D; END_OF_MAT; NEXT_OF_MAT) {
+ AndSetA(elem, ELEM_OF_MAT, P);
+ flag = 0;
+ no1 = 0;
+ if (!InterSetA(Q, ELEM_OF_MAT))
+ continue;
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--) {
+ for (bit = 0; bit < _cluster_bits; bit++)
+ if (_mask[bit] & elem[cluster]) {
+ no1++;
+ if (no1 > 1) {
+ flag = 1;
+ break;
+ }
+ else
+ pcluster = cluster;
+ }
+ if (flag)
+ break;
+ }
+ if (no1 == 1)
+ core[pcluster] |= elem[pcluster];
+ }
+ CloseSetA(elem);
+ return 0;
+}
+
+int IsOrtho(setA red, setA over, int matrix_type)
+{
+ setA and, redprim;
+
+ and = InitEmptySetA();
+ redprim = InitEmptySetA();
+ for (start_of_tab(matrix_type); end_of_tab(); next_of_tab()) {
+ AndSetA(and, _table_element, red);
+ if (CardSetA(and) == 1)
+ OrSetA(redprim, redprim, and);
+ }
+ CloseSetA(and);
+ DifSetA(over, red, redprim);
+ CloseSetA(redprim);
+ return IsEmptySetA(over);
+}
+
int IsOrthoRel(setA red, setA over, setA P, setA Q, int matrix_type)
- { setA and, redprim;
- and=InitEmptySetA();
- redprim=InitEmptySetA();
- for(start_of_tab(matrix_type); end_of_tab(); next_of_tab())
- if ( InterSetA( _table_element, Q ) )
- { AndSetA( and, _table_element, red );
- AndSetA( and, and, P );
- if ( CardSetA( and ) == 1 )
- OrSetA( redprim, redprim, and );
- }
- CloseSetA(and);
- DifSetA( over, red, redprim );
- CloseSetA( redprim );
- return IsEmptySetA( over );
- }
+{
+ setA and, redprim;
-int IsCover(setA red,int matrix_type)
- { switch(matrix_type)
- { case MATA : return IsCoverA(red);
- case MATD : return IsCoverDX(red,matrix_type);
- case MATX : return IsCoverDX(red,matrix_type);
- default : ERROR(8)
- }
- }
+ and = InitEmptySetA();
+ redprim = InitEmptySetA();
+ for (start_of_tab(matrix_type); end_of_tab(); next_of_tab())
+ if (InterSetA(_table_element, Q)) {
+ AndSetA(and, _table_element, red);
+ AndSetA(and, and, P);
+ if (CardSetA(and) == 1)
+ OrSetA(redprim, redprim, and);
+ }
+ CloseSetA(and);
+ DifSetA(over, red, redprim);
+ CloseSetA(redprim);
+ return IsEmptySetA(over);
+}
+int IsCover(setA red, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return IsCoverA(red);
+ case MATD:
+ return IsCoverDX(red, matrix_type);
+ case MATX:
+ return IsCoverDX(red, matrix_type);
+ default:
+ ERROR(8)
+ }
+}
+
int IsCoverA(setA red)
- { int ob1,ob2;
- setA P=InitFullSetA();
- DifSetA(P,P,red);
- if(_mainsys->matA==NULL) ERROR(5);
- for(ob1=_mainsys->objects_num-1;ob1>0;ob1--)
- for(ob2=ob1-1;ob2>=0;ob2--)
- if(CompareA(ob1,ob2,red))
- if(!CompareA(ob1,ob2,P))
- { CloseSetA(P);
- return 0;
- }
- CloseSetA(P);
- return 1;
- }
+{
+ int ob1, ob2;
+ setA P = InitFullSetA();
+ DifSetA(P, P, red);
+ if (_mainsys->matA == NULL)
+ ERROR(5);
+ for (ob1 = _mainsys->objects_num - 1; ob1 > 0; ob1--)
+ for (ob2 = ob1 - 1; ob2 >= 0; ob2--)
+ if (CompareA(ob1, ob2, red))
+ if (!CompareA(ob1, ob2, P)) {
+ CloseSetA(P);
+ return 0;
+ }
+ CloseSetA(P);
+ return 1;
+}
+
int IsCoverDX(setA red, int matrix_type)
- { if(matrix_type==MATD)
- { if (_mainsys->matD==NULL) ERROR(6)
- START_OF_D;
- }
- else
- { if (_mainsys->matX==NULL) ERROR(7)
- START_OF_X;
- }
- for(;END_OF_MAT;NEXT_OF_MAT)
- if( !IsEmptySetA(ELEM_OF_MAT) )
- if(!InterSetA(ELEM_OF_MAT,red))
- return 0;
- return 1;
- }
+{
+ if (matrix_type == MATD) {
+ if (_mainsys->matD == NULL)
+ ERROR(6)
+ START_OF_D;
+ }
+ else {
+ if (_mainsys->matX == NULL)
+ ERROR(7)
+ START_OF_X;
+ }
+ for (; END_OF_MAT; NEXT_OF_MAT)
+ if (!IsEmptySetA(ELEM_OF_MAT))
+ if (!InterSetA(ELEM_OF_MAT, red))
+ return 0;
+ return 1;
+}
-int IsCoverRel(setA red,setA P,setA Q,int matrix_type)
- { switch(matrix_type)
- { case MATA : return IsCoverRelA(red,P,Q);
- case MATD : return IsCoverRelD(red,P,Q);
- default : ERROR(8)
- }
- }
+int IsCoverRel(setA red, setA P, setA Q, int matrix_type)
+{
+ switch (matrix_type) {
+ case MATA:
+ return IsCoverRelA(red, P, Q);
+ case MATD:
+ return IsCoverRelD(red, P, Q);
+ default:
+ ERROR(8)
+ }
+}
-int IsCoverRelA(setA red,setA P,setA Q)
- { int ob1,ob2;
- setA Pprim;
- if(_mainsys->matA==NULL) ERROR(5);
- Pprim=InitEmptySetA();
- DifSetA(Pprim,P,red);
- for(ob1=_mainsys->objects_num-1;ob1>0;ob1--)
- for(ob2=ob1-1;ob2>=0;ob2--)
- if(!CompareA(ob1,ob2,Q))
- if(CompareA(ob1,ob2,red))
- if(!CompareA(ob1,ob2,Pprim))
- { CloseSetA(Pprim);
- return 0;
- }
- CloseSetA(Pprim);
- return 1;
- }
+int IsCoverRelA(setA red, setA P, setA Q)
+{
+ int ob1, ob2;
+ setA Pprim;
-int IsCoverRelD(setA red,setA P,setA Q)
- { if(_mainsys->matD==NULL) ERROR(6);
- for(START_OF_D;END_OF_MAT;NEXT_OF_MAT)
- if(InterSetA(ELEM_OF_MAT,Q))
- if(!InterSetA(ELEM_OF_MAT,red))
- if(InterSetA(ELEM_OF_MAT,P))
- return 0;
- return 1;
- }
+ if (_mainsys->matA == NULL)
+ ERROR(5);
+ Pprim = InitEmptySetA();
+ DifSetA(Pprim, P, red);
+ for (ob1 = _mainsys->objects_num - 1; ob1 > 0; ob1--)
+ for (ob2 = ob1 - 1; ob2 >= 0; ob2--)
+ if (!CompareA(ob1, ob2, Q))
+ if (CompareA(ob1, ob2, red))
+ if (!CompareA(ob1, ob2, Pprim)) {
+ CloseSetA(Pprim);
+ return 0;
+ }
+ CloseSetA(Pprim);
+ return 1;
+}
-int IsRed(setA red,int matrix_type)
-{ int result;
- setA over;
- if(!IsCover(red,matrix_type))
- return 0;
- over=InitEmptySetA();
- result=IsOrtho(red,over,matrix_type);
- CloseSetA(over);
- return result;
+int IsCoverRelD(setA red, setA P, setA Q)
+{
+ if (_mainsys->matD == NULL)
+ ERROR(6);
+ for (START_OF_D; END_OF_MAT; NEXT_OF_MAT)
+ if (InterSetA(ELEM_OF_MAT, Q))
+ if (!InterSetA(ELEM_OF_MAT, red))
+ if (InterSetA(ELEM_OF_MAT, P))
+ return 0;
+ return 1;
}
+int IsRed(setA red, int matrix_type)
+{
+ int result;
+ setA over;
-int IsRedRel(setA red,setA P,setA Q,int matrix_type)
- { int result;
- setA over;
- if(!IsCoverRel(red,P,Q,matrix_type))
- return 0;
- over=InitEmptySetA();
- result=IsOrthoRel(red,over,P,Q,matrix_type);
- CloseSetA(over);
- return result;
- }
+ if (!IsCover(red, matrix_type))
+ return 0;
+ over = InitEmptySetA();
+ result = IsOrtho(red, over, matrix_type);
+ CloseSetA(over);
+ return result;
+}
+
+
+int IsRedRel(setA red, setA P, setA Q, int matrix_type)
+{
+ int result;
+ setA over;
+
+ if (!IsCoverRel(red, P, Q, matrix_type))
+ return 0;
+ over = InitEmptySetA();
+ result = IsOrthoRel(red, over, P, Q, matrix_type);
+ CloseSetA(over);
+ return result;
+}
Modified: grass-addons/raster/mcda/r.roughset/rcore.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rcore.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rcore.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,51 +16,65 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SOME MORE QUERIES FOR SYSTEM ***/
+
/*** ( FINDING CORES AND CHECKING REDUCTS ) ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
-int Core (setA core,int matrix_type);
-int CoreA (setA core);
-int CoreDX(setA core,int matrix_type);
+int Core(setA core, int matrix_type);
+int CoreA(setA core);
+int CoreDX(setA core, int matrix_type);
+
/* finds a core of all attributes */
-int CoreRel (setA core,setA P,setA Q,int matrix_type);
-int CoreRelA(setA core,setA P,setA Q);
-int CoreRelD(setA core,setA P,setA Q);
+int CoreRel(setA core, setA P, setA Q, int matrix_type);
+int CoreRelA(setA core, setA P, setA Q);
+int CoreRelD(setA core, setA P, setA Q);
+
/* finds a core of P relativly to Q */
-int IsOrtho(setA red,setA over,int matrix_type);
+int IsOrtho(setA red, setA over, int matrix_type);
+
/* return 1 if red is orthogonal */
/* otherwise returns 0 */
-int IsOrthoRel(setA red,setA over,setA P,setA Q,int matrix_type);
+int IsOrthoRel(setA red, setA over, setA P, setA Q, int matrix_type);
+
/* return 1 if red is Q-orthogonal in P */
/* otherwise returns 0 */
-int IsCover (setA red,int matrix_type);
-int IsCoverA (setA red);
-int IsCoverDX(setA red,int matrix_type);
+int IsCover(setA red, int matrix_type);
+int IsCoverA(setA red);
+int IsCoverDX(setA red, int matrix_type);
+
/* return 1 if red is a cover */
/* otherwise returns 0 */
-int IsCoverRel (setA red,setA P,setA Q,int matrix_type);
-int IsCoverRelA(setA red,setA P,setA Q);
-int IsCoverRelD(setA red,setA P,setA Q);
+int IsCoverRel(setA red, setA P, setA Q, int matrix_type);
+int IsCoverRelA(setA red, setA P, setA Q);
+int IsCoverRelD(setA red, setA P, setA Q);
+
/* return 1 if red is Q-cover in P */
/* otherwise returns 0 */
-int IsRed(setA red,int matrix_type);
+int IsRed(setA red, int matrix_type);
+
/* returns 1 if red is a reduct */
/* otherwise returns 0 */
-int IsRedRel(setA red,setA P,setA Q,int matrix_type);
+int IsRedRel(setA red, setA P, setA Q, int matrix_type);
+
/* returns 1 if red is a Q-relative reduct of P */
/* otherwise returns 0 */
-
Modified: grass-addons/raster/mcda/r.roughset/reduct1.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/reduct1.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/reduct1.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,1023 +16,1151 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SOME MORE QUERIES FOR SYSTEM ***/
+
/*** ( FINDING REDUCTS ) ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
#include "rough.h"
#include <stdlib.h>
-
-int RedRel(setA *reducts,setA P,setA Q,int matrix_type)
-{ int MEMOKWANT=_mainsys->attributes_num*_mainsys->attributes_num,
- j,atr,
- over,size=_mainsys->setAsize,
- memoryN=1,memoryO=1, /* size of the allocated memory */
- newcount=0,oldcount; /* number of new/old reducts */
- int no_A=_mainsys->attributes_num;
- setA arg, /* arguments are elements of matrix*/
- oldhead, /* head of static list of reducts */
- oldtail, /* tail ends the old reducts list */
- el,el1, /* elements of this list */
- new_el, /* probably new element of the list*/
- newhead, /* begin of new reducts */
- newtail; /* tail of the list of new reducts */
- setA CORE,keep;
- CORE=InitEmptySetA();
- _rerror=0;
- CoreRel(CORE,P,Q,matrix_type);
- if (_rerror!=0) { CloseSetA(CORE); return(-_rerror); }
- if ((oldhead=(setA)malloc(MEMOKWANT))==NULL)
- { CloseSetA(CORE); ERROR(3); }
- if ((newhead=(setA)malloc(MEMOKWANT))==NULL)
- { free(oldhead); CloseSetA(CORE); ERROR(3);}
- new_el=InitEmptySetA();
- arg=InitEmptySetA();
- oldtail=oldhead;
- newtail=newhead;
- start_of_tab(matrix_type); /* initializing the reducts list */
- if ( !IsEmptySetA(CORE) )
- { CopySetA(oldtail,CORE);
- oldtail+=size,oldcount=1;
- }
- else do
- { AndSetA(arg,_table_element,P);
- oldcount=0;
- if (InterSetA(_table_element,Q))
- for(atr=0;atr<no_A;atr++)
- if ( ContSetA(arg,atr) )
- { ClearSetA(oldtail);
- AddSetA(oldtail,atr);
- oldtail+=size;
- oldcount++;
- }
- next_of_tab();
- }
- while ((oldcount==0) && end_of_tab());
- for(;end_of_tab();next_of_tab()) /* for each element of matD do */
- { AndSetA(arg,_table_element,P); /* take next element */
- over = 0;
- if ( InterSetA(CORE,arg) ) continue;
- if ( !InterSetA(_table_element,Q) ) continue;
- if ( IsEmptySetA(arg) ) continue;
- el=oldhead;
- while (el<oldtail) /* compare arg to all the old reducts */
- { if ( !InterSetA(el,arg) )
- { for(atr=0;atr<no_A;atr++) /* for each atribute of arg */
- if ( ContSetA(arg,atr) )
- { CopySetA(new_el,el); /* creating potentialy new reduct */
- AddSetA(new_el,atr);
- over=0;
- el1=oldhead;
- while ((el1!=el) && !over) /* comparing new reduct to old reducts */
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- el1=el+size;
- while ((el1!=oldtail) && !over)
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- if (!over) /* appending new reduct */
- { newcount++;
- if (newcount*size*_cluster_bytes>memoryN*MEMOKWANT)
- { keep=newhead;
- if ((newhead=(setA)realloc(keep,MEMOKWANT*(++memoryN)))==NULL)
- { free(oldhead);
- CloseSetA(new_el);
- CloseSetA(arg);
- CloseSetA(CORE); ERROR(3);
- }
- if (keep!=newhead) newtail=newhead+(newcount-1)*size;
- }
- CopySetA(newtail,new_el);
- newtail+=size;
- }
+int RedRel(setA * reducts, setA P, setA Q, int matrix_type)
+{
+ int MEMOKWANT = _mainsys->attributes_num * _mainsys->attributes_num, j, atr, over, size = _mainsys->setAsize, memoryN = 1, memoryO = 1, /* size of the allocated memory */
+ newcount = 0, oldcount; /* number of new/old reducts */
+ int no_A = _mainsys->attributes_num;
+ setA arg, /* arguments are elements of matrix */
+ oldhead, /* head of static list of reducts */
+ oldtail, /* tail ends the old reducts list */
+ el, el1, /* elements of this list */
+ new_el, /* probably new element of the list */
+ newhead, /* begin of new reducts */
+ newtail; /* tail of the list of new reducts */
+ setA CORE, keep;
+
+ CORE = InitEmptySetA();
+ _rerror = 0;
+ CoreRel(CORE, P, Q, matrix_type);
+ if (_rerror != 0) {
+ CloseSetA(CORE);
+ return (-_rerror);
+ }
+ if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL) {
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if ((newhead = (setA) malloc(MEMOKWANT)) == NULL) {
+ free(oldhead);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ new_el = InitEmptySetA();
+ arg = InitEmptySetA();
+ oldtail = oldhead;
+ newtail = newhead;
+ start_of_tab(matrix_type); /* initializing the reducts list */
+ if (!IsEmptySetA(CORE)) {
+ CopySetA(oldtail, CORE);
+ oldtail += size, oldcount = 1;
+ }
+ else
+ do {
+ AndSetA(arg, _table_element, P);
+ oldcount = 0;
+ if (InterSetA(_table_element, Q))
+ for (atr = 0; atr < no_A; atr++)
+ if (ContSetA(arg, atr)) {
+ ClearSetA(oldtail);
+ AddSetA(oldtail, atr);
+ oldtail += size;
+ oldcount++;
+ }
+ next_of_tab();
+ }
+ while ((oldcount == 0) && end_of_tab());
+ for (; end_of_tab(); next_of_tab()) { /* for each element of matD do */
+ AndSetA(arg, _table_element, P); /* take next element */
+ over = 0;
+ if (InterSetA(CORE, arg))
+ continue;
+ if (!InterSetA(_table_element, Q))
+ continue;
+ if (IsEmptySetA(arg))
+ continue;
+ el = oldhead;
+ while (el < oldtail) { /* compare arg to all the old reducts */
+ if (!InterSetA(el, arg)) {
+ for (atr = 0; atr < no_A; atr++) /* for each atribute of arg */
+ if (ContSetA(arg, atr)) {
+ CopySetA(new_el, el); /* creating potentialy new reduct */
+ AddSetA(new_el, atr);
+ over = 0;
+ el1 = oldhead;
+ while ((el1 != el) && !over) { /* comparing new reduct to old reducts */
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ el1 = el + size;
+ while ((el1 != oldtail) && !over) {
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ if (!over) { /* appending new reduct */
+ newcount++;
+ if (newcount * size * _cluster_bytes >
+ memoryN * MEMOKWANT) {
+ keep = newhead;
+ if ((newhead =
+ (setA) realloc(keep,
+ MEMOKWANT *
+ (++memoryN))) == NULL) {
+ free(oldhead);
+ CloseSetA(new_el);
+ CloseSetA(arg);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if (keep != newhead)
+ newtail = newhead + (newcount - 1) * size;
+ }
+ CopySetA(newtail, new_el);
+ newtail += size;
+ }
+ }
}
- }
- else /* if reduct covers arg - rewrite it */
- { newcount++;
- if (newcount*size*_cluster_bytes>memoryN*MEMOKWANT)
- { keep=newhead;
- if ((newhead=(setA)realloc(keep,MEMOKWANT*(++memoryN)))==NULL)
- { free(oldhead);
- CloseSetA(new_el);
- CloseSetA(arg);
- CloseSetA(CORE);
- ERROR(3);
- }
- if (keep!=newhead) newtail=newhead+(newcount-1)*size;
+ else { /* if reduct covers arg - rewrite it */
+ newcount++;
+ if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT) {
+ keep = newhead;
+ if ((newhead =
+ (setA) realloc(keep,
+ MEMOKWANT * (++memoryN))) == NULL) {
+ free(oldhead);
+ CloseSetA(new_el);
+ CloseSetA(arg);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if (keep != newhead)
+ newtail = newhead + (newcount - 1) * size;
+ }
+ CopySetA(newtail, el);
+ newtail += size;
}
- CopySetA(newtail,el);
- newtail+=size;
- }
- el+=size;
- }
- oldtail=newhead;/* new reducts list becomes old */
- newhead=oldhead;
- oldhead=oldtail;
- oldtail=newtail;
- newtail=newhead;
- oldcount=newcount;
- newcount=0;
- j=memoryO;
- memoryO=memoryN;
- memoryN=j;
- }
- if (oldcount==0)
- { free(oldhead);
- *reducts=NULL;
- }
- else
- *reducts=oldhead;
- free(newhead);
- CloseSetA(CORE);
- CloseSetA(arg);
- CloseSetA(new_el);
- return (oldcount);
+ el += size;
+ }
+ oldtail = newhead; /* new reducts list becomes old */
+ newhead = oldhead;
+ oldhead = oldtail;
+ oldtail = newtail;
+ newtail = newhead;
+ oldcount = newcount;
+ newcount = 0;
+ j = memoryO;
+ memoryO = memoryN;
+ memoryN = j;
+ }
+ if (oldcount == 0) {
+ free(oldhead);
+ *reducts = NULL;
+ }
+ else
+ *reducts = oldhead;
+ free(newhead);
+ CloseSetA(CORE);
+ CloseSetA(arg);
+ CloseSetA(new_el);
+ return (oldcount);
}
-int Red(setA *reducts,int matrix_type)
- {int j, MEMOKWANT=_mainsys->attributes_num*_mainsys->attributes_num,
- atr,
- over,size=_mainsys->setAsize,
- memoryN=1,memoryO=1, /* size of the allocated memory */
- newcount=0,oldcount; /* number of new/old reducts */
- int no_A=_mainsys->attributes_num;
- setA oldhead, /* head of static list of reducts */
- oldtail, /* tail ends the old reducts list */
- el,el1, /* elements of this list */
- new_el, /* probably new element of the list*/
- newhead, /* begin of new reducts */
- newtail; /* tail of the list of new reducts */
- setA CORE,keep,and,redprim;
+int Red(setA * reducts, int matrix_type)
+{
+ int j, MEMOKWANT = _mainsys->attributes_num * _mainsys->attributes_num, atr, over, size = _mainsys->setAsize, memoryN = 1, memoryO = 1, /* size of the allocated memory */
+ newcount = 0, oldcount; /* number of new/old reducts */
+ int no_A = _mainsys->attributes_num;
+ setA oldhead, /* head of static list of reducts */
+ oldtail, /* tail ends the old reducts list */
+ el, el1, /* elements of this list */
+ new_el, /* probably new element of the list */
+ newhead, /* begin of new reducts */
+ newtail; /* tail of the list of new reducts */
+ setA CORE, keep, and, redprim;
- CORE=InitEmptySetA();
- _rerror=0;
- Core(CORE,matrix_type);
- if (_rerror!=0)
- { CloseSetA(CORE); return(-_rerror); }
- if ((oldhead=(setA)malloc(MEMOKWANT))==NULL)
- { CloseSetA(CORE);
- keep=NULL;
- ERROR(3);
+ CORE = InitEmptySetA();
+ _rerror = 0;
+ Core(CORE, matrix_type);
+ if (_rerror != 0) {
+ CloseSetA(CORE);
+ return (-_rerror);
}
- if ((newhead=(setA)malloc(MEMOKWANT))==NULL)
- { free(oldhead);
- CloseSetA(CORE);
- ERROR(3);
+ if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL) {
+ CloseSetA(CORE);
+ keep = NULL;
+ ERROR(3);
}
- new_el=InitEmptySetA();
- and=InitEmptySetA();
- redprim=InitEmptySetA();
- oldtail=oldhead;
- newtail=newhead;
- start_of_tab(matrix_type);
- if ( !IsEmptySetA(CORE) ) /* initializing of the reducts list */
- { CopySetA(oldtail,CORE);
- oldtail+=size,oldcount=1;
- }
- else do
- { oldcount=0;
- for(atr=0;atr<no_A;atr++)
- if ( ContSetA(_table_element,atr) )
- { ClearSetA(oldtail);
- AddSetA(oldtail,atr);
- oldtail+=size;
- oldcount++;
- }
- next_of_tab();
- }
- while ((oldcount==0) && end_of_tab());
- for(;end_of_tab();next_of_tab()) /* for each element of matrix */
- { over = 0;
- if ( InterSetA(CORE,_table_element) ) continue;
- if ( IsEmptySetA(_table_element) ) continue;
- el=oldhead;
- while (el<oldtail) /* compare _table_element to all the old reducts */
- { if ( !InterSetA(el,_table_element) ) /* old reduct does not cover new element */
- { for(atr=0;atr<no_A;atr++) /* for each atribute of _table_element */
- if ( ContSetA(_table_element,atr) )
- { CopySetA(new_el,el); /* creating potentialy new reduct */
- AddSetA(new_el,atr);
- over=0;
- el1=oldhead;
- /* if ( matrix_type==MATX && (_mainsys->matXsize<(oldtail-oldhead)))
- { ClearSetA( redprim );
- for(el1=_mainsys->matX;el1<_table_end;el1+=size)
- { AndSetA( and, el1, new_el );
- if ( CardSetA( and ) == 1 ) OrSetA( redprim, redprim, and );
- }
- over = !CompSetA( redprim, new_el );
- }
- else
- */
- { while ((el1!=el) && !over) /* comparing new reduct to all the old reducts */
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- el1=el+size;
- while ((el1!=oldtail) && !over)
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- }
- if (!over) /* appending new reduct */
- { newcount++;
- if (newcount*size*_cluster_bytes>memoryN*MEMOKWANT)
- { keep=newhead;
- if ((newhead=(setA)realloc(keep,MEMOKWANT*(++memoryN)))==NULL)
- { free(oldhead);
- CloseSetA(new_el);
- CloseSetA(CORE); ERROR(3);
- }
- if (keep!=newhead) newtail=newhead+(newcount-1)*size;
- }
- CopySetA(newtail,new_el);
- newtail+=size;
- }
+ if ((newhead = (setA) malloc(MEMOKWANT)) == NULL) {
+ free(oldhead);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ new_el = InitEmptySetA();
+ and = InitEmptySetA();
+ redprim = InitEmptySetA();
+ oldtail = oldhead;
+ newtail = newhead;
+ start_of_tab(matrix_type);
+ if (!IsEmptySetA(CORE)) { /* initializing of the reducts list */
+ CopySetA(oldtail, CORE);
+ oldtail += size, oldcount = 1;
+ }
+ else
+ do {
+ oldcount = 0;
+ for (atr = 0; atr < no_A; atr++)
+ if (ContSetA(_table_element, atr)) {
+ ClearSetA(oldtail);
+ AddSetA(oldtail, atr);
+ oldtail += size;
+ oldcount++;
+ }
+ next_of_tab();
+ }
+ while ((oldcount == 0) && end_of_tab());
+ for (; end_of_tab(); next_of_tab()) { /* for each element of matrix */
+ over = 0;
+ if (InterSetA(CORE, _table_element))
+ continue;
+ if (IsEmptySetA(_table_element))
+ continue;
+ el = oldhead;
+ while (el < oldtail) { /* compare _table_element to all the old reducts */
+ if (!InterSetA(el, _table_element)) { /* old reduct does not cover new element */
+ for (atr = 0; atr < no_A; atr++) /* for each atribute of _table_element */
+ if (ContSetA(_table_element, atr)) {
+ CopySetA(new_el, el); /* creating potentialy new reduct */
+ AddSetA(new_el, atr);
+ over = 0;
+ el1 = oldhead;
+ /* if ( matrix_type==MATX && (_mainsys->matXsize<(oldtail-oldhead)))
+ { ClearSetA( redprim );
+ for(el1=_mainsys->matX;el1<_table_end;el1+=size)
+ { AndSetA( and, el1, new_el );
+ if ( CardSetA( and ) == 1 ) OrSetA( redprim, redprim, and );
+ }
+ over = !CompSetA( redprim, new_el );
+ }
+ else
+ */
+ {
+ while ((el1 != el) && !over) { /* comparing new reduct to all the old reducts */
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ el1 = el + size;
+ while ((el1 != oldtail) && !over) {
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ }
+ if (!over) { /* appending new reduct */
+ newcount++;
+ if (newcount * size * _cluster_bytes >
+ memoryN * MEMOKWANT) {
+ keep = newhead;
+ if ((newhead =
+ (setA) realloc(keep,
+ MEMOKWANT *
+ (++memoryN))) == NULL) {
+ free(oldhead);
+ CloseSetA(new_el);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if (keep != newhead)
+ newtail = newhead + (newcount - 1) * size;
+ }
+ CopySetA(newtail, new_el);
+ newtail += size;
+ }
+ }
}
- }
- else /* old reduct covers new element */
- { newcount++;
- if (newcount*size*_cluster_bytes>memoryN*MEMOKWANT)
- { keep=newhead;
- if ((newhead=(setA)realloc(keep,MEMOKWANT*(++memoryN)))==NULL)
- { free(oldhead);
- CloseSetA(new_el);
- CloseSetA(CORE); ERROR(3);
- }
- if (keep!=newhead) newtail=newhead+(newcount-1)*size;
+ else { /* old reduct covers new element */
+ newcount++;
+ if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT) {
+ keep = newhead;
+ if ((newhead =
+ (setA) realloc(keep,
+ MEMOKWANT * (++memoryN))) == NULL) {
+ free(oldhead);
+ CloseSetA(new_el);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if (keep != newhead)
+ newtail = newhead + (newcount - 1) * size;
+ }
+ CopySetA(newtail, el);
+ newtail += size;
}
- CopySetA(newtail,el);
- newtail+=size;
- }
- el+=size;
- }
- oldtail=newhead; /* new reducts list becomes old */
- newhead=oldhead;
- oldhead=oldtail;
- oldtail=newtail;
- newtail=newhead;
- oldcount=newcount;
- newcount=0;
- j=memoryO;
- memoryO=memoryN;
- memoryN=j;
- }
- if (oldcount==0)
- { free(oldhead); *reducts=NULL; }
- else
- *reducts=oldhead;
- free(newhead);
- CloseSetA(CORE);
- CloseSetA(new_el);
- CloseSetA(redprim);
- CloseSetA(and);
- return (oldcount);
+ el += size;
+ }
+ oldtail = newhead; /* new reducts list becomes old */
+ newhead = oldhead;
+ oldhead = oldtail;
+ oldtail = newtail;
+ newtail = newhead;
+ oldcount = newcount;
+ newcount = 0;
+ j = memoryO;
+ memoryO = memoryN;
+ memoryN = j;
+ }
+ if (oldcount == 0) {
+ free(oldhead);
+ *reducts = NULL;
+ }
+ else
+ *reducts = oldhead;
+ free(newhead);
+ CloseSetA(CORE);
+ CloseSetA(new_el);
+ CloseSetA(redprim);
+ CloseSetA(and);
+ return (oldcount);
}
-int RedRelLess(setA *reducts,setA P,setA Q,int N,int matrix_type)
-{ int j, MEMOKWANT=_mainsys->attributes_num*_mainsys->attributes_num,
- atr,
- over,size=_mainsys->setAsize,
- memoryN=1,memoryO=1, /* size of the allocated memory */
- newcount=0,oldcount; /* number of new/old reducts */
- int no_A=_mainsys->attributes_num;
- setA arg, /* arguments are elements of matrix*/
- oldhead, /* head of static list of reducts */
- oldtail, /* tail ends the old reducts list */
- el,el1, /* elements of this list */
- new_el, /* probably new element of the list*/
- newhead, /* begin of new reducts */
- newtail; /* tail of the list of new reducts */
- setA CORE,keep;
+int RedRelLess(setA * reducts, setA P, setA Q, int N, int matrix_type)
+{
+ int j, MEMOKWANT = _mainsys->attributes_num * _mainsys->attributes_num, atr, over, size = _mainsys->setAsize, memoryN = 1, memoryO = 1, /* size of the allocated memory */
+ newcount = 0, oldcount; /* number of new/old reducts */
+ int no_A = _mainsys->attributes_num;
+ setA arg, /* arguments are elements of matrix */
+ oldhead, /* head of static list of reducts */
+ oldtail, /* tail ends the old reducts list */
+ el, el1, /* elements of this list */
+ new_el, /* probably new element of the list */
+ newhead, /* begin of new reducts */
+ newtail; /* tail of the list of new reducts */
+ setA CORE, keep;
- CORE=InitEmptySetA();
- _rerror=0;
- CoreRel(CORE,P,Q,matrix_type);
- if (_rerror!=0) { CloseSetA(CORE); return(-_rerror); }
- if ( CardSetA(CORE)>N ) { free(CORE); return(0); }
- if ((oldhead=(setA)malloc(MEMOKWANT))==NULL)
- { CloseSetA(CORE); ERROR(3); }
- if ((newhead=(setA)malloc(MEMOKWANT))==NULL)
- { free(oldhead);
- CloseSetA(CORE);
- ERROR(3);
- }
- new_el=InitEmptySetA();
- arg=InitEmptySetA();
- oldtail=oldhead;
- newtail=newhead;
- start_of_tab(matrix_type);
- if ( !IsEmptySetA(CORE) )
- { CopySetA(oldtail,CORE);
- oldtail+=size,oldcount=1;
- }
- else do
- { AndSetA(arg,_table_element,P);
- oldcount=0;
- if (InterSetA(_table_element,Q))
- for(atr=0;atr<no_A;atr++)
- if ( ContSetA(arg,atr) )
- { ClearSetA(oldtail);
- AddSetA(oldtail,atr);
- oldtail+=size;
- oldcount++;
- }
- next_of_tab();
- }
- while ((oldcount==0) && end_of_tab());
- for(;end_of_tab();next_of_tab()) /* for each element of matrix do */
- { AndSetA(arg,_table_element,P); /* take next element */
- over = 0;
- if ( InterSetA(CORE,arg) ) continue;
- if ( !InterSetA(_table_element,Q) ) continue;
- if ( IsEmptySetA(arg) ) continue;
- el=oldhead;
- while (el<oldtail) /* compare arg to all old reducts */
- { if ( !InterSetA(el,arg) ) /* old reduct does not cover new element */
- { if ( CardSetA(el)<N ) /* shorter elements should be corected */
- for(atr=0;atr<no_A;atr++) /* for each atribute of arg */
- if ( ContSetA(arg,atr) )
- { CopySetA(new_el,el); /* creating potentialy new reduct */
- AddSetA(new_el,atr);
- over=0;
- el1=oldhead;
- while ((el1!=el) && !over) /* comparing new reduct to all the old list */
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- el1=el+size;
- while ((el1!=oldtail) && !over)
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- if (!over) /* appending to new list */
- { newcount++;
- if (newcount*size*_cluster_bytes>memoryN*MEMOKWANT)
- { keep=newhead;
- if ((newhead=(setA)realloc(keep,MEMOKWANT*(++memoryN)))==NULL)
- { free(oldhead);
- CloseSetA(new_el);
- CloseSetA(arg);
- CloseSetA(CORE);
- ERROR(3);
- }
- if (keep!=newhead) newtail=newhead+(newcount-1)*size;
+ CORE = InitEmptySetA();
+ _rerror = 0;
+ CoreRel(CORE, P, Q, matrix_type);
+ if (_rerror != 0) {
+ CloseSetA(CORE);
+ return (-_rerror);
+ }
+ if (CardSetA(CORE) > N) {
+ free(CORE);
+ return (0);
+ }
+ if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL) {
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if ((newhead = (setA) malloc(MEMOKWANT)) == NULL) {
+ free(oldhead);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ new_el = InitEmptySetA();
+ arg = InitEmptySetA();
+ oldtail = oldhead;
+ newtail = newhead;
+ start_of_tab(matrix_type);
+ if (!IsEmptySetA(CORE)) {
+ CopySetA(oldtail, CORE);
+ oldtail += size, oldcount = 1;
+ }
+ else
+ do {
+ AndSetA(arg, _table_element, P);
+ oldcount = 0;
+ if (InterSetA(_table_element, Q))
+ for (atr = 0; atr < no_A; atr++)
+ if (ContSetA(arg, atr)) {
+ ClearSetA(oldtail);
+ AddSetA(oldtail, atr);
+ oldtail += size;
+ oldcount++;
}
- CopySetA(newtail,new_el);
- newtail+=size;
- }
- }
- }
- else /* old reduct covers new element */
- { newcount++;
- if (newcount*size*_cluster_bytes>memoryN*MEMOKWANT)
- { keep=newhead;
- if ((newhead=(setA)realloc(keep,MEMOKWANT*(++memoryN)))==NULL)
- { free(oldhead);
- CloseSetA(new_el);
- CloseSetA(arg);
- CloseSetA(CORE); ERROR(3);
- }
- if (keep!=newhead) newtail=newhead+(newcount-1)*size;
- }
- CopySetA(newtail,el);
- newtail+=size;
- }
- el+=size;
- }
- oldtail=newhead; /* new list becomes old*/
- newhead=oldhead;
- oldhead=oldtail;
- oldtail=newtail;
- newtail=newhead;
- oldcount=newcount;
- newcount=0;
- j=memoryO;
- memoryO=memoryN;
- memoryN=j;
- }
- if (oldcount==0)
- { free(oldhead);
- *reducts=NULL;
- }
- else
- *reducts=oldhead;
- free(newhead);
- CloseSetA(CORE);
- CloseSetA(arg);
- CloseSetA(new_el);
- return (oldcount);
+ next_of_tab();
+ }
+ while ((oldcount == 0) && end_of_tab());
+ for (; end_of_tab(); next_of_tab()) { /* for each element of matrix do */
+ AndSetA(arg, _table_element, P); /* take next element */
+ over = 0;
+ if (InterSetA(CORE, arg))
+ continue;
+ if (!InterSetA(_table_element, Q))
+ continue;
+ if (IsEmptySetA(arg))
+ continue;
+ el = oldhead;
+ while (el < oldtail) { /* compare arg to all old reducts */
+ if (!InterSetA(el, arg)) { /* old reduct does not cover new element */
+ if (CardSetA(el) < N) /* shorter elements should be corected */
+ for (atr = 0; atr < no_A; atr++) /* for each atribute of arg */
+ if (ContSetA(arg, atr)) {
+ CopySetA(new_el, el); /* creating potentialy new reduct */
+ AddSetA(new_el, atr);
+ over = 0;
+ el1 = oldhead;
+ while ((el1 != el) && !over) { /* comparing new reduct to all the old list */
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ el1 = el + size;
+ while ((el1 != oldtail) && !over) {
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ if (!over) { /* appending to new list */
+ newcount++;
+ if (newcount * size * _cluster_bytes >
+ memoryN * MEMOKWANT) {
+ keep = newhead;
+ if ((newhead =
+ (setA) realloc(keep,
+ MEMOKWANT *
+ (++memoryN))) ==
+ NULL) {
+ free(oldhead);
+ CloseSetA(new_el);
+ CloseSetA(arg);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if (keep != newhead)
+ newtail =
+ newhead + (newcount - 1) * size;
+ }
+ CopySetA(newtail, new_el);
+ newtail += size;
+ }
+ }
+ }
+ else { /* old reduct covers new element */
+ newcount++;
+ if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT) {
+ keep = newhead;
+ if ((newhead =
+ (setA) realloc(keep,
+ MEMOKWANT * (++memoryN))) == NULL) {
+ free(oldhead);
+ CloseSetA(new_el);
+ CloseSetA(arg);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if (keep != newhead)
+ newtail = newhead + (newcount - 1) * size;
+ }
+ CopySetA(newtail, el);
+ newtail += size;
+ }
+ el += size;
+ }
+ oldtail = newhead; /* new list becomes old */
+ newhead = oldhead;
+ oldhead = oldtail;
+ oldtail = newtail;
+ newtail = newhead;
+ oldcount = newcount;
+ newcount = 0;
+ j = memoryO;
+ memoryO = memoryN;
+ memoryN = j;
+ }
+ if (oldcount == 0) {
+ free(oldhead);
+ *reducts = NULL;
+ }
+ else
+ *reducts = oldhead;
+ free(newhead);
+ CloseSetA(CORE);
+ CloseSetA(arg);
+ CloseSetA(new_el);
+ return (oldcount);
}
-int RedLess(setA *reducts,int N,int matrix_type)
-{ int j, MEMOKWANT=_mainsys->attributes_num*_mainsys->attributes_num,
- atr,
- over,size=_mainsys->setAsize,
- memoryN=1,memoryO=1, /* size of the allocated memory */
- newcount=0,oldcount; /* number of new/old reducts */
- int no_A=_mainsys->attributes_num;
- setA oldhead, /* head of static list of reducts */
- oldtail, /* tail ends the old reducts list */
- el,el1, /* elements of this list */
- new_el, /* probably new element of the list*/
- newhead, /* begin of new reducts */
- newtail; /* tail of the list of new reducts */
- setA CORE,keep;
-
- CORE=InitEmptySetA();
- _rerror=0;
- Core(CORE,matrix_type);
- if (_rerror!=0) { CloseSetA(CORE); return(-_rerror); }
- if ( CardSetA(CORE)>N ) { free(CORE); return(0); }
- if ((oldhead=(setA)malloc(MEMOKWANT))==NULL)
- { CloseSetA(CORE);
- ERROR(3);
- }
- if ((newhead=(setA)malloc(MEMOKWANT))==NULL)
- { free(oldhead);
- CloseSetA(CORE); ERROR(3);
- }
- new_el=InitEmptySetA();
- oldtail=oldhead;
- newtail=newhead;
- start_of_tab(matrix_type);
- if ( !IsEmptySetA(CORE) ) /*initializing the reducts list */
- { CopySetA(oldtail,CORE);
- oldtail+=size;
- oldcount=1;
- }
- else do
- { oldcount=0;
- for(atr=0;atr<no_A;atr++)
- if ( ContSetA(_table_element,atr) )
- { ClearSetA(oldtail);
- AddSetA(oldtail,atr);
- oldtail+=size;
- oldcount++;
- }
- next_of_tab();
- }
- while ((oldcount==0) && end_of_tab());
- for(;end_of_tab();next_of_tab()) /* for each element of matD do */
- { over = 0;
- if ( InterSetA(_table_element,CORE) ) continue;
- if ( IsEmptySetA(_table_element) ) continue;
- el=oldhead;
- while (el<oldtail) /* compare _table_element to all the old reducts */
- { if ( !InterSetA(el,_table_element) ) /* old reduct does not cover new element */
- { if ( CardSetA(el)<N )
- for(atr=0;atr<no_A;atr++) /* for each atribute of element */
- if ( ContSetA(_table_element,atr) )
- { CopySetA(new_el,el); /* creating potentialy new reduct */
- AddSetA(new_el,atr);
- over=0;
- el1=oldhead; /* comparing new reduct to the old reducts */
- while ((el1!=el) && !over)
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- el1=el+size;
- while ((el1!=oldtail) && !over)
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- if (!over) /* appending new reduct to list */
- { newcount++;
- if (newcount*size*_cluster_bytes>memoryN*MEMOKWANT)
- { keep=newhead;
- if ((newhead=(setA)realloc(keep,MEMOKWANT*(++memoryN)))==NULL)
- { free(oldhead);
- CloseSetA(new_el);
- CloseSetA(CORE);
- ERROR(3);
- }
- if (keep!=newhead) newtail=newhead+(newcount-1)*size;
+int RedLess(setA * reducts, int N, int matrix_type)
+{
+ int j, MEMOKWANT = _mainsys->attributes_num * _mainsys->attributes_num, atr, over, size = _mainsys->setAsize, memoryN = 1, memoryO = 1, /* size of the allocated memory */
+ newcount = 0, oldcount; /* number of new/old reducts */
+ int no_A = _mainsys->attributes_num;
+ setA oldhead, /* head of static list of reducts */
+ oldtail, /* tail ends the old reducts list */
+ el, el1, /* elements of this list */
+ new_el, /* probably new element of the list */
+ newhead, /* begin of new reducts */
+ newtail; /* tail of the list of new reducts */
+ setA CORE, keep;
+
+ CORE = InitEmptySetA();
+ _rerror = 0;
+ Core(CORE, matrix_type);
+ if (_rerror != 0) {
+ CloseSetA(CORE);
+ return (-_rerror);
+ }
+ if (CardSetA(CORE) > N) {
+ free(CORE);
+ return (0);
+ }
+ if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL) {
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if ((newhead = (setA) malloc(MEMOKWANT)) == NULL) {
+ free(oldhead);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ new_el = InitEmptySetA();
+ oldtail = oldhead;
+ newtail = newhead;
+ start_of_tab(matrix_type);
+ if (!IsEmptySetA(CORE)) { /*initializing the reducts list */
+ CopySetA(oldtail, CORE);
+ oldtail += size;
+ oldcount = 1;
+ }
+ else
+ do {
+ oldcount = 0;
+ for (atr = 0; atr < no_A; atr++)
+ if (ContSetA(_table_element, atr)) {
+ ClearSetA(oldtail);
+ AddSetA(oldtail, atr);
+ oldtail += size;
+ oldcount++;
+ }
+ next_of_tab();
+ }
+ while ((oldcount == 0) && end_of_tab());
+ for (; end_of_tab(); next_of_tab()) { /* for each element of matD do */
+ over = 0;
+ if (InterSetA(_table_element, CORE))
+ continue;
+ if (IsEmptySetA(_table_element))
+ continue;
+ el = oldhead;
+ while (el < oldtail) { /* compare _table_element to all the old reducts */
+ if (!InterSetA(el, _table_element)) { /* old reduct does not cover new element */
+ if (CardSetA(el) < N)
+ for (atr = 0; atr < no_A; atr++) /* for each atribute of element */
+ if (ContSetA(_table_element, atr)) {
+ CopySetA(new_el, el); /* creating potentialy new reduct */
+ AddSetA(new_el, atr);
+ over = 0;
+ el1 = oldhead; /* comparing new reduct to the old reducts */
+ while ((el1 != el) && !over) {
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ el1 = el + size;
+ while ((el1 != oldtail) && !over) {
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ if (!over) { /* appending new reduct to list */
+ newcount++;
+ if (newcount * size * _cluster_bytes >
+ memoryN * MEMOKWANT) {
+ keep = newhead;
+ if ((newhead =
+ (setA) realloc(keep,
+ MEMOKWANT *
+ (++memoryN))) ==
+ NULL) {
+ free(oldhead);
+ CloseSetA(new_el);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if (keep != newhead)
+ newtail =
+ newhead + (newcount - 1) * size;
+ }
+ CopySetA(newtail, new_el);
+ newtail += size;
+ }
+ }
+ }
+ else { /* old reduct covers new element */
+ newcount++;
+ if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT) {
+ keep = newhead;
+ if ((newhead =
+ (setA) realloc(keep,
+ MEMOKWANT * (++memoryN))) == NULL) {
+ free(oldhead);
+ CloseSetA(new_el);
+ CloseSetA(CORE);
+ ERROR(3);
}
- CopySetA(newtail,new_el);
- newtail+=size;
- }
- }
- }
- else /* old reduct covers new element */
- { newcount++;
- if (newcount*size*_cluster_bytes>memoryN*MEMOKWANT)
- { keep=newhead;
- if ((newhead=(setA)realloc(keep,MEMOKWANT*(++memoryN)))==NULL)
- { free(oldhead);
- CloseSetA(new_el);
- CloseSetA(CORE); ERROR(3);
- }
- if (keep!=newhead) newtail=newhead+(newcount-1)*size;
- }
- CopySetA(newtail,el);
- newtail+=size;
- }
- el+=size;
- }
- oldtail=newhead; /* new list becomes old */
- newhead=oldhead;
- oldhead=oldtail;
- oldtail=newtail;
- newtail=newhead;
- oldcount=newcount;
- newcount=0;
- j=memoryO;
- memoryO=memoryN;
- memoryN=j;
- }
- if (oldcount==0)
- { free(oldhead);
- *reducts=NULL;
- }
- else
- *reducts=oldhead;
- free(newhead);
- CloseSetA(CORE);
- CloseSetA(new_el);
- return (oldcount);
+ if (keep != newhead)
+ newtail = newhead + (newcount - 1) * size;
+ }
+ CopySetA(newtail, el);
+ newtail += size;
+ }
+ el += size;
+ }
+ oldtail = newhead; /* new list becomes old */
+ newhead = oldhead;
+ oldhead = oldtail;
+ oldtail = newtail;
+ newtail = newhead;
+ oldcount = newcount;
+ newcount = 0;
+ j = memoryO;
+ memoryO = memoryN;
+ memoryN = j;
+ }
+ if (oldcount == 0) {
+ free(oldhead);
+ *reducts = NULL;
+ }
+ else
+ *reducts = oldhead;
+ free(newhead);
+ CloseSetA(CORE);
+ CloseSetA(new_el);
+ return (oldcount);
}
-int RedRelSetA(setA *reducts,setA quasicore,setA P,setA Q,int matrix_type)
+int RedRelSetA(setA * reducts, setA quasicore, setA P, setA Q,
+ int matrix_type)
{
- int j, MEMOKWANT=_mainsys->attributes_num*_mainsys->attributes_num,
- atr,
- over,size=_mainsys->setAsize,
- memoryN=1,memoryO=1, /* size of the allocated memory */
- newcount=0,oldcount; /* number of new/old reducts */
- int no_A=_mainsys->attributes_num;
- setA arg, /* arguments are elements of matrix*/
- oldhead, /* head of static list of reducts */
- oldtail, /* tail ends the old reducts list */
- el,el1, /* elements of this list */
- new_el, /* probably new element of the list*/
- newhead, /* begin of new reducts */
- newtail; /* tail of the list of new reducts */
- setA CORE,keep;
+ int j, MEMOKWANT = _mainsys->attributes_num * _mainsys->attributes_num, atr, over, size = _mainsys->setAsize, memoryN = 1, memoryO = 1, /* size of the allocated memory */
+ newcount = 0, oldcount; /* number of new/old reducts */
+ int no_A = _mainsys->attributes_num;
+ setA arg, /* arguments are elements of matrix */
+ oldhead, /* head of static list of reducts */
+ oldtail, /* tail ends the old reducts list */
+ el, el1, /* elements of this list */
+ new_el, /* probably new element of the list */
+ newhead, /* begin of new reducts */
+ newtail; /* tail of the list of new reducts */
+ setA CORE, keep;
- CORE=InitEmptySetA();
- _rerror=0;
- CoreRel(CORE,P,Q,matrix_type);
- if (_rerror!=0)
- { CloseSetA(CORE);
- return(-_rerror);
+ CORE = InitEmptySetA();
+ _rerror = 0;
+ CoreRel(CORE, P, Q, matrix_type);
+ if (_rerror != 0) {
+ CloseSetA(CORE);
+ return (-_rerror);
}
- OrSetA(CORE,CORE,quasicore);
- if ((oldhead=(setA)malloc(MEMOKWANT))==NULL)
- { CloseSetA(CORE);
- ERROR(3);
+ OrSetA(CORE, CORE, quasicore);
+ if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL) {
+ CloseSetA(CORE);
+ ERROR(3);
}
- if ((newhead=(setA)malloc(MEMOKWANT))==NULL)
- { free(oldhead);
- CloseSetA(CORE);
- ERROR(3);
- }
- new_el=InitEmptySetA();
- arg=InitEmptySetA();
- oldtail=oldhead;
- newtail=newhead;
- start_of_tab(matrix_type);
- if ( !IsEmptySetA(CORE) ) /*initializing the reducts list */
- { CopySetA(oldtail,CORE);
- oldtail+=size;
- oldcount=1;
- }
- else do
- { AndSetA(arg,_table_element,P);
- oldcount=0;
- if (InterSetA(_table_element,Q))
- for(atr=0;atr<no_A;atr++)
- if ( ContSetA(arg,atr) )
- { ClearSetA(oldtail);
- AddSetA(oldtail,atr);
- oldtail+=size;
- oldcount++;
- }
- next_of_tab();
- }
- while ((oldcount==0) && end_of_tab());
- for(;end_of_tab();next_of_tab()) /* for each element of matrix do */
- { AndSetA(arg,_table_element,P); /* take next element */
- over = 0;
- if ( InterSetA(CORE,arg) ) continue;
- if ( !InterSetA(_table_element,Q) ) continue;
- if ( IsEmptySetA(arg) ) continue;
- el=oldhead;
- while (el<oldtail) /* compare element to all the old reducts */
- { if ( !InterSetA(el,arg) ) /* old reduct does not cover new element */
- { for(atr=0;atr<no_A;atr++)/* for each atribute of element */
- if ( ContSetA(arg,atr) )
- { CopySetA(new_el,el); /* creating potentialy new reduct */
- AddSetA(new_el,atr);
- over=0;
- el1=oldhead;
- while ((el1!=el) && !over)/* comparing new reduct to all the old reducts */
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- el1=el+size;
- while ((el1!=oldtail) && !over)
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- if (!over) /* appending new reduct to list */
- { newcount++;
- if (newcount*size*_cluster_bytes>memoryN*MEMOKWANT)
- { keep=newhead;
- if ((newhead=(setA)realloc(keep,MEMOKWANT*(++memoryN)))==NULL)
- { free(oldhead);
- CloseSetA(new_el);
- CloseSetA(arg);
- CloseSetA(CORE); ERROR(3);
- }
- if (keep!=newhead) newtail=newhead+(newcount-1)*size;
- }
- CopySetA(newtail,new_el);
- newtail+=size;
- }
+ if ((newhead = (setA) malloc(MEMOKWANT)) == NULL) {
+ free(oldhead);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ new_el = InitEmptySetA();
+ arg = InitEmptySetA();
+ oldtail = oldhead;
+ newtail = newhead;
+ start_of_tab(matrix_type);
+ if (!IsEmptySetA(CORE)) { /*initializing the reducts list */
+ CopySetA(oldtail, CORE);
+ oldtail += size;
+ oldcount = 1;
+ }
+ else
+ do {
+ AndSetA(arg, _table_element, P);
+ oldcount = 0;
+ if (InterSetA(_table_element, Q))
+ for (atr = 0; atr < no_A; atr++)
+ if (ContSetA(arg, atr)) {
+ ClearSetA(oldtail);
+ AddSetA(oldtail, atr);
+ oldtail += size;
+ oldcount++;
+ }
+ next_of_tab();
+ }
+ while ((oldcount == 0) && end_of_tab());
+ for (; end_of_tab(); next_of_tab()) { /* for each element of matrix do */
+ AndSetA(arg, _table_element, P); /* take next element */
+ over = 0;
+ if (InterSetA(CORE, arg))
+ continue;
+ if (!InterSetA(_table_element, Q))
+ continue;
+ if (IsEmptySetA(arg))
+ continue;
+ el = oldhead;
+ while (el < oldtail) { /* compare element to all the old reducts */
+ if (!InterSetA(el, arg)) { /* old reduct does not cover new element */
+ for (atr = 0; atr < no_A; atr++) /* for each atribute of element */
+ if (ContSetA(arg, atr)) {
+ CopySetA(new_el, el); /* creating potentialy new reduct */
+ AddSetA(new_el, atr);
+ over = 0;
+ el1 = oldhead;
+ while ((el1 != el) && !over) { /* comparing new reduct to all the old reducts */
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ el1 = el + size;
+ while ((el1 != oldtail) && !over) {
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ if (!over) { /* appending new reduct to list */
+ newcount++;
+ if (newcount * size * _cluster_bytes >
+ memoryN * MEMOKWANT) {
+ keep = newhead;
+ if ((newhead =
+ (setA) realloc(keep,
+ MEMOKWANT *
+ (++memoryN))) == NULL) {
+ free(oldhead);
+ CloseSetA(new_el);
+ CloseSetA(arg);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if (keep != newhead)
+ newtail = newhead + (newcount - 1) * size;
+ }
+ CopySetA(newtail, new_el);
+ newtail += size;
+ }
+ }
}
- }
- else /* old reduct covers new elemet */
- { newcount++;
- if (newcount*size*_cluster_bytes>memoryN*MEMOKWANT)
- { keep=newhead;
- if ((newhead=(setA)realloc(keep,MEMOKWANT*(++memoryN)))==NULL)
- { free(oldhead);
- CloseSetA(new_el);
- CloseSetA(arg);
- CloseSetA(CORE); ERROR(3);
- }
- if (keep!=newhead) newtail=newhead+(newcount-1)*size;
- }
- CopySetA(newtail,el);
- newtail+=size;
- }
- el+=size;
- }
- oldtail=newhead; /* new list becomes old */
- newhead=oldhead;
- oldhead=oldtail;
- oldtail=newtail;
- newtail=newhead;
- oldcount=newcount;
- newcount=0;
- j=memoryO;
- memoryO=memoryN;
- memoryN=j;
- }
- if (oldcount==0)
- { free(oldhead);
- *reducts=NULL;
- }
- else
- *reducts=oldhead;
- free(newhead);
- CloseSetA(CORE);
- CloseSetA(arg);
- CloseSetA(new_el);
- return (oldcount);
+ else { /* old reduct covers new elemet */
+ newcount++;
+ if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT) {
+ keep = newhead;
+ if ((newhead =
+ (setA) realloc(keep,
+ MEMOKWANT * (++memoryN))) == NULL) {
+ free(oldhead);
+ CloseSetA(new_el);
+ CloseSetA(arg);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if (keep != newhead)
+ newtail = newhead + (newcount - 1) * size;
+ }
+ CopySetA(newtail, el);
+ newtail += size;
+ }
+ el += size;
+ }
+ oldtail = newhead; /* new list becomes old */
+ newhead = oldhead;
+ oldhead = oldtail;
+ oldtail = newtail;
+ newtail = newhead;
+ oldcount = newcount;
+ newcount = 0;
+ j = memoryO;
+ memoryO = memoryN;
+ memoryN = j;
+ }
+ if (oldcount == 0) {
+ free(oldhead);
+ *reducts = NULL;
+ }
+ else
+ *reducts = oldhead;
+ free(newhead);
+ CloseSetA(CORE);
+ CloseSetA(arg);
+ CloseSetA(new_el);
+ return (oldcount);
}
-int RedSetA(setA *reducts,setA quasicore,int matrix_type)
- { int j, MEMOKWANT=_mainsys->attributes_num*_mainsys->attributes_num,
- atr,
- over,size=_mainsys->setAsize,
- memoryN=1,memoryO=1, /* size of the allocated memory */
- newcount=0,oldcount; /* number of new/old reducts */
- int no_A=_mainsys->attributes_num;
- setA oldhead, /* head of static list of reducts */
- oldtail, /* tail ends the old reducts list */
- el,el1, /* elements of this list */
- new_el, /* probably new element of the list*/
- newhead, /* begin of new reducts */
- newtail; /* tail of the list of new reducts */
- setA CORE,keep;
+int RedSetA(setA * reducts, setA quasicore, int matrix_type)
+{
+ int j, MEMOKWANT = _mainsys->attributes_num * _mainsys->attributes_num, atr, over, size = _mainsys->setAsize, memoryN = 1, memoryO = 1, /* size of the allocated memory */
+ newcount = 0, oldcount; /* number of new/old reducts */
+ int no_A = _mainsys->attributes_num;
+ setA oldhead, /* head of static list of reducts */
+ oldtail, /* tail ends the old reducts list */
+ el, el1, /* elements of this list */
+ new_el, /* probably new element of the list */
+ newhead, /* begin of new reducts */
+ newtail; /* tail of the list of new reducts */
+ setA CORE, keep;
- CORE=InitEmptySetA();
- _rerror=0;
- Core(CORE,matrix_type);
- if (_rerror!=0) { CloseSetA(CORE); return(-_rerror); }
- OrSetA(CORE,CORE,quasicore);
- if ((oldhead=(setA)malloc(MEMOKWANT))==NULL)
- { CloseSetA(CORE);
- ERROR(3);
+ CORE = InitEmptySetA();
+ _rerror = 0;
+ Core(CORE, matrix_type);
+ if (_rerror != 0) {
+ CloseSetA(CORE);
+ return (-_rerror);
}
- if ((newhead=(setA)malloc(MEMOKWANT))==NULL)
- { free(oldhead);
- CloseSetA(CORE);
- ERROR(3);
+ OrSetA(CORE, CORE, quasicore);
+ if ((oldhead = (setA) malloc(MEMOKWANT)) == NULL) {
+ CloseSetA(CORE);
+ ERROR(3);
}
- new_el=InitEmptySetA();
- oldtail=oldhead;
- newtail=newhead;
- start_of_tab(matrix_type);
- if ( !IsEmptySetA(CORE) ) /*initializing the reducts list */
- { CopySetA(oldtail,CORE);
- oldtail+=size,oldcount=1;
- }
- else do
- { oldcount=0;
- for(atr=0;atr<no_A;atr++)
- if ( ContSetA(_table_element,atr) )
- { ClearSetA(oldtail);
- AddSetA(oldtail,atr);
- oldtail+=size;
- oldcount++;
- }
- next_of_tab();
- }
- while ((oldcount==0) && end_of_tab());
- for(;end_of_tab();next_of_tab()) /* for each element of matrix do */
- { over = 0;
- if ( InterSetA(_table_element,CORE) ) continue;
- if ( IsEmptySetA(_table_element) ) continue;
- el=oldhead;
- while (el<oldtail) /* compare elment to all the old reducts */
- { if ( !InterSetA(el,_table_element) ) /* old reduct does not cover element */
- { for(atr=0;atr<no_A;atr++) /* for each atribute of element */
- if ( ContSetA(_table_element,atr) )
- { CopySetA(new_el,el); /* creating potentialy new reduct */
- AddSetA(new_el,atr);
- over=0;
- el1=oldhead;
- while ((el1!=el) && !over) /* comparing new reduct to all the old reducts */
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- el1=el+size;
- while ((el1!=oldtail) && !over)
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- if (!over) /* appending new reduct to list */
- { newcount++;
- if (newcount*size*_cluster_bytes>memoryN*MEMOKWANT)
- { keep=newhead;
- if ((newhead=(setA)realloc(keep,MEMOKWANT*(++memoryN)))==NULL)
- { free(oldhead);
- CloseSetA(new_el);
- CloseSetA(CORE); ERROR(3);
- }
- if (keep!=newhead) newtail=newhead+(newcount-1)*size;
- }
- CopySetA(newtail,new_el);
- newtail+=size;
- }
+ if ((newhead = (setA) malloc(MEMOKWANT)) == NULL) {
+ free(oldhead);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ new_el = InitEmptySetA();
+ oldtail = oldhead;
+ newtail = newhead;
+ start_of_tab(matrix_type);
+ if (!IsEmptySetA(CORE)) { /*initializing the reducts list */
+ CopySetA(oldtail, CORE);
+ oldtail += size, oldcount = 1;
+ }
+ else
+ do {
+ oldcount = 0;
+ for (atr = 0; atr < no_A; atr++)
+ if (ContSetA(_table_element, atr)) {
+ ClearSetA(oldtail);
+ AddSetA(oldtail, atr);
+ oldtail += size;
+ oldcount++;
+ }
+ next_of_tab();
+ }
+ while ((oldcount == 0) && end_of_tab());
+ for (; end_of_tab(); next_of_tab()) { /* for each element of matrix do */
+ over = 0;
+ if (InterSetA(_table_element, CORE))
+ continue;
+ if (IsEmptySetA(_table_element))
+ continue;
+ el = oldhead;
+ while (el < oldtail) { /* compare elment to all the old reducts */
+ if (!InterSetA(el, _table_element)) { /* old reduct does not cover element */
+ for (atr = 0; atr < no_A; atr++) /* for each atribute of element */
+ if (ContSetA(_table_element, atr)) {
+ CopySetA(new_el, el); /* creating potentialy new reduct */
+ AddSetA(new_el, atr);
+ over = 0;
+ el1 = oldhead;
+ while ((el1 != el) && !over) { /* comparing new reduct to all the old reducts */
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ el1 = el + size;
+ while ((el1 != oldtail) && !over) {
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ if (!over) { /* appending new reduct to list */
+ newcount++;
+ if (newcount * size * _cluster_bytes >
+ memoryN * MEMOKWANT) {
+ keep = newhead;
+ if ((newhead =
+ (setA) realloc(keep,
+ MEMOKWANT *
+ (++memoryN))) == NULL) {
+ free(oldhead);
+ CloseSetA(new_el);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if (keep != newhead)
+ newtail = newhead + (newcount - 1) * size;
+ }
+ CopySetA(newtail, new_el);
+ newtail += size;
+ }
+ }
}
- }
- else /* old reduct covers new element */
- { newcount++;
- if (newcount*size*_cluster_bytes>memoryN*MEMOKWANT)
- { keep=newhead;
- if ((newhead=(setA)realloc(keep,MEMOKWANT*(++memoryN)))==NULL)
- { free(oldhead);
- CloseSetA(new_el);
- CloseSetA(CORE); ERROR(3);
- }
- if (keep!=newhead) newtail=newhead+(newcount-1)*size;
- }
- CopySetA(newtail,el);
- newtail+=size;
- }
- el+=size;
- }
- oldtail=newhead; /* new list becomes old */
- newhead=oldhead;
- oldhead=oldtail;
- oldtail=newtail;
- newtail=newhead;
- oldcount=newcount;
- newcount=0;
- j=memoryO;
- memoryO=memoryN;
- memoryN=j;
- }
- if (oldcount==0)
- { free(oldhead);
- *reducts=NULL;
- }
- else
- *reducts=oldhead;
- free(newhead);
- CloseSetA(CORE);
- CloseSetA(new_el);
- return (oldcount);
+ else { /* old reduct covers new element */
+ newcount++;
+ if (newcount * size * _cluster_bytes > memoryN * MEMOKWANT) {
+ keep = newhead;
+ if ((newhead =
+ (setA) realloc(keep,
+ MEMOKWANT * (++memoryN))) == NULL) {
+ free(oldhead);
+ CloseSetA(new_el);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if (keep != newhead)
+ newtail = newhead + (newcount - 1) * size;
+ }
+ CopySetA(newtail, el);
+ newtail += size;
+ }
+ el += size;
+ }
+ oldtail = newhead; /* new list becomes old */
+ newhead = oldhead;
+ oldhead = oldtail;
+ oldtail = newtail;
+ newtail = newhead;
+ oldcount = newcount;
+ newcount = 0;
+ j = memoryO;
+ memoryO = memoryN;
+ memoryN = j;
+ }
+ if (oldcount == 0) {
+ free(oldhead);
+ *reducts = NULL;
+ }
+ else
+ *reducts = oldhead;
+ free(newhead);
+ CloseSetA(CORE);
+ CloseSetA(new_el);
+ return (oldcount);
}
-int RedRelFirst(setA *reducts,setA P,setA Q,int N,int matrix_type)
-{ int atr,
- over,size=_mainsys->setAsize,
- newcount=0,oldcount; /* number of new,old reducts */
- int no_A=_mainsys->attributes_num;
- setA arg, /* arguments are elements of matrix*/
- oldhead, /* head of static list of reducts */
- oldtail, /* tail ends the old reducts list */
- el,el1, /* elements of this list */
- new_el, /* probably new element of the list*/
- newhead, /* begin of new reducts */
- newtail; /* tail of the list of new reducts */
- setA CORE;
+int RedRelFirst(setA * reducts, setA P, setA Q, int N, int matrix_type)
+{
+ int atr, over, size = _mainsys->setAsize, newcount = 0, oldcount; /* number of new,old reducts */
+ int no_A = _mainsys->attributes_num;
+ setA arg, /* arguments are elements of matrix */
+ oldhead, /* head of static list of reducts */
+ oldtail, /* tail ends the old reducts list */
+ el, el1, /* elements of this list */
+ new_el, /* probably new element of the list */
+ newhead, /* begin of new reducts */
+ newtail; /* tail of the list of new reducts */
+ setA CORE;
- if (N==0) return 0;
- CORE=InitEmptySetA();
- _rerror=0;
- CoreRel(CORE,P,Q,matrix_type);
- if (_rerror!=0) { CloseSetA(CORE); return(-_rerror); }
- if ((oldhead=(setA)malloc(N*size*_cluster_bytes))==NULL)
- { CloseSetA(CORE);
- ERROR(3);
+ if (N == 0)
+ return 0;
+ CORE = InitEmptySetA();
+ _rerror = 0;
+ CoreRel(CORE, P, Q, matrix_type);
+ if (_rerror != 0) {
+ CloseSetA(CORE);
+ return (-_rerror);
}
- if ((newhead=(setA)malloc(N*size*_cluster_bytes))==NULL)
- { free(oldhead);
- CloseSetA(CORE);
- ERROR(3);
+ if ((oldhead = (setA) malloc(N * size * _cluster_bytes)) == NULL) {
+ CloseSetA(CORE);
+ ERROR(3);
}
- new_el=InitEmptySetA();
- arg=InitEmptySetA();
- oldtail=oldhead;
- newtail=newhead;
- start_of_tab(matrix_type);
- if ( !IsEmptySetA(CORE) ) /* initializing the reducts list */
- { CopySetA(oldtail,CORE);
- oldtail+=size,oldcount=1;
- }
- else do
- { AndSetA(arg,_table_element,P);
- oldcount=0;
- if (InterSetA(_table_element,Q))
- for(atr=0;atr<no_A;atr++)
- if ( ContSetA(arg,atr)&&(oldcount<N) )
- { ClearSetA(oldtail);
- AddSetA(oldtail,atr);
- oldtail+=size;
- oldcount++;
- }
- next_of_tab();
- }
- while ((oldcount==0) && end_of_tab());
- for(;end_of_tab();next_of_tab()) /* for each element of matrix do */
- { AndSetA(arg,_table_element,P); /* take next element */
- over = 0;
- if ( InterSetA(CORE,arg) ) continue;
- if ( !InterSetA(_table_element,Q) ) continue;
- if ( IsEmptySetA(arg) ) continue;
- el=oldhead;
- while (el<oldtail) /* compare element to all the old reducts */
- { if ( !InterSetA(el,arg) ) /* old reduct does not cover element */
- { for(atr=0;atr<no_A;atr++) /* for each atribute of elememt */
- if ( ContSetA(arg,atr)&&(newcount<N) )
- { CopySetA(new_el,el); /* creating potentialy new reduct */
- AddSetA(new_el,atr);
- over=0;
- el1=oldhead;
- while ((el1!=el) && !over) /* comparing new reduct to all the old reducts */
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- el1=el+size;
- while ((el1!=oldtail) && !over)
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- if (!over) /* appending new reduct to list*/
- { CopySetA(newtail,new_el);
- newtail+=size;
- newcount++;
- }
- }
- }
- else if (newcount<N)
- { CopySetA(newtail,el);
- newtail+=size;
+ if ((newhead = (setA) malloc(N * size * _cluster_bytes)) == NULL) {
+ free(oldhead);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ new_el = InitEmptySetA();
+ arg = InitEmptySetA();
+ oldtail = oldhead;
+ newtail = newhead;
+ start_of_tab(matrix_type);
+ if (!IsEmptySetA(CORE)) { /* initializing the reducts list */
+ CopySetA(oldtail, CORE);
+ oldtail += size, oldcount = 1;
+ }
+ else
+ do {
+ AndSetA(arg, _table_element, P);
+ oldcount = 0;
+ if (InterSetA(_table_element, Q))
+ for (atr = 0; atr < no_A; atr++)
+ if (ContSetA(arg, atr) && (oldcount < N)) {
+ ClearSetA(oldtail);
+ AddSetA(oldtail, atr);
+ oldtail += size;
+ oldcount++;
+ }
+ next_of_tab();
+ }
+ while ((oldcount == 0) && end_of_tab());
+ for (; end_of_tab(); next_of_tab()) { /* for each element of matrix do */
+ AndSetA(arg, _table_element, P); /* take next element */
+ over = 0;
+ if (InterSetA(CORE, arg))
+ continue;
+ if (!InterSetA(_table_element, Q))
+ continue;
+ if (IsEmptySetA(arg))
+ continue;
+ el = oldhead;
+ while (el < oldtail) { /* compare element to all the old reducts */
+ if (!InterSetA(el, arg)) { /* old reduct does not cover element */
+ for (atr = 0; atr < no_A; atr++) /* for each atribute of elememt */
+ if (ContSetA(arg, atr) && (newcount < N)) {
+ CopySetA(new_el, el); /* creating potentialy new reduct */
+ AddSetA(new_el, atr);
+ over = 0;
+ el1 = oldhead;
+ while ((el1 != el) && !over) { /* comparing new reduct to all the old reducts */
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ el1 = el + size;
+ while ((el1 != oldtail) && !over) {
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ if (!over) { /* appending new reduct to list */
+ CopySetA(newtail, new_el);
+ newtail += size;
+ newcount++;
+ }
+ }
+ }
+ else if (newcount < N) {
+ CopySetA(newtail, el);
+ newtail += size;
newcount++;
- }
- el+=size;
- }
- oldtail=newhead; /* new list becomes old */
- newhead=oldhead;
- oldhead=oldtail;
- oldtail=newtail;
- newtail=newhead;
- oldcount=newcount;
- newcount=0;
- }
- if (oldcount==0)
- { free(oldhead);
- *reducts=NULL;
- }
- else
- *reducts=oldhead;
- free(newhead);
- CloseSetA(CORE);
- CloseSetA(arg);
- CloseSetA(new_el);
- return (oldcount);
+ }
+ el += size;
+ }
+ oldtail = newhead; /* new list becomes old */
+ newhead = oldhead;
+ oldhead = oldtail;
+ oldtail = newtail;
+ newtail = newhead;
+ oldcount = newcount;
+ newcount = 0;
+ }
+ if (oldcount == 0) {
+ free(oldhead);
+ *reducts = NULL;
+ }
+ else
+ *reducts = oldhead;
+ free(newhead);
+ CloseSetA(CORE);
+ CloseSetA(arg);
+ CloseSetA(new_el);
+ return (oldcount);
}
-int RedFirst(setA *reducts,int N,int matrix_type)
-{ int atr,over,size=_mainsys->setAsize,
- newcount=0,oldcount; /* sizes of reduct lists */
- int no_A=_mainsys->attributes_num;
- setA oldhead, /* head of static list of reducts */
- oldtail, /* tail ends the old reducts list */
- el,el1, /* elements of this list */
- new_el, /* probably new element of the list*/
- newhead, /* begin of new reducts */
- newtail; /* tail of the list of new reducts */
- setA CORE;
+int RedFirst(setA * reducts, int N, int matrix_type)
+{
+ int atr, over, size = _mainsys->setAsize, newcount = 0, oldcount; /* sizes of reduct lists */
+ int no_A = _mainsys->attributes_num;
+ setA oldhead, /* head of static list of reducts */
+ oldtail, /* tail ends the old reducts list */
+ el, el1, /* elements of this list */
+ new_el, /* probably new element of the list */
+ newhead, /* begin of new reducts */
+ newtail; /* tail of the list of new reducts */
+ setA CORE;
- if (N==0) return 0;
- CORE=InitEmptySetA();
- _rerror=0;
- Core(CORE,matrix_type);
- if (_rerror!=0) { CloseSetA(CORE); return(-_rerror); }
- if ((oldhead=(setA)malloc(N*size*_cluster_bytes))==NULL)
- { CloseSetA(CORE); ERROR(3); }
- if ((newhead=(setA)malloc(N*size*_cluster_bytes))==NULL)
- { free(oldhead); CloseSetA(CORE); ERROR(3); }
- new_el=InitEmptySetA();
- oldtail=oldhead;
- newtail=newhead;
- start_of_tab(matrix_type);
- if ( !IsEmptySetA(CORE) ) /*initializing the reducts list */
- { CopySetA(oldtail,CORE);
- oldtail+=size,oldcount=1;
- }
- else do
- { oldcount=0;
- for(atr=0;atr<no_A;atr++)
- if ( ContSetA(_table_element,atr)&&(oldcount<N) )
- { ClearSetA(oldtail);
- AddSetA(oldtail,atr);
- oldtail+=size;
- oldcount++;
- }
- next_of_tab();
- }
- while ((oldcount==0) && end_of_tab());
- for(;end_of_tab();next_of_tab()) /* for each element of matrix do */
- { over = 0;
- if ( InterSetA(_table_element,CORE) ) continue;
- if ( IsEmptySetA(_table_element) ) continue;
- el=oldhead;
- while (el<oldtail) /* compare element to all the old reducts */
- { if ( !InterSetA(el,_table_element) ) /* old reduct does not cover element */
- { for(atr=0;atr<no_A;atr++) /* for each atribute of element */
- if ( ContSetA(_table_element,atr)&&(newcount<N) )
- { CopySetA(new_el,el); /* creating potentialy new element */
- AddSetA(new_el,atr);
- over=0;
- el1=oldhead;
- while ((el1!=el) && !over) /* comparing new reduct to old list */
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- el1=el+size;
- while ((el1!=oldtail) && !over)
- { over = InSetA(new_el,el1);
- el1+=size;
- }
- if (!over)
- { CopySetA(newtail,new_el);
- newtail+=size;
- newcount++;
- }
- }
- }
- else if (newcount<N)
- { CopySetA(newtail,el); /* rewriting reduct from old list */
- newtail+=size;
+ if (N == 0)
+ return 0;
+ CORE = InitEmptySetA();
+ _rerror = 0;
+ Core(CORE, matrix_type);
+ if (_rerror != 0) {
+ CloseSetA(CORE);
+ return (-_rerror);
+ }
+ if ((oldhead = (setA) malloc(N * size * _cluster_bytes)) == NULL) {
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ if ((newhead = (setA) malloc(N * size * _cluster_bytes)) == NULL) {
+ free(oldhead);
+ CloseSetA(CORE);
+ ERROR(3);
+ }
+ new_el = InitEmptySetA();
+ oldtail = oldhead;
+ newtail = newhead;
+ start_of_tab(matrix_type);
+ if (!IsEmptySetA(CORE)) { /*initializing the reducts list */
+ CopySetA(oldtail, CORE);
+ oldtail += size, oldcount = 1;
+ }
+ else
+ do {
+ oldcount = 0;
+ for (atr = 0; atr < no_A; atr++)
+ if (ContSetA(_table_element, atr) && (oldcount < N)) {
+ ClearSetA(oldtail);
+ AddSetA(oldtail, atr);
+ oldtail += size;
+ oldcount++;
+ }
+ next_of_tab();
+ }
+ while ((oldcount == 0) && end_of_tab());
+ for (; end_of_tab(); next_of_tab()) { /* for each element of matrix do */
+ over = 0;
+ if (InterSetA(_table_element, CORE))
+ continue;
+ if (IsEmptySetA(_table_element))
+ continue;
+ el = oldhead;
+ while (el < oldtail) { /* compare element to all the old reducts */
+ if (!InterSetA(el, _table_element)) { /* old reduct does not cover element */
+ for (atr = 0; atr < no_A; atr++) /* for each atribute of element */
+ if (ContSetA(_table_element, atr) && (newcount < N)) {
+ CopySetA(new_el, el); /* creating potentialy new element */
+ AddSetA(new_el, atr);
+ over = 0;
+ el1 = oldhead;
+ while ((el1 != el) && !over) { /* comparing new reduct to old list */
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ el1 = el + size;
+ while ((el1 != oldtail) && !over) {
+ over = InSetA(new_el, el1);
+ el1 += size;
+ }
+ if (!over) {
+ CopySetA(newtail, new_el);
+ newtail += size;
+ newcount++;
+ }
+ }
+ }
+ else if (newcount < N) {
+ CopySetA(newtail, el); /* rewriting reduct from old list */
+ newtail += size;
newcount++;
- }
- el+=size;
- }
- oldtail=newhead; /* new list becomes old */
- newhead=oldhead;
- oldhead=oldtail;
- oldtail=newtail;
- newtail=newhead;
- oldcount=newcount;
- newcount=0;
- }
- if (oldcount==0)
- { free(oldhead); *reducts=NULL; }
- else
- *reducts=oldhead;
- free(newhead);
- CloseSetA(CORE);
- CloseSetA(new_el);
- return (oldcount);
+ }
+ el += size;
+ }
+ oldtail = newhead; /* new list becomes old */
+ newhead = oldhead;
+ oldhead = oldtail;
+ oldtail = newtail;
+ newtail = newhead;
+ oldcount = newcount;
+ newcount = 0;
+ }
+ if (oldcount == 0) {
+ free(oldhead);
+ *reducts = NULL;
+ }
+ else
+ *reducts = oldhead;
+ free(newhead);
+ CloseSetA(CORE);
+ CloseSetA(new_el);
+ return (oldcount);
}
-
Modified: grass-addons/raster/mcda/r.roughset/reduct1.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/reduct1.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/reduct1.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,49 +16,63 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SOME MORE QUERIES FOR SYSTEM ***/
+
/*** ( FINDING REDUCTS ) ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
-int Red (setA *red,int matrix);
+int Red(setA * red, int matrix);
+
/* finds all reducts for information system, */
- /* sets red to yhe allocated reducts table */
+ /* sets red to yhe allocated reducts table */
/* function returns number of reducts */
-int RedRel (setA *red,setA P,setA Q,int matrix_type);
+int RedRel(setA * red, setA P, setA Q, int matrix_type);
+
/* like Red, but reducts are Q-relative and */
/* computed from set of attributes P */
-int RedLess (setA *red,int N,int matrix_type);
+int RedLess(setA * red, int N, int matrix_type);
+
/* finds all reducts which contain less than */
/* N attributes, other parameters and result */
/* like Red */
-int RedRelLess (setA *red,setA P,setA Q,int N,int matrix_type);
+int RedRelLess(setA * red, setA P, setA Q, int N, int matrix_type);
+
/* like RedLess, but reducts are Q-relative of P */
-int RedSetA (setA *red,setA quasicore,int matrix_type);
+int RedSetA(setA * red, setA quasicore, int matrix_type);
+
/* finds only reducts including quasicore , */
/* some reducts can be not minimal ( formally */
/* they are not reducts ) , other parameters and */
/* result like Red */
-int RedRelSetA (setA *red,setA quasicore,setA P,setA Q,int matrix_type);
+int RedRelSetA(setA * red, setA quasicore, setA P, setA Q, int matrix_type);
+
/* like RedSetA, but reducts are Q-relative of P */
-int RedFirst (setA *red,int N,int matrix_type);
+int RedFirst(setA * red, int N, int matrix_type);
+
/* finds first N reducts ( only quasi-reduct ), */
/* other parameters and result like Red */
-int RedRelFirst (setA *red,setA P,setA Q,int N,int matrix_type);
+int RedRelFirst(setA * red, setA P, setA Q, int N, int matrix_type);
+
/* like RedFirst, but reducts are Q-relative of P */
-
Modified: grass-addons/raster/mcda/r.roughset/reduct2.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/reduct2.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/reduct2.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,174 +16,214 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SOME MORE QUERIES FOR SYSTEM ***/
+
/*** ( AUXILIARY REDUCTS ROUTINES ) ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
#include <stdlib.h>
#include "rough.h"
-int RedSingle( setA red, int matrix_type)
- {
+int RedSingle(setA red, int matrix_type)
+{
int i;
- int cont=1;
+ int cont = 1;
setA over;
+
over = InitEmptySetA();
- Core( red, matrix_type );
- for (i=0;(i<_mainsys->attributes_num)&&cont;i++)
- if ( IsCover( red, matrix_type ) ) cont=0;
- else AddSetA( red, i );
- cont=1;
- while(cont)
- if ( IsOrtho( red, over, matrix_type ) ) cont=0;
- else
- for (i=0;i<_mainsys->attributes_num;i++)
- if (ContSetA( over, i ))
- { DelSetA( red, i ); break; }
- CloseSetA( over );
+ Core(red, matrix_type);
+ for (i = 0; (i < _mainsys->attributes_num) && cont; i++)
+ if (IsCover(red, matrix_type))
+ cont = 0;
+ else
+ AddSetA(red, i);
+ cont = 1;
+ while (cont)
+ if (IsOrtho(red, over, matrix_type))
+ cont = 0;
+ else
+ for (i = 0; i < _mainsys->attributes_num; i++)
+ if (ContSetA(over, i)) {
+ DelSetA(red, i);
+ break;
+ }
+ CloseSetA(over);
return 1;
- }
-
-int RedRelSingle( setA red, setA P, setA Q, int matrix_type)
-{ int i;
- int cont=1;
- setA over;
- over = InitEmptySetA();
- CoreRel( red, P, Q, matrix_type );
- for (i=0;(i<_mainsys->attributes_num)&&cont;i++)
- {
- if ( IsCoverRel( red, P, Q, matrix_type ) ) cont=0;
- else AddSetA( red, i );
- }
- cont=1;
- while(cont)
- {
- if ( IsOrthoRel( red, over, P, Q, matrix_type ) ) cont=0;
- else
- for (i=0;i<_mainsys->attributes_num;i++)
- if (ContSetA( over, i )) { DelSetA( red, i ); break; }
- }
- CloseSetA( over );
- return 1;
}
+int RedRelSingle(setA red, setA P, setA Q, int matrix_type)
+{
+ int i;
+ int cont = 1;
+ setA over;
+ over = InitEmptySetA();
+ CoreRel(red, P, Q, matrix_type);
+ for (i = 0; (i < _mainsys->attributes_num) && cont; i++) {
+ if (IsCoverRel(red, P, Q, matrix_type))
+ cont = 0;
+ else
+ AddSetA(red, i);
+ }
+ cont = 1;
+ while (cont) {
+ if (IsOrthoRel(red, over, P, Q, matrix_type))
+ cont = 0;
+ else
+ for (i = 0; i < _mainsys->attributes_num; i++)
+ if (ContSetA(over, i)) {
+ DelSetA(red, i);
+ break;
+ }
+ }
+ CloseSetA(over);
+ return 1;
+}
-int RedOptim( setA red, int matrix_type)
-{ int max, f, fmax;
- int i, atr;
- int cont=1;
- setA over;
- over = InitFullSetA();
- Core( red, matrix_type );
- fmax = CardCoef( over, matrix_type );
- max = CardCoef( red, matrix_type );
- while ( max < fmax )
- { for( i=0; i<_mainsys->attributes_num; i++ )
- if ( !ContSetA( red, i) )
- { AddSetA( red, i );
- f = CardCoef( red, matrix_type );
- if ( f >= max ) max = f, atr = i;
- DelSetA( red, i );
- }
- AddSetA( red, atr );
- }
- cont=1;
- while( cont )
- { if ( IsOrtho( red, over, matrix_type ) ) cont=0;
- else
- for( i=0; i<_mainsys->attributes_num; i++ )
- if ( ContSetA( over, i ) )
- { DelSetA( red, i ); break; }
- }
- CloseSetA( over );
- return 1;
- }
-int RedRelOptim( setA red, setA P, setA Q, int matrix_type)
- { float max, f, fmax;
- int i, atr;
- int cont=1;
- setA over;
- over = InitEmptySetA();
- CoreRel( red, P, Q, matrix_type );
- fmax = DependCoef( P, Q, matrix_type );
- while (cont)
- { max = 0;
- for (i=0;i<_mainsys->attributes_num;i++)
- if (ContSetA( P, i ) && !ContSetA( red, i))
- { AddSetA( red, i );
- f = DependCoef( red, Q, matrix_type );
- if ( f >= max ) max = f, atr = i;
- DelSetA( red, i );
- }
- AddSetA( red, atr );
- if ( max==fmax ) cont=0;
+int RedOptim(setA red, int matrix_type)
+{
+ int max, f, fmax;
+ int i, atr;
+ int cont = 1;
+ setA over;
+
+ over = InitFullSetA();
+ Core(red, matrix_type);
+ fmax = CardCoef(over, matrix_type);
+ max = CardCoef(red, matrix_type);
+ while (max < fmax) {
+ for (i = 0; i < _mainsys->attributes_num; i++)
+ if (!ContSetA(red, i)) {
+ AddSetA(red, i);
+ f = CardCoef(red, matrix_type);
+ if (f >= max)
+ max = f, atr = i;
+ DelSetA(red, i);
+ }
+ AddSetA(red, atr);
}
- cont=1;
- while(cont)
- { if ( IsOrthoRel( red, over, P, Q, matrix_type ) ) cont=0;
- else
- for (i=0;i<_mainsys->attributes_num;i++)
- if (ContSetA( over, i )) { DelSetA( red, i ); break; }
+ cont = 1;
+ while (cont) {
+ if (IsOrtho(red, over, matrix_type))
+ cont = 0;
+ else
+ for (i = 0; i < _mainsys->attributes_num; i++)
+ if (ContSetA(over, i)) {
+ DelSetA(red, i);
+ break;
+ }
}
- CloseSetA( over );
- return 1;
- }
-
-int RedFew( setA *reds, int matrix_type)
- { setA r;
- int n;
- r = InitEmptySetA();
- RedSingle( r, matrix_type );
- n = RedLess( reds, CardSetA(r), matrix_type );
- CloseSetA( r );
- return n;
- }
+ CloseSetA(over);
+ return 1;
+}
-int RedRelFew( setA *reds, setA P, setA Q, int matrix_type)
- { setA r;
- int n;
- r = InitEmptySetA();
- RedRelSingle( r, P, Q, matrix_type );
- n = RedRelLess( reds, P, Q, CardSetA(r), matrix_type );
- CloseSetA( r );
- return n;
- }
-
-int SelectOneShort( setA reds, int N )
- { int min, m, i, num=0;
- min = _mainsys->attributes_num;
- for( i=0,START_OF_MAT(reds,N); END_OF_MAT; i++,NEXT_OF_MAT )
- if ( min > (m=CardSetA( ELEM_OF_MAT )) )
- min = m, num = i;
- return num;
- }
+int RedRelOptim(setA red, setA P, setA Q, int matrix_type)
+{
+ float max, f, fmax;
+ int i, atr;
+ int cont = 1;
+ setA over;
-int SelectAllShort( setA *newreds, setA reds, int N)
- { int num, m, min;
- int size = _mainsys->setAsize;
- min = _mainsys->attributes_num+1;
- *newreds = (cluster_type *)malloc( N*size*_cluster_bytes );
- for( START_OF_MAT(reds,N); END_OF_MAT; NEXT_OF_MAT )
- if ( min > (m=CardSetA( ELEM_OF_MAT )) )
- { min = m;
- num = 0;
- CopySetA( *newreds+num*size, ELEM_OF_MAT );
- }
- else if ( min==m )
- { num++;
- CopySetA( *newreds+num*size, ELEM_OF_MAT );
- }
- *newreds = (cluster_type *)realloc( *newreds, (num+1)*size*_cluster_bytes );
- if ( *newreds==0 ) num=-1;
- return num+1;
- }
+ over = InitEmptySetA();
+ CoreRel(red, P, Q, matrix_type);
+ fmax = DependCoef(P, Q, matrix_type);
+ while (cont) {
+ max = 0;
+ for (i = 0; i < _mainsys->attributes_num; i++)
+ if (ContSetA(P, i) && !ContSetA(red, i)) {
+ AddSetA(red, i);
+ f = DependCoef(red, Q, matrix_type);
+ if (f >= max)
+ max = f, atr = i;
+ DelSetA(red, i);
+ }
+ AddSetA(red, atr);
+ if (max == fmax)
+ cont = 0;
+ }
+ cont = 1;
+ while (cont) {
+ if (IsOrthoRel(red, over, P, Q, matrix_type))
+ cont = 0;
+ else
+ for (i = 0; i < _mainsys->attributes_num; i++)
+ if (ContSetA(over, i)) {
+ DelSetA(red, i);
+ break;
+ }
+ }
+ CloseSetA(over);
+ return 1;
+}
+int RedFew(setA * reds, int matrix_type)
+{
+ setA r;
+ int n;
+ r = InitEmptySetA();
+ RedSingle(r, matrix_type);
+ n = RedLess(reds, CardSetA(r), matrix_type);
+ CloseSetA(r);
+ return n;
+}
+
+int RedRelFew(setA * reds, setA P, setA Q, int matrix_type)
+{
+ setA r;
+ int n;
+
+ r = InitEmptySetA();
+ RedRelSingle(r, P, Q, matrix_type);
+ n = RedRelLess(reds, P, Q, CardSetA(r), matrix_type);
+ CloseSetA(r);
+ return n;
+}
+
+int SelectOneShort(setA reds, int N)
+{
+ int min, m, i, num = 0;
+
+ min = _mainsys->attributes_num;
+ for (i = 0, START_OF_MAT(reds, N); END_OF_MAT; i++, NEXT_OF_MAT)
+ if (min > (m = CardSetA(ELEM_OF_MAT)))
+ min = m, num = i;
+ return num;
+}
+
+int SelectAllShort(setA * newreds, setA reds, int N)
+{
+ int num, m, min;
+ int size = _mainsys->setAsize;
+
+ min = _mainsys->attributes_num + 1;
+ *newreds = (cluster_type *) malloc(N * size * _cluster_bytes);
+ for (START_OF_MAT(reds, N); END_OF_MAT; NEXT_OF_MAT)
+ if (min > (m = CardSetA(ELEM_OF_MAT))) {
+ min = m;
+ num = 0;
+ CopySetA(*newreds + num * size, ELEM_OF_MAT);
+ }
+ else if (min == m) {
+ num++;
+ CopySetA(*newreds + num * size, ELEM_OF_MAT);
+ }
+ *newreds =
+ (cluster_type *) realloc(*newreds, (num + 1) * size * _cluster_bytes);
+ if (*newreds == 0)
+ num = -1;
+ return num + 1;
+}
Modified: grass-addons/raster/mcda/r.roughset/reduct2.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/reduct2.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/reduct2.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,46 +16,59 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SOME MORE QUERIES FOR SYSTEM ***/
+
/*** (AUXILIARY REDUCTS ROUTINES) ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
-int RedSingle( setA red, int matrix_type);
+int RedSingle(setA red, int matrix_type);
+
/* heuristicly searches for a single reduct and stores it in red */
-int RedRelSingle( setA red, setA P, setA Q, int matrix_type);
+int RedRelSingle(setA red, setA P, setA Q, int matrix_type);
+
/* heuristicly searches for a single Q-relative reduct of P */
/* and stores it in red */
-int RedOptim( setA red, int matrix_type);
+int RedOptim(setA red, int matrix_type);
+
/* heuristicly searches for a single reduct and stores it in red */
/* dependency coefficient is used to select */
/* attributes for search optimization */
-
-int RedRelOptim( setA red, setA P, setA Q, int matrix_type);
+
+int RedRelOptim(setA red, setA P, setA Q, int matrix_type);
+
/* heuristicly searches for a single Q-relative reduct of P */
/* and stores it in red; dependency coefficient is used to select */
/* attributes for search optimization */
-int RedFew( setA *reds, int matrix_type);
+int RedFew(setA * reds, int matrix_type);
+
/* finds all reducts shortesest or equal in size to the first */
/* reduct found by the heuristic algorithm */
-int RedRelFew( setA *reds, setA P, setA Q, int matrix_type);
+int RedRelFew(setA * reds, setA P, setA Q, int matrix_type);
+
/* finds all Q-relative P-reducts shortesest or equal in size */
/* to the first reduct found by the heuristic algorithm */
-int SelectOneShort( setA reds, int num );
+int SelectOneShort(setA reds, int num);
+
/* returns index of the single shortest reduct */
/* from the table of num reducts pointed by reds */
-
-int SelectAllShort( setA *newreds, setA reds, int num);
+
+int SelectAllShort(setA * newreds, setA reds, int num);
+
/* copies all the shortest reducts */
/* from the table of num reducts pointed by reds */
-
-
Modified: grass-addons/raster/mcda/r.roughset/rerror.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rerror.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rerror.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,25 +16,30 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** OPTIONAL ERROR HANDLING AND ERROR MESSAGES ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J. Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
-char *errcodes[10]={ "everything O.K.",
- "Cannot open file",
- "Wrong format of file",
- "Not enough memory",
- "Cannot write to file",
- "Matrix A not initialized",
- "Matrix D not initialized",
- "Matrix X not initialized",
- "Wrong matrix type",
- "Set element out of domain"
- };
+char *errcodes[10] = { "everything O.K.",
+ "Cannot open file",
+ "Wrong format of file",
+ "Not enough memory",
+ "Cannot write to file",
+ "Matrix A not initialized",
+ "Matrix D not initialized",
+ "Matrix X not initialized",
+ "Wrong matrix type",
+ "Set element out of domain"
+};
#define ErrorPrint() {printf("ERROR no: %i: %s\n",_rerror,errcodes[_rerror]);_rerror=0;}
-
Modified: grass-addons/raster/mcda/r.roughset/rough.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rough.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rough.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,12 +16,19 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** OBLIGATORY FILE TO INCLUDE IN APPLICATION SOURCE ***/
+
/*** (DATA TYPES, CONSTANTS AND HEADERS) ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
/********************* CONSTANTS AND TYPES ***********************************/
@@ -36,19 +44,20 @@
typedef cluster_type *setO;
typedef cluster_type *setA;
-typedef struct {
- char name[50];
- int objects_num;
- int attributes_num;
- int descr_size;
- void *description;
- int setAsize;
- int setOsize;
- value_type *matA;
- cluster_type *matD;
- cluster_type *matX;
- unsigned int matXsize;
- } SYSTEM;
+typedef struct
+{
+ char name[50];
+ int objects_num;
+ int attributes_num;
+ int descr_size;
+ void *description;
+ int setAsize;
+ int setOsize;
+ value_type *matA;
+ cluster_type *matD;
+ cluster_type *matX;
+ unsigned int matXsize;
+} SYSTEM;
/************** H-FILES CONTAINING DECLARATIONS OF FUNCTIONS *********/
@@ -58,7 +67,7 @@
#include "rbasic.h"
#include "rcore.h"
#include "reduct1.h"
-#include "reduct2.h"
+#include "reduct2.h"
#include "rule1.h"
#include "rule2.h"
#include "rclass.h"
Modified: grass-addons/raster/mcda/r.roughset/rset.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rset.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rset.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,11 +16,17 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** OPERATIONS ON SETS OF ATTRIBUTES AND OBJECTS ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J. Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
@@ -27,362 +34,473 @@
#include <stdlib.h>
-int _cluster_bytes=sizeof(cluster_type);
-int _cluster_bits=8*sizeof(cluster_type);
-cluster_type _mask[8*sizeof(cluster_type)];
-
-setA InitEmptySetA( void)
- { int cluster;
- setA set;
- set=(setA)malloc(_mainsys->setAsize*_cluster_bytes);
- for(cluster=_mainsys->setAsize-1;cluster>=0;cluster--)
- set[cluster]=0;
- return set;
- }
+int _cluster_bytes = sizeof(cluster_type);
+int _cluster_bits = 8 * sizeof(cluster_type);
+cluster_type _mask[8 * sizeof(cluster_type)];
-setO InitEmptySetO( void)
- { int cluster;
- setO set;
- set=(setA)malloc(_mainsys->setOsize*_cluster_bytes);
- for(cluster=_mainsys->setOsize-1;cluster>=0;cluster--)
- set[cluster]=0;
- return set;
- }
+setA InitEmptySetA(void)
+{
+ int cluster;
+ setA set;
-setA InitFullSetA( void)
- { int attr,cluster;
- setA set;
- set=(setA)malloc(_mainsys->setAsize*_cluster_bytes);
- for(cluster=_mainsys->setAsize-2;cluster>=0;cluster--)
- set[cluster]=~(cluster_type)0;
- set[_mainsys->setAsize-1]=0;
- for (attr=_mainsys->attributes_num-1;
- attr>=_cluster_bits*(_mainsys->setAsize-1);attr--)
- AddSetA(set,attr);
- return set;
- }
+ set = (setA) malloc(_mainsys->setAsize * _cluster_bytes);
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+ set[cluster] = 0;
+ return set;
+}
-setO InitFullSetO( void)
- { int cluster,attr;
- setO set;
- set=(setA)malloc(_mainsys->setOsize*_cluster_bytes);
- for(cluster=_mainsys->setOsize-2;cluster>=0;cluster--)
- set[cluster]=~(cluster_type)0;
- set[_mainsys->setOsize-1]=0;
- for (attr=_mainsys->objects_num-1;
- attr>=_cluster_bits*(_mainsys->setOsize-1);attr--)
- AddSetO(set,attr);
- return set;
- }
+setO InitEmptySetO(void)
+{
+ int cluster;
+ setO set;
-void TabToSetA(setA set,int num,int tab[])
- { int atr;
- ClearSetA(set);
- for(atr=0; atr<num; atr++)
- AddSetA(set,tab[atr]);
- }
+ set = (setA) malloc(_mainsys->setOsize * _cluster_bytes);
+ for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
+ set[cluster] = 0;
+ return set;
+}
-void TabToSetO(setO set,int num,int tab[])
- { int obj;
- ClearSetO(set);
- for(obj=0; obj<num; obj++)
- AddSetO(set,tab[obj]);
- }
+setA InitFullSetA(void)
+{
+ int attr, cluster;
+ setA set;
-void ArgToSetA(setA set,int num,...)
-{ int atr;
- va_list list;
- ClearSetA(set);
- va_start(list,num);
- for(atr=0; atr<num; atr++)
- AddSetA(set,va_arg(list,int));
- va_end(list);
- }
+ set = (setA) malloc(_mainsys->setAsize * _cluster_bytes);
+ for (cluster = _mainsys->setAsize - 2; cluster >= 0; cluster--)
+ set[cluster] = ~(cluster_type) 0;
+ set[_mainsys->setAsize - 1] = 0;
+ for (attr = _mainsys->attributes_num - 1;
+ attr >= _cluster_bits * (_mainsys->setAsize - 1); attr--)
+ AddSetA(set, attr);
+ return set;
+}
-void ArgToSetO(setO set,int num,...)
-{ int obj;
- va_list list;
- ClearSetO(set);
- va_start(list,num);
- for(obj=0; obj<num; obj++)
- AddSetO(set,va_arg(list,int));
- va_end(list);
- }
+setO InitFullSetO(void)
+{
+ int cluster, attr;
+ setO set;
-void CloseSetA( setA set)
- { free(set); }
+ set = (setA) malloc(_mainsys->setOsize * _cluster_bytes);
+ for (cluster = _mainsys->setOsize - 2; cluster >= 0; cluster--)
+ set[cluster] = ~(cluster_type) 0;
+ set[_mainsys->setOsize - 1] = 0;
+ for (attr = _mainsys->objects_num - 1;
+ attr >= _cluster_bits * (_mainsys->setOsize - 1); attr--)
+ AddSetO(set, attr);
+ return set;
+}
-void CloseSetO( setA set)
- { free(set); }
+void TabToSetA(setA set, int num, int tab[])
+{
+ int atr;
-void OrSetO( setO or, setO s1, setO s2)
- { int cluster;
- for (cluster=_mainsys->setOsize-1;cluster>=0;cluster--)
- or[cluster]= s1[cluster] | s2[cluster];
- return;
- }
+ ClearSetA(set);
+ for (atr = 0; atr < num; atr++)
+ AddSetA(set, tab[atr]);
+}
-void OrSetA( setA or, setA s1, setA s2)
- { int cluster;
- for (cluster=_mainsys->setAsize-1;cluster>=0;cluster--)
- or[cluster]= s1[cluster] | s2[cluster];
- return;
- }
+void TabToSetO(setO set, int num, int tab[])
+{
+ int obj;
-void AndSetO( setO and, setO s1, setO s2)
- { int cluster;
- for (cluster=_mainsys->setOsize-1;cluster>=0;cluster--)
- and[cluster]= s1[cluster] & s2[cluster];
- return;
- }
+ ClearSetO(set);
+ for (obj = 0; obj < num; obj++)
+ AddSetO(set, tab[obj]);
+}
-void AndSetA( setA and, setA s1, setA s2)
- { int cluster;
- for (cluster=_mainsys->setAsize-1;cluster>=0;cluster--)
- and[cluster]= s1[cluster] & s2[cluster];
- return;
- }
+void ArgToSetA(setA set, int num, ...)
+{
+ int atr;
+ va_list list;
-void DifSetO( setO dif, setO s1, setO s2)
- { int cluster;
- for (cluster=_mainsys->setOsize-1;cluster>=0;cluster--)
- dif[cluster]= s1[cluster] & ~s2[cluster];
- return;
- }
+ ClearSetA(set);
+ va_start(list, num);
+ for (atr = 0; atr < num; atr++)
+ AddSetA(set, va_arg(list, int));
-void DifSetA( setA dif, setA s1, setA s2)
- { int cluster;
- for (cluster=_mainsys->setAsize-1;cluster>=0;cluster--)
- dif[cluster]= s1[cluster] & ~s2[cluster];
- return;
- }
+ va_end(list);
+}
+void ArgToSetO(setO set, int num, ...)
+{
+ int obj;
+ va_list list;
-void NotSetO( setO not, setO set)
- { int cluster, obj;
- for (cluster=_mainsys->setOsize-2;cluster>=0;cluster--)
- not[cluster]= ~set[cluster] ;
- cluster=_mainsys->setOsize-1;
- for (obj=_mainsys->objects_num-1-_cluster_bits*(_mainsys->setOsize-1);
- obj>=0;obj--)
- if ( set[cluster]&_mask[obj] )
- not[cluster] &= ~_mask[obj];
- else
- not[cluster] |= _mask[obj];
- return;
- }
+ ClearSetO(set);
+ va_start(list, num);
+ for (obj = 0; obj < num; obj++)
+ AddSetO(set, va_arg(list, int));
-void NotSetA( setA not, setA set)
- { int cluster, attr;
- for (cluster=_mainsys->setAsize-2;cluster>=0;cluster--)
- not[cluster]= ~set[cluster] ;
- cluster=_mainsys->setAsize-1;
- for (attr=_mainsys->attributes_num-1-_cluster_bits*(_mainsys->setAsize-1);
- attr>=0;attr--)
- if ( set[cluster]&_mask[attr] )
- not[cluster] &= ~_mask[attr];
- else
- not[cluster] |= _mask[attr];
- return;
- }
+ va_end(list);
+}
-void ClearSetO( setO set)
- { int cluster;
- for (cluster=_mainsys->setOsize-1;cluster>=0;cluster--)
- set[cluster]=0;
- return;
- }
+void CloseSetA(setA set)
+{
+ free(set);
+}
-void ClearSetA( setA set)
- { int cluster;
- for (cluster=_mainsys->setAsize-1;cluster>=0;cluster--)
- set[cluster]=0;
- return;
- }
+void CloseSetO(setA set)
+{
+ free(set);
+}
-void FillSetO( setO set)
- { int cluster,obj;
- for(cluster=_mainsys->setOsize-2;cluster>=0;cluster--)
- set[cluster]=~(cluster_type)0;
- set[_mainsys->setOsize-1]=0;
- for(obj=_mainsys->objects_num-1;
- obj>=_cluster_bits*(_mainsys->setOsize-1);obj--)
- AddSetO(set,obj);
- return;
- }
+void OrSetO(setO or, setO s1, setO s2)
+{
+ int cluster;
-void FillSetA( setA set)
- { int cluster,attr;
- for(cluster=_mainsys->setAsize-2;cluster>=0;cluster--)
- set[cluster]=~(cluster_type)0;
- set[_mainsys->setAsize-1]=0;
- for(attr=_mainsys->attributes_num-1;
- attr>=_cluster_bits*(_mainsys->setAsize-1);attr--)
- AddSetA(set,attr);
- return;
- }
+ for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
+ or[cluster] = s1[cluster] | s2[cluster];
+ return;
+}
-int AddSetO( setO set, int obj)
- { if (obj>=_mainsys->objects_num) ERROR(9)
- set[obj/_cluster_bits] |= _mask[obj%_cluster_bits];
- return 0;
- }
+void OrSetA(setA or, setA s1, setA s2)
+{
+ int cluster;
-int AddSetA( setA set, int attr)
- { if (attr>=_mainsys->attributes_num) ERROR(9)
- set[attr/_cluster_bits] |= _mask[attr%_cluster_bits];
- return 0;
- }
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+ or[cluster] = s1[cluster] | s2[cluster];
+ return;
+}
-int DelSetO( setO set, int obj)
- { if (obj>=_mainsys->objects_num) ERROR(9)
- set[obj/_cluster_bits] &= ~_mask[obj%_cluster_bits];
- return 0;
- }
+void AndSetO(setO and, setO s1, setO s2)
+{
+ int cluster;
-int DelSetA( setA set, int attr)
- { if (attr>=_mainsys->attributes_num) ERROR(9)
- set[attr/_cluster_bits] &= ~_mask[attr%_cluster_bits];
- return 0;
- }
+ for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
+ and[cluster] = s1[cluster] & s2[cluster];
+ return;
+}
-int InSetO( setO big, setO small)
- { int cluster;
- for (cluster=_mainsys->setOsize-1; cluster>=0 ; cluster--)
- if(big[cluster]!=(big[cluster] | small[cluster])) return 0;
- return 1;
- }
+void AndSetA(setA and, setA s1, setA s2)
+{
+ int cluster;
-int InSetA( setA big, setA small)
- { int cluster;
- for (cluster=_mainsys->setAsize-1; cluster>=0 ; cluster--)
- if(big[cluster]!=(big[cluster] | small[cluster])) return 0;
- return 1;
- }
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+ and[cluster] = s1[cluster] & s2[cluster];
+ return;
+}
-int ContSetA( setA set, int attr)
- { if(attr>=_mainsys->attributes_num) ERROR(9)
- return (_mask[attr%_cluster_bits] & set[attr/_cluster_bits]);
- }
+void DifSetO(setO dif, setO s1, setO s2)
+{
+ int cluster;
-int ContSetO( setO set,int obj)
- { if(obj>=_mainsys->objects_num) ERROR(9)
- return (_mask[obj%_cluster_bits] & set[obj/_cluster_bits]);
- }
+ for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
+ dif[cluster] = s1[cluster] & ~s2[cluster];
+ return;
+}
-int InterSetO( setO s1, setO s2)
- { int cluster;
- for (cluster=_mainsys->setOsize-1; cluster>=0 ; cluster--)
- if(s1[cluster] & s2[cluster]) return 1;
- return 0;
- }
+void DifSetA(setA dif, setA s1, setA s2)
+{
+ int cluster;
-int InterSetA( setA s1, setA s2)
- { int cluster;
- for (cluster=_mainsys->setAsize-1; cluster>=0 ; cluster--)
- if(s1[cluster] & s2[cluster]) return 1;
- return 0;
- }
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+ dif[cluster] = s1[cluster] & ~s2[cluster];
+ return;
+}
-int IsEmptySetO( setO set )
- { int cluster;
- for (cluster=_mainsys->setOsize-1; cluster>=0 ; cluster--)
- if(set[cluster]) return 0;
- return 1;
- }
+void NotSetO(setO not, setO set)
+{
+ int cluster, obj;
-int IsEmptySetA( setA set )
- { int cluster;
- for (cluster=_mainsys->setAsize-1; cluster>=0 ; cluster--)
- if(set[cluster]) return 0;
- return 1;
- }
+ for (cluster = _mainsys->setOsize - 2; cluster >= 0; cluster--)
+ not[cluster] = ~set[cluster];
+ cluster = _mainsys->setOsize - 1;
+ for (obj =
+ _mainsys->objects_num - 1 - _cluster_bits * (_mainsys->setOsize - 1);
+ obj >= 0; obj--)
+ if (set[cluster] & _mask[obj])
+ not[cluster] &= ~_mask[obj];
+ else
+ not[cluster] |= _mask[obj];
+ return;
+}
-int CardSetO( setO set)
- { int obj,card=0;
- for(obj=_mainsys->objects_num-1;obj>=0;obj--)
- if(ContSetO(set,obj)) card++;
- return card;
- }
+void NotSetA(setA not, setA set)
+{
+ int cluster, attr;
-int CardSetA( setA set)
- { int cluster,attr,card=0;
- for(cluster=_mainsys->setAsize-2;cluster>=0;cluster--)
- for(attr=_cluster_bits-1;attr>=0;attr--)
- if( _mask[attr] & set[cluster] ) card++;
- cluster=_mainsys->setAsize-1;
- for(attr=_mainsys->attributes_num-1-_cluster_bits*(_mainsys->setAsize-1);
- attr>=0;attr--)
- if( _mask[attr] & set[cluster] ) card++;
+ for (cluster = _mainsys->setAsize - 2; cluster >= 0; cluster--)
+ not[cluster] = ~set[cluster];
+ cluster = _mainsys->setAsize - 1;
+ for (attr =
+ _mainsys->attributes_num - 1 - _cluster_bits * (_mainsys->setAsize -
+ 1); attr >= 0;
+ attr--)
+ if (set[cluster] & _mask[attr])
+ not[cluster] &= ~_mask[attr];
+ else
+ not[cluster] |= _mask[attr];
+ return;
+}
+
+void ClearSetO(setO set)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
+ set[cluster] = 0;
+ return;
+}
+
+void ClearSetA(setA set)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+ set[cluster] = 0;
+ return;
+}
+
+void FillSetO(setO set)
+{
+ int cluster, obj;
+
+ for (cluster = _mainsys->setOsize - 2; cluster >= 0; cluster--)
+ set[cluster] = ~(cluster_type) 0;
+ set[_mainsys->setOsize - 1] = 0;
+ for (obj = _mainsys->objects_num - 1;
+ obj >= _cluster_bits * (_mainsys->setOsize - 1); obj--)
+ AddSetO(set, obj);
+ return;
+}
+
+void FillSetA(setA set)
+{
+ int cluster, attr;
+
+ for (cluster = _mainsys->setAsize - 2; cluster >= 0; cluster--)
+ set[cluster] = ~(cluster_type) 0;
+ set[_mainsys->setAsize - 1] = 0;
+ for (attr = _mainsys->attributes_num - 1;
+ attr >= _cluster_bits * (_mainsys->setAsize - 1); attr--)
+ AddSetA(set, attr);
+ return;
+}
+
+int AddSetO(setO set, int obj)
+{
+ if (obj >= _mainsys->objects_num)
+ ERROR(9)
+ set[obj / _cluster_bits] |= _mask[obj % _cluster_bits];
+ return 0;
+}
+
+int AddSetA(setA set, int attr)
+{
+ if (attr >= _mainsys->attributes_num)
+ ERROR(9)
+ set[attr / _cluster_bits] |= _mask[attr % _cluster_bits];
+ return 0;
+}
+
+int DelSetO(setO set, int obj)
+{
+ if (obj >= _mainsys->objects_num)
+ ERROR(9)
+ set[obj / _cluster_bits] &= ~_mask[obj % _cluster_bits];
+ return 0;
+}
+
+int DelSetA(setA set, int attr)
+{
+ if (attr >= _mainsys->attributes_num)
+ ERROR(9)
+ set[attr / _cluster_bits] &= ~_mask[attr % _cluster_bits];
+ return 0;
+}
+
+int InSetO(setO big, setO small)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
+ if (big[cluster] != (big[cluster] | small[cluster]))
+ return 0;
+ return 1;
+}
+
+int InSetA(setA big, setA small)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+ if (big[cluster] != (big[cluster] | small[cluster]))
+ return 0;
+ return 1;
+}
+
+int ContSetA(setA set, int attr)
+{
+ if (attr >= _mainsys->attributes_num)
+ ERROR(9)
+ return (_mask[attr % _cluster_bits] & set[attr / _cluster_bits]);
+}
+
+int ContSetO(setO set, int obj)
+{
+ if (obj >= _mainsys->objects_num)
+ ERROR(9)
+ return (_mask[obj % _cluster_bits] & set[obj / _cluster_bits]);
+}
+
+int InterSetO(setO s1, setO s2)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
+ if (s1[cluster] & s2[cluster])
+ return 1;
+ return 0;
+}
+
+int InterSetA(setA s1, setA s2)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+ if (s1[cluster] & s2[cluster])
+ return 1;
+ return 0;
+}
+
+
+int IsEmptySetO(setO set)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
+ if (set[cluster])
+ return 0;
+ return 1;
+}
+
+int IsEmptySetA(setA set)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+ if (set[cluster])
+ return 0;
+ return 1;
+}
+
+int CardSetO(setO set)
+{
+ int obj, card = 0;
+
+ for (obj = _mainsys->objects_num - 1; obj >= 0; obj--)
+ if (ContSetO(set, obj))
+ card++;
return card;
- }
-
-void CopySetO( setO dest, setO source)
- { int cluster;
- for (cluster=_mainsys->setOsize-1;cluster>=0;cluster--)
- dest[cluster]=source[cluster];
- return;
- }
+}
-void CopySetA( setA dest, setA source)
- { int cluster;
- for (cluster=_mainsys->setAsize-1;cluster>=0;cluster--)
- dest[cluster]=source[cluster];
- return;
- }
+int CardSetA(setA set)
+{
+ int cluster, attr, card = 0;
-int CompSetO( setO set1, setO set2)
- { int cluster;
- for(cluster=_mainsys->setOsize-1;cluster>=0;cluster--)
- if(set1[cluster] != set2[cluster]) return 0;
- return 1;
- }
+ for (cluster = _mainsys->setAsize - 2; cluster >= 0; cluster--)
+ for (attr = _cluster_bits - 1; attr >= 0; attr--)
+ if (_mask[attr] & set[cluster])
+ card++;
+ cluster = _mainsys->setAsize - 1;
+ for (attr =
+ _mainsys->attributes_num - 1 - _cluster_bits * (_mainsys->setAsize -
+ 1); attr >= 0;
+ attr--)
+ if (_mask[attr] & set[cluster])
+ card++;
+ return card;
+}
-int CompSetA( setA set1, setA set2)
- { int cluster;
- for(cluster=_mainsys->setAsize-1;cluster>=0;cluster--)
- if(set1[cluster] != set2[cluster]) return 0;
- return 1;
- }
+void CopySetO(setO dest, setO source)
+{
+ int cluster;
+ for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
+ dest[cluster] = source[cluster];
+ return;
+}
+
+void CopySetA(setA dest, setA source)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+ dest[cluster] = source[cluster];
+ return;
+}
+
+int CompSetO(setO set1, setO set2)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
+ if (set1[cluster] != set2[cluster])
+ return 0;
+ return 1;
+}
+
+int CompSetA(setA set1, setA set2)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setAsize - 1; cluster >= 0; cluster--)
+ if (set1[cluster] != set2[cluster])
+ return 0;
+ return 1;
+}
+
int SizeSetO(void)
- { return _mainsys->setOsize; }
+{
+ return _mainsys->setOsize;
+}
int SizeSetA(void)
- { return _mainsys->setAsize; }
+{
+ return _mainsys->setAsize;
+}
-void AttrValSetO( setO set, int attr, value_type val)
- { int obj;
- ClearSetO(set);
- for (obj=0; obj<_mainsys->objects_num ;obj++)
- if( val==GetA(obj,attr))
- AddSetO(set,obj);
- }
+void AttrValSetO(setO set, int attr, value_type val)
+{
+ int obj;
-int ClassSetO( setO aclass, int obj, setA Q )
- { int i;
- ClearSetO( aclass );
- for (i=0;i<_mainsys->objects_num;i++)
- if ( CompareA( i, obj, Q ) ) AddSetO( aclass, i );
- return 0;
- }
+ ClearSetO(set);
+ for (obj = 0; obj < _mainsys->objects_num; obj++)
+ if (val == GetA(obj, attr))
+ AddSetO(set, obj);
+}
+int ClassSetO(setO aclass, int obj, setA Q)
+{
+ int i;
-void PrintSetO( setO set )
- { int obj,i=0;
- printf("{");
- for (obj=0; obj<_mainsys->objects_num ;obj++)
- if (ContSetO(set,obj)) printf("%c%i",(i++>0?',':' '),obj);
- printf(" }\n");
- }
+ ClearSetO(aclass);
+ for (i = 0; i < _mainsys->objects_num; i++)
+ if (CompareA(i, obj, Q))
+ AddSetO(aclass, i);
+ return 0;
+}
-void PrintSetA( setA set )
- { int attr,i=0;
- printf("{");
- for (attr=0; attr<_mainsys->attributes_num ;attr++)
- if (ContSetA(set,attr)) printf("%c%i",(i++>0?',':' '),attr);
- printf(" }\n");
- }
+void PrintSetO(setO set)
+{
+ int obj, i = 0;
+ printf("{");
+ for (obj = 0; obj < _mainsys->objects_num; obj++)
+ if (ContSetO(set, obj))
+ printf("%c%i", (i++ > 0 ? ',' : ' '), obj);
+ printf(" }\n");
+}
+
+void PrintSetA(setA set)
+{
+ int attr, i = 0;
+
+ printf("{");
+ for (attr = 0; attr < _mainsys->attributes_num; attr++)
+ if (ContSetA(set, attr))
+ printf("%c%i", (i++ > 0 ? ',' : ' '), attr);
+ printf(" }\n");
+}
Modified: grass-addons/raster/mcda/r.roughset/rset.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rset.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rset.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,11 +16,17 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** OPERATIONS ON SETS OF ATTRIBUTES AND OBJECTS ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J. Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
@@ -31,104 +38,128 @@
setO InitEmptySetO(void);
setA InitEmptySetA(void);
+
/* allocates memory for set and initializes it */
- /* as empty, returns allocated set */
+ /* as empty, returns allocated set */
setO InitFullSetO(void);
setO InitFullSetA(void);
+
/* allocates memory for set and initializes it */
/* as full, returns newly allocated set */
-void TabToSetO(setO set,int num,int tab[]);
-void TabToSetA(setA set,int num,int tab[]);
+void TabToSetO(setO set, int num, int tab[]);
+void TabToSetA(setA set, int num, int tab[]);
+
/* sets a set with num elements of table tab */
-void ArgToSetO(setO set,int num,...);
-void ArgToSetA(setA set,int num,...);
+void ArgToSetO(setO set, int num, ...);
+void ArgToSetA(setA set, int num, ...);
+
/* sets a set with num arguments of function */
void CloseSetO(setO set);
void CloseSetA(setA set);
+
/* free memory used by set */
-void OrSetO(setO or,setO s1,setO s2);
-void OrSetA(setA or,setA s1,setA s2);
+void OrSetO(setO or, setO s1, setO s2);
+void OrSetA(setA or, setA s1, setA s2);
+
/* puts union of s1 and s2 to or */
-void AndSetO(setO and,setO s1,setO s2);
-void AndSetA(setA and,setA s1,setA s2);
+void AndSetO(setO and, setO s1, setO s2);
+void AndSetA(setA and, setA s1, setA s2);
+
/* puts product of s1 and s2 to and */
-void DifSetO(setO dif,setO s1,setO s2);
-void DifSetA(setA dif,setA s1,setA s2);
+void DifSetO(setO dif, setO s1, setO s2);
+void DifSetA(setA dif, setA s1, setA s2);
+
/* puts complement of s1 in s2 to dif */
-void NotSetO(setO not,setO set);
-void NotSetA(setO not,setA set);
+void NotSetO(setO not, setO set);
+void NotSetA(setO not, setA set);
+
/* puts a complement of set to not */
void ClearSetO(setO set);
void ClearSetA(setA set);
+
/* clears set */
void FillSetO(setO set);
void FillSetA(setA set);
+
/* fills set with domain */
-int AddSetO(setO set,int obj);
-int AddSetA(setA set,int attr);
+int AddSetO(setO set, int obj);
+int AddSetA(setA set, int attr);
+
/* adds element to set */
-int DelSetO(setO set,int obj);
-int DelSetA(setA set,int attr);
+int DelSetO(setO set, int obj);
+int DelSetA(setA set, int attr);
+
/* deletes element from set */
-int InSetO(setO big,setO small);
-int InSetA(setA big,setA small);
+int InSetO(setO big, setO small);
+int InSetA(setA big, setA small);
+
/* return 1 if set big contains set small */
/* otherwise returns 0 */
-int ContSetO(setO set,int obj);
-int ContSetA(setA set,int attr);
+int ContSetO(setO set, int obj);
+int ContSetA(setA set, int attr);
+
/* returns 1 if set contains element */
/* otherwise returns 0 */
-int InterSetO(setO s1,setO s2);
-int InterSetA(setA s1,setA s2);
+int InterSetO(setO s1, setO s2);
+int InterSetA(setA s1, setA s2);
+
/* returns 1 if s1 and s2 have nonempty product */
/* otherwise returns 0 */
int IsEmptySetO(setO set);
int IsEmptySetA(setA set);
+
/* returns 1 if set is empty */
/* otherwise returns 0 */
int CardSetO(setO set);
int CardSetA(setA set);
+
/* returns cardinality of set */
-void CopySetO(setO dest,setO source);
-void CopySetA(setA dest,setO source);
+void CopySetO(setO dest, setO source);
+void CopySetA(setA dest, setO source);
+
/* copy source to dest */
-int CompSetO(setO set1,setO set2);
-int CompSetA(setA set1,setA set2);
+int CompSetO(setO set1, setO set2);
+int CompSetA(setA set1, setA set2);
+
/* returns 1 if set1 and set2 are identical */
/* otherwise returns 0 */
int SizeSetO(void);
int SizeSetA(void);
+
/* returns number of clusters in set representation */
/* in the active system sizeof(cluster_type)=_cluster_bytes */
-void AttrValSetO(setO set,int attr,value_type val);
+void AttrValSetO(setO set, int attr, value_type val);
+
/* puts into set all object that have value val */
/* on attribute attr */
-int ClassSetO( setO aclass, int obj, setA Q );
+int ClassSetO(setO aclass, int obj, setA Q);
+
/* fills class with all object that have the same values */
/* on all attributes from Q as the object obj, uses MATA */
void PrintSetO(setO set);
void PrintSetA(setA set);
+
/* outputs set to screen */
Modified: grass-addons/raster/mcda/r.roughset/rsystem.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rsystem.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rsystem.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,123 +16,157 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SYSTEM HANDLING FUNCTIONS ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
#include <stdio.h>
-extern SYSTEM *_mainsys;
+extern SYSTEM *_mainsys;
+
/* active information system */
-extern int _rerror;
+extern int _rerror;
+
/* error code */
-SYSTEM *InitEmptySys(void);
- /* allocates memory for a new system descriptor*/
+SYSTEM *InitEmptySys(void);
+
+ /* allocates memory for a new system descriptor */
/* and clears all parameters, no matrices connected */
-void SetParameters(SYSTEM *sys,int objects_num,int attributes_num);
+void SetParameters(SYSTEM * sys, int objects_num, int attributes_num);
+
/* puts system parameters to the system descriptor */
-void ConnectDescr(SYSTEM *sys,void *descr,int size);
+void ConnectDescr(SYSTEM * sys, void *descr, int size);
+
/* connects additional description to the system descriptor */
-void SetName(SYSTEM *sys,char *name);
+void SetName(SYSTEM * sys, char *name);
+
/* puts system name to the system descriptor */
-int FileToSys(SYSTEM *sys,char *filename);
+int FileToSys(SYSTEM * sys, char *filename);
+
/* imports system from the special format file */
/* including parameters, desicripton and matrix A */
/* other matrices are left uninitialed */
-int SysToFile(SYSTEM *sys,char *filename);
+int SysToFile(SYSTEM * sys, char *filename);
+
/* exports system descriptor, additional description */
/* and matrix A to a special format file */
-void ConnectA(SYSTEM *sys,value_type *buf);
+void ConnectA(SYSTEM * sys, value_type * buf);
+
/* connects matrix A (it may be empty) with */
/* the system descriptor */
-void PutToA(SYSTEM *sys,int object,int attribute,value_type value);
+void PutToA(SYSTEM * sys, int object, int attribute, value_type value);
+
/* sets value to element of matrix A */
-int FillAfromAscii(SYSTEM *sys,FILE *file);
+int FillAfromAscii(SYSTEM * sys, FILE * file);
+
/* fills matrix A with the values from Ascii file */
-int InitD(SYSTEM *sys);
+int InitD(SYSTEM * sys);
+
/* fills matrix D from A, allocates memory */
/* and connects it with the system descriptor */
/* matrix A must already exist */
-int InitX(SYSTEM *sys,setA P,setA Q,int matrix_type);
+int InitX(SYSTEM * sys, setA P, setA Q, int matrix_type);
+
/* fills matrix X, allocates memory for it and */
/* connects it with the system descriptor */
/* matrix_type indicates the source matrix */
/* initialization is done with respect to Q from P */
-int InitXforObject(SYSTEM *sys,int obj,setA P,setA Q,int matrix_type);
+int InitXforObject(SYSTEM * sys, int obj, setA P, setA Q, int matrix_type);
+
/* works like InitX but considers only single column of MATD */
-int InitXforObjects(SYSTEM *sys,setO objects,setA P,setA Q,int matrix_type);
+int InitXforObjects(SYSTEM * sys, setO objects, setA P, setA Q,
+ int matrix_type);
/* works like InitX but concider only columns of MATD */
/* belonging to objects */
-int InitXforObjectFromClass(SYSTEM* sys,int obj,setA P,setO aclass,
+int InitXforObjectFromClass(SYSTEM * sys, int obj, setA P, setO aclass,
int matrix_type);
/* works like InitX, conciders only specified objects */
/* initialization is done with respect to objects from */
/* outside of aclass */
-void UseSys(SYSTEM *sys);
+void UseSys(SYSTEM * sys);
+
/* makes indicated system active, from now on */
/* all query routines will operate only on it */
-void CloseSys(SYSTEM *sys);
+void CloseSys(SYSTEM * sys);
+
/* frees memory allocated for all matrixes, */
/* system descriptor and additional description */
-void CloseMat(SYSTEM *sys, int matrix_type);
+void CloseMat(SYSTEM * sys, int matrix_type);
+
/* disconnects matrix X from the system descriptor */
/* and frees memory */
-void DisconMat(SYSTEM *sys, int matrix_type);
+void DisconMat(SYSTEM * sys, int matrix_type);
+
/* disconnects matrix from the system descriptor */
/* does not free memory */
-unsigned int Asize(SYSTEM *sys);
+unsigned int Asize(SYSTEM * sys);
+
/* returns number of elements in matrix A */
/* memory size = Asize * sizeof(value_type) */
/* system parameters should be valued */
-unsigned int Dsize(SYSTEM *sys);
+unsigned int Dsize(SYSTEM * sys);
+
/* returns number of memory clusters for matrix D */
/* memory size = Dsize * sizeof(cluster_type) */
/* system parameters should be valued */
-unsigned int Xsize(SYSTEM *sys);
+unsigned int Xsize(SYSTEM * sys);
+
/* returns number of memory cluster used by matrix X */
/* memory size = Xsize * sizeof(cluster_type) */
/* matrix X should be generated */
-unsigned int MatMemSize(SYSTEM *sys,int matrix_type);
+unsigned int MatMemSize(SYSTEM * sys, int matrix_type);
+
/* returns the size of memory used by specified matrix */
-void *MatExist(SYSTEM *sys,int matrix_type);
- /* return specified matrix if exist */
- /* otherwise returns NULL */
-
-int ObjectsNum(SYSTEM *sys);
+void *MatExist(SYSTEM * sys, int matrix_type);
+
+ /* return specified matrix if exist */
+ /* otherwise returns NULL */
+
+int ObjectsNum(SYSTEM * sys);
+
/* returns number of objects in the system */
-int AttributesNum(SYSTEM *sys);
+int AttributesNum(SYSTEM * sys);
+
/* returns number of attributes in the system */
-void *Description(SYSTEM *sys);
+void *Description(SYSTEM * sys);
+
/* returns pointer to additional description */
-char *SysName(SYSTEM *sys);
+char *SysName(SYSTEM * sys);
+
/* returns system name */
Modified: grass-addons/raster/mcda/r.roughset/rule1.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rule1.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rule1.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,36 +16,47 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SOME MORE QUERIES FOR SYSTEM ***/
+
/*** ( MENAGING RULES ) ***/
+
/*** ***/
+
/*** part of the ROUGH system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
-
+
#include <stdlib.h>
#include <string.h>
#include "rough.h"
-void RuleCopy(value_type *dest,value_type *source)
- { memcpy( dest, source, _mainsys->attributes_num*sizeof(value_type) );
- }
+void RuleCopy(value_type * dest, value_type * source)
+{
+ memcpy(dest, source, _mainsys->attributes_num * sizeof(value_type));
+}
-int RuleEQ(value_type *first,value_type *second)
- { return !memcmp(first, second, _mainsys->attributes_num*sizeof(value_type) );
- }
+int RuleEQ(value_type * first, value_type * second)
+{
+ return !memcmp(first, second,
+ _mainsys->attributes_num * sizeof(value_type));
+}
-void AddRule(value_type *rules,int *count,value_type *rule)
- { int i;
- int size=_mainsys->attributes_num;
- for( i=0; i<*count; i++ )
- if ( RuleEQ( rules+i*size, rule ) )
- return;
- RuleCopy( rules+(*count)*size, rule );
- *count += 1;
- return;
- }
+void AddRule(value_type * rules, int *count, value_type * rule)
+{
+ int i;
+ int size = _mainsys->attributes_num;
+ for (i = 0; i < *count; i++)
+ if (RuleEQ(rules + i * size, rule))
+ return;
+ RuleCopy(rules + (*count) * size, rule);
+ *count += 1;
+ return;
+}
Modified: grass-addons/raster/mcda/r.roughset/rule1.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rule1.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rule1.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,23 +16,33 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SOME MORE QUERIES FOR SYSTEM ***/
+
/*** ( MENAGING RULES ) ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
#define MINUS ((value_type)-1)
-void RuleCopy( value_type *dest,value_type *source);
+void RuleCopy(value_type * dest, value_type * source);
+
/* copies a rule from source to dest */
-
-int RuleEQ( value_type *first,value_type *second);
+
+int RuleEQ(value_type * first, value_type * second);
+
/* returns 1 if first rule is equal to second */
-void AddRule( value_type *rules,int *size,value_type *rule);
+void AddRule(value_type * rules, int *size, value_type * rule);
+
/* adds new rule to array of rules */
/* if the rule is unique size is incremented */
Modified: grass-addons/raster/mcda/r.roughset/rule2.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rule2.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rule2.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,12 +16,19 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SOME MORE QUERIES FOR SYSTEM ***/
+
/*** ( FINDING RULES ) ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
@@ -28,538 +36,598 @@
#include <stdlib.h>
#include <string.h>
-int AllRules(value_type **rules,setA P,setA Q,int matrix_type)
- { int obj,attr,n,red;
- int memo=_mainsys->objects_num;
- int count=0;
- int size=_mainsys->setAsize;
- setA reducts=NULL;
- value_type *rule=NULL;
+int AllRules(value_type ** rules, setA P, setA Q, int matrix_type)
+{
+ int obj, attr, n, red;
+ int memo = _mainsys->objects_num;
+ int count = 0;
+ int size = _mainsys->setAsize;
+ setA reducts = NULL;
+ value_type *rule = NULL;
- *rules = (value_type *)malloc(memo*_mainsys->attributes_num*sizeof(value_type));
- if (*rules == NULL)
- ERROR(3);
- if ( !MatExist(_mainsys,MATA) )
- ERROR(5);
- rule=(value_type *)malloc(_mainsys->attributes_num*sizeof(value_type));
- if (rule == NULL)
- ERROR(3);
- for (obj=0; obj<_mainsys->objects_num; obj++)
- { if ( InitXforObject(_mainsys,obj,P,Q,matrix_type) < 0 )
- { free(rule); return(-_rerror); }
- else if ( !MatExist(_mainsys,MATX) )
- continue;
- n=Red(&reducts,MATX);
- CloseMat(_mainsys,MATX);
- if (memo<count+n)
- { memo=count+n;
- if ((*rules=(value_type *)realloc(*rules,
- memo*_mainsys->attributes_num*sizeof(value_type))) == NULL)
- { free(reducts);
- free(rule);
- ERROR(3)
+ *rules =
+ (value_type *) malloc(memo * _mainsys->attributes_num *
+ sizeof(value_type));
+ if (*rules == NULL)
+ ERROR(3);
+ if (!MatExist(_mainsys, MATA))
+ ERROR(5);
+ rule =
+ (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+ if (rule == NULL)
+ ERROR(3);
+ for (obj = 0; obj < _mainsys->objects_num; obj++) {
+ if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0) {
+ free(rule);
+ return (-_rerror);
+ }
+ else if (!MatExist(_mainsys, MATX))
+ continue;
+ n = Red(&reducts, MATX);
+ CloseMat(_mainsys, MATX);
+ if (memo < count + n) {
+ memo = count + n;
+ if ((*rules = (value_type *) realloc(*rules,
+ memo *
+ _mainsys->attributes_num *
+ sizeof(value_type))) ==
+ NULL) {
+ free(reducts);
+ free(rule);
+ ERROR(3)
}
- }
- for (red=0;red<n;red++)
- { for ( attr=_mainsys->attributes_num-1; attr>=0; attr--)
- if ( ContSetA( reducts+red*size, attr) || ContSetA(Q,attr) )
- rule[attr] = GetA(obj,attr);
- else
- rule[attr]=MINUS;
- AddRule(*rules, &count, rule);
- }
- if (n > 0)
- free(reducts);
- reducts = NULL;
- }
- free(rule);
- if ((*rules=(value_type *)realloc
- (*rules, count*_mainsys->attributes_num*sizeof(value_type)))==NULL)
- ERROR(3);
- return count;
- }
+ }
+ for (red = 0; red < n; red++) {
+ for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
+ if (ContSetA(reducts + red * size, attr) || ContSetA(Q, attr))
+ rule[attr] = GetA(obj, attr);
+ else
+ rule[attr] = MINUS;
+ AddRule(*rules, &count, rule);
+ }
+ if (n > 0)
+ free(reducts);
+ reducts = NULL;
+ }
+ free(rule);
+ if ((*rules = (value_type *) realloc
+ (*rules,
+ count * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+ ERROR(3);
+ return count;
+}
-int AllRulesForReducts(value_type **rules, cluster_type *reducts,
+int AllRulesForReducts(value_type ** rules, cluster_type * reducts,
int N, setA Q, int matrix_type)
- { int red,num,i,count=0;
- value_type *newrules=NULL; /* rules for a single reduct */
-
- *rules=NULL;
- for (red=0;red<N;red++)
- { num=AllRules(&newrules,reducts+red*_mainsys->setAsize,Q,matrix_type);
- if ((*rules=(value_type *)realloc(*rules,
- (count+num)*_mainsys->attributes_num*sizeof(value_type) )) == NULL)
- { free(newrules);
- ERROR(3)
- }
- for ( i=0; i<num; i++)
- AddRule(*rules,&count,newrules+i*_mainsys->attributes_num);
- if (num > 0)
- free(newrules);
- newrules=NULL;
- }
- if ((*rules=(value_type *)realloc
- (*rules,count*_mainsys->attributes_num*sizeof(value_type)))==NULL)
- ERROR(3);
- return count;
- }
+{
+ int red, num, i, count = 0;
+ value_type *newrules = NULL; /* rules for a single reduct */
+ *rules = NULL;
+ for (red = 0; red < N; red++) {
+ num =
+ AllRules(&newrules, reducts + red * _mainsys->setAsize, Q,
+ matrix_type);
+ if ((*rules =
+ (value_type *) realloc(*rules,
+ (count +
+ num) * _mainsys->attributes_num *
+ sizeof(value_type))) == NULL) {
+ free(newrules);
+ ERROR(3)
+ }
+ for (i = 0; i < num; i++)
+ AddRule(*rules, &count, newrules + i * _mainsys->attributes_num);
+ if (num > 0)
+ free(newrules);
+ newrules = NULL;
+ }
+ if ((*rules = (value_type *) realloc
+ (*rules,
+ count * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+ ERROR(3);
+ return count;
+}
-int SelectRules( value_type **rules, int *N, setO set, setA P, int option )
-{ int i,j,obj,find,newXsize,
- newN = 0,
- next=-1,
- size=_mainsys->attributes_num;
- setA red, newfull;
- SYSTEM *oldsys=_mainsys,
- *newsys=InitEmptySys();
- cluster_type *newX;
- value_type *newrules;
- SetParameters( newsys, *N, *N );
- newXsize = CardSetO(set) * (newsys->setAsize);
- newX = (cluster_type *)calloc( newXsize, _cluster_bytes );
- if( newX==NULL )
- { CloseSys( newsys );
- ERROR( 3 );
+
+int SelectRules(value_type ** rules, int *N, setO set, setA P, int option)
+{
+ int i, j, obj, find, newXsize,
+ newN = 0, next = -1, size = _mainsys->attributes_num;
+ setA red, newfull;
+ SYSTEM *oldsys = _mainsys, *newsys = InitEmptySys();
+ cluster_type *newX;
+ value_type *newrules;
+
+ SetParameters(newsys, *N, *N);
+ newXsize = CardSetO(set) * (newsys->setAsize);
+ newX = (cluster_type *) calloc(newXsize, _cluster_bytes);
+ if (newX == NULL) {
+ CloseSys(newsys);
+ ERROR(3);
}
- for( obj=0; obj<_mainsys->objects_num; obj++ )
- if( ContSetO( set,obj ) )
- for( i=0,next++; i<*N; i++ )
- { find=1;
- for( j=0; j<_mainsys->attributes_num; j++ )
- { if ( !ContSetA(P,j) ) continue;
- if ( (*rules+i*size)[j] != GetA(obj,j) )
- if ((*rules+i*size)[j]!=MINUS)
- { find=0; break; }
+ for (obj = 0; obj < _mainsys->objects_num; obj++)
+ if (ContSetO(set, obj))
+ for (i = 0, next++; i < *N; i++) {
+ find = 1;
+ for (j = 0; j < _mainsys->attributes_num; j++) {
+ if (!ContSetA(P, j))
+ continue;
+ if ((*rules + i * size)[j] != GetA(obj, j))
+ if ((*rules + i * size)[j] != MINUS) {
+ find = 0;
+ break;
+ }
+ }
+ if (find)
+ newX[next * newsys->setAsize + i / _cluster_bits] |=
+ _mask[i % _cluster_bits];
}
- if(find)
- newX[ next*newsys->setAsize+i/_cluster_bits ] |=
- _mask[ i%_cluster_bits ];
- }
- UseSys( newsys );
- newsys->matX = newX;
- newsys->matXsize = newXsize;
- newfull = InitFullSetA();
- InitX( newsys, newfull, newfull, MATX );
- free( newX );
- CloseSetA( newfull );
- if( _rerror!=0 )
- { free( newsys );
- UseSys( oldsys );
- ERROR( 3 );
+ UseSys(newsys);
+ newsys->matX = newX;
+ newsys->matXsize = newXsize;
+ newfull = InitFullSetA();
+ InitX(newsys, newfull, newfull, MATX);
+ free(newX);
+ CloseSetA(newfull);
+ if (_rerror != 0) {
+ free(newsys);
+ UseSys(oldsys);
+ ERROR(3);
}
- if( option==BESTOPT )
- { i = Red( &red, MATX );
- j = SelectOneShort( red, i );
+ if (option == BESTOPT) {
+ i = Red(&red, MATX);
+ j = SelectOneShort(red, i);
}
- else
- { red = InitEmptySetA();
- RedOptim( red, MATX );
- j=0;
+ else {
+ red = InitEmptySetA();
+ RedOptim(red, MATX);
+ j = 0;
}
- newN = CardSetA( red + j * newsys->setAsize );
- newrules = (value_type *)malloc( newN * oldsys->attributes_num *
- sizeof(value_type));
- if( newrules==NULL )
- { CloseSys( newsys );
- UseSys( oldsys );
- ERROR( 3 );
+ newN = CardSetA(red + j * newsys->setAsize);
+ newrules = (value_type *) malloc(newN * oldsys->attributes_num *
+ sizeof(value_type));
+ if (newrules == NULL) {
+ CloseSys(newsys);
+ UseSys(oldsys);
+ ERROR(3);
}
- for( i=0,obj=0; i<*N; i++ )
- if( ContSetA( red + j*newsys->setAsize , i ) )
- memcpy(newrules+obj++*oldsys->attributes_num,
- *rules+i*oldsys->attributes_num,
- oldsys->attributes_num*sizeof(value_type) );
- if( option==BESTOPT )
- free( red );
- else
- CloseSetA( red );
- if( *N>0 )
- free( *rules );
- *N = newN;
- *rules = newrules;
- UseSys( oldsys );
- CloseSys( newsys );
- return 0;
+ for (i = 0, obj = 0; i < *N; i++)
+ if (ContSetA(red + j * newsys->setAsize, i))
+ memcpy(newrules + obj++ * oldsys->attributes_num,
+ *rules + i * oldsys->attributes_num,
+ oldsys->attributes_num * sizeof(value_type));
+ if (option == BESTOPT)
+ free(red);
+ else
+ CloseSetA(red);
+ if (*N > 0)
+ free(*rules);
+ *N = newN;
+ *rules = newrules;
+ UseSys(oldsys);
+ CloseSys(newsys);
+ return 0;
}
-int BestRules( value_type **rules, setA P, setA Q, int matrix_type )
- { int i,obj,
- num=0, /* total number of rules */
- classnum=0; /* number of rules for class */
- setO processed, /* already covered objects */
- newclass; /* class */
- value_type *classrules=NULL; /* rules for a single class */
-
- *rules=(value_type *)malloc( Asize(_mainsys)*sizeof(value_type) );
- if (*rules==NULL)
- ERROR(3);
- if ( !MatExist( _mainsys,MATA ) )
- ERROR(5);
- processed = InitEmptySetO();
- newclass = InitEmptySetO();
- for( obj=0; obj<_mainsys->objects_num; obj++ )
- if( !ContSetO( processed, obj ) )
- { ClassSetO( newclass, obj, Q );
- classnum = 0;
- OrSetO( processed, processed, newclass );
- classnum = BestRulesForClass( &classrules, newclass, P, Q, matrix_type );
- for( i=0; i<classnum; i++ )
- AddRule( *rules,&num,classrules+i*_mainsys->attributes_num );
- if( classnum >0 )
- free( classrules );
- classrules = NULL;
- }
- CloseSetO( processed );
- CloseSetO( newclass );
- if( (*rules=(value_type *)realloc( *rules,
- num*_mainsys->attributes_num*sizeof(value_type) ) )==NULL )
- ERROR(3);
- return num;
+int BestRules(value_type ** rules, setA P, setA Q, int matrix_type)
+{
+ int i, obj, num = 0, /* total number of rules */
+ classnum = 0; /* number of rules for class */
+ setO processed, /* already covered objects */
+ newclass; /* class */
+ value_type *classrules = NULL; /* rules for a single class */
+
+ *rules = (value_type *) malloc(Asize(_mainsys) * sizeof(value_type));
+ if (*rules == NULL)
+ ERROR(3);
+ if (!MatExist(_mainsys, MATA))
+ ERROR(5);
+ processed = InitEmptySetO();
+ newclass = InitEmptySetO();
+ for (obj = 0; obj < _mainsys->objects_num; obj++)
+ if (!ContSetO(processed, obj)) {
+ ClassSetO(newclass, obj, Q);
+ classnum = 0;
+ OrSetO(processed, processed, newclass);
+ classnum =
+ BestRulesForClass(&classrules, newclass, P, Q, matrix_type);
+ for (i = 0; i < classnum; i++)
+ AddRule(*rules, &num,
+ classrules + i * _mainsys->attributes_num);
+ if (classnum > 0)
+ free(classrules);
+ classrules = NULL;
+ }
+ CloseSetO(processed);
+ CloseSetO(newclass);
+ if ((*rules = (value_type *) realloc(*rules,
+ num * _mainsys->attributes_num *
+ sizeof(value_type))) == NULL)
+ ERROR(3);
+ return num;
}
-int BestRulesForClass( value_type **rules, setO set, setA P, setA Q, int matrix_type )
- { int n,attr,obj,red,
- num=0; /* total number of rules */
- int size=_mainsys->setAsize;
- setA fewred=NULL, /* selected reducts */
- allred=NULL; /* all reducts */
- value_type *rule=NULL; /* single rule */
+int BestRulesForClass(value_type ** rules, setO set, setA P, setA Q,
+ int matrix_type)
+{
+ int n, attr, obj, red, num = 0; /* total number of rules */
+ int size = _mainsys->setAsize;
+ setA fewred = NULL, /* selected reducts */
+ allred = NULL; /* all reducts */
+ value_type *rule = NULL; /* single rule */
- *rules = NULL;
- if( !MatExist( _mainsys,MATA ) )
- ERROR(5);
- rule=(value_type *)malloc( _mainsys->attributes_num*sizeof(value_type) );
- if( rule==NULL )
- ERROR(3);
- for( obj=0; obj<_mainsys->objects_num; obj++ )
- if ( ContSetO( set, obj ) )
- { if( InitXforObject( _mainsys,obj,P,Q,matrix_type ) < 0 )
- { free( rule );
- return( -_rerror );
- }
- else if ( !MatExist(_mainsys,MATX) )
- continue;
- n = Red( &allred ,MATX);
- CloseMat(_mainsys,MATX);
- if( n>0 )
- { n = SelectAllShort( &fewred, allred, n );
- free( allred );
- }
- else
- { free( rule );
- return( -_rerror );
- }
- if( ( *rules=(value_type *)realloc
- (*rules,(n+num)*_mainsys->attributes_num*sizeof(value_type)) ) == NULL )
- { free( rule );
- free( fewred );
- return( -_rerror );
- }
- for( red=0; red<n; red++ )
- { for( attr=_mainsys->attributes_num-1; attr>=0; attr-- )
- if( ContSetA( fewred+red*size, attr ) || ContSetA( Q,attr ) )
- rule[attr] = GetA( obj,attr );
- else
- rule[attr] = MINUS;
- AddRule( *rules,&num,rule );
- }
- }
- if( n>0 )
- free( fewred );
- free( rule );
- if( SelectRules( rules, &num, set, P, BESTOPT ) < 0 )
- return ( -_rerror );
- if ( (*rules=(value_type *)realloc
- ( *rules,num*_mainsys->attributes_num*sizeof(value_type) ) )==NULL )
- ERROR(3);
- return num;
- }
+ *rules = NULL;
+ if (!MatExist(_mainsys, MATA))
+ ERROR(5);
+ rule =
+ (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+ if (rule == NULL)
+ ERROR(3);
+ for (obj = 0; obj < _mainsys->objects_num; obj++)
+ if (ContSetO(set, obj)) {
+ if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0) {
+ free(rule);
+ return (-_rerror);
+ }
+ else if (!MatExist(_mainsys, MATX))
+ continue;
+ n = Red(&allred, MATX);
+ CloseMat(_mainsys, MATX);
+ if (n > 0) {
+ n = SelectAllShort(&fewred, allred, n);
+ free(allred);
+ }
+ else {
+ free(rule);
+ return (-_rerror);
+ }
+ if ((*rules = (value_type *) realloc
+ (*rules,
+ (n +
+ num) * _mainsys->attributes_num * sizeof(value_type))) ==
+ NULL) {
+ free(rule);
+ free(fewred);
+ return (-_rerror);
+ }
+ for (red = 0; red < n; red++) {
+ for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
+ if (ContSetA(fewred + red * size, attr) ||
+ ContSetA(Q, attr))
+ rule[attr] = GetA(obj, attr);
+ else
+ rule[attr] = MINUS;
+ AddRule(*rules, &num, rule);
+ }
+ }
+ if (n > 0)
+ free(fewred);
+ free(rule);
+ if (SelectRules(rules, &num, set, P, BESTOPT) < 0)
+ return (-_rerror);
+ if ((*rules = (value_type *) realloc
+ (*rules,
+ num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+ ERROR(3);
+ return num;
+}
-int Rules( value_type **rules, setA P, setA Q, int matrix_type )
- { int i,obj,
- num=0, /* total number of rules */
- classnum=0; /* number of rules for class */
- setO processed, /* already covered objects */
- newclass; /* class */
- value_type *rule=NULL, /* single rule */
- *classrules=NULL; /* rules for class */
-
- *rules=(value_type *)malloc( Asize(_mainsys)*sizeof(value_type) );
- if (*rules==NULL)
- ERROR(3);
- if ( !MatExist( _mainsys,MATA ) )
- ERROR(5);
- rule = (value_type *)malloc( _mainsys->attributes_num*sizeof(value_type) );
- if ( rule==NULL )
- ERROR(3);
- processed = InitEmptySetO();
- newclass = InitEmptySetO();
- for( obj=0; obj<_mainsys->objects_num; obj++ )
- if ( !ContSetO( processed, obj ) )
- { ClassSetO( newclass, obj, Q );
- classnum = 0;
- OrSetO( processed, processed, newclass );
- classnum = RulesForClass( &classrules, newclass, P, Q, matrix_type );
- for ( i=0; i<classnum; i++ )
- AddRule( *rules,&num,classrules+i*_mainsys->attributes_num );
- if ( classnum>0 )
- free( classrules );
- classrules = NULL;
- }
- free( rule );
- CloseSetO( processed );
- CloseSetO( newclass );
- if ( (*rules=(value_type *)realloc
- ( *rules,num*_mainsys->attributes_num*sizeof(value_type) ) )==NULL )
- ERROR(3);
- return num;
+int Rules(value_type ** rules, setA P, setA Q, int matrix_type)
+{
+ int i, obj, num = 0, /* total number of rules */
+ classnum = 0; /* number of rules for class */
+ setO processed, /* already covered objects */
+ newclass; /* class */
+ value_type *rule = NULL, /* single rule */
+ *classrules = NULL; /* rules for class */
+
+ *rules = (value_type *) malloc(Asize(_mainsys) * sizeof(value_type));
+ if (*rules == NULL)
+ ERROR(3);
+ if (!MatExist(_mainsys, MATA))
+ ERROR(5);
+ rule =
+ (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+ if (rule == NULL)
+ ERROR(3);
+ processed = InitEmptySetO();
+ newclass = InitEmptySetO();
+ for (obj = 0; obj < _mainsys->objects_num; obj++)
+ if (!ContSetO(processed, obj)) {
+ ClassSetO(newclass, obj, Q);
+ classnum = 0;
+ OrSetO(processed, processed, newclass);
+ classnum =
+ RulesForClass(&classrules, newclass, P, Q, matrix_type);
+ for (i = 0; i < classnum; i++)
+ AddRule(*rules, &num,
+ classrules + i * _mainsys->attributes_num);
+ if (classnum > 0)
+ free(classrules);
+ classrules = NULL;
+ }
+ free(rule);
+ CloseSetO(processed);
+ CloseSetO(newclass);
+ if ((*rules = (value_type *) realloc
+ (*rules,
+ num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+ ERROR(3);
+ return num;
}
-int RulesForClass( value_type **rules, setO set, setA P, setA Q, int matrix_type )
- { int j,n,obj,red,
- num=0; /* total number of rules */
- int size=_mainsys->setAsize;
- setA fewred=NULL, /* selected reducts */
- allred=NULL; /* all reducts */
- value_type *rule=NULL; /* single rule */
+int RulesForClass(value_type ** rules, setO set, setA P, setA Q,
+ int matrix_type)
+{
+ int j, n, obj, red, num = 0; /* total number of rules */
+ int size = _mainsys->setAsize;
+ setA fewred = NULL, /* selected reducts */
+ allred = NULL; /* all reducts */
+ value_type *rule = NULL; /* single rule */
- *rules = NULL;
- if( !MatExist( _mainsys,MATA ) )
- ERROR(5);
- rule=(value_type *)malloc( _mainsys->attributes_num*sizeof(value_type) );
- if( rule==NULL )
- ERROR(3);
- for( obj=0; obj<_mainsys->objects_num; obj++ )
- if ( ContSetO( set, obj ) )
- { if( InitXforObject( _mainsys,obj,P,Q,matrix_type ) < 0 )
- { free( rule );
- return( -_rerror );
- }
- else if ( !MatExist(_mainsys,MATX) )
- continue;
- n = Red( &allred ,MATX);
- CloseMat(_mainsys,MATX);
- if( n>0 )
- { n = SelectAllShort( &fewred, allred, n );
- free( allred );
- }
- else
- { free( rule );
- return( -_rerror );
- }
- if( ( *rules=(value_type *)realloc
- (*rules,(n+num)*_mainsys->attributes_num*sizeof(value_type)) ) == NULL )
- { free( rule );
- free( fewred );
- return( -_rerror );
- }
- for( red=0; red<n; red++ )
- { for( j=_mainsys->attributes_num-1; j>=0; j-- )
- if( ContSetA( fewred+red*size, j ) || ContSetA( Q,j ) )
- rule[j] = GetA( obj,j );
- else
- rule[j] = MINUS;
- AddRule( *rules,&num,rule );
- }
- }
- if( n>0 )
- free( fewred );
- free( rule );
- if( SelectRules( rules, &num, set, P, FASTOPT ) < 0 )
- return ( -_rerror );
- if ( (*rules=(value_type *)realloc
- ( *rules,num*_mainsys->attributes_num*sizeof(value_type) ) )==NULL )
- ERROR(3);
- return num;
- }
+ *rules = NULL;
+ if (!MatExist(_mainsys, MATA))
+ ERROR(5);
+ rule =
+ (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+ if (rule == NULL)
+ ERROR(3);
+ for (obj = 0; obj < _mainsys->objects_num; obj++)
+ if (ContSetO(set, obj)) {
+ if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0) {
+ free(rule);
+ return (-_rerror);
+ }
+ else if (!MatExist(_mainsys, MATX))
+ continue;
+ n = Red(&allred, MATX);
+ CloseMat(_mainsys, MATX);
+ if (n > 0) {
+ n = SelectAllShort(&fewred, allred, n);
+ free(allred);
+ }
+ else {
+ free(rule);
+ return (-_rerror);
+ }
+ if ((*rules = (value_type *) realloc
+ (*rules,
+ (n +
+ num) * _mainsys->attributes_num * sizeof(value_type))) ==
+ NULL) {
+ free(rule);
+ free(fewred);
+ return (-_rerror);
+ }
+ for (red = 0; red < n; red++) {
+ for (j = _mainsys->attributes_num - 1; j >= 0; j--)
+ if (ContSetA(fewred + red * size, j) || ContSetA(Q, j))
+ rule[j] = GetA(obj, j);
+ else
+ rule[j] = MINUS;
+ AddRule(*rules, &num, rule);
+ }
+ }
+ if (n > 0)
+ free(fewred);
+ free(rule);
+ if (SelectRules(rules, &num, set, P, FASTOPT) < 0)
+ return (-_rerror);
+ if ((*rules = (value_type *) realloc
+ (*rules,
+ num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+ ERROR(3);
+ return num;
+}
-int FastRules(value_type **rules,setA P,setA Q,int matrix_type)
- { int obj,attr,n,red,count=0;
- int size=_mainsys->setAsize;
- setA reducts=NULL;
- value_type *rule=NULL;
-
- *rules=(value_type *)malloc(Asize(_mainsys)*sizeof(value_type));
- if(*rules==NULL)
- ERROR(3);
- if(!MatExist(_mainsys,MATA))
- ERROR(5);
- rule=(value_type *)malloc(_mainsys->attributes_num*sizeof(value_type));
- if(rule==NULL)
- ERROR(3);
- for(obj=0;obj<_mainsys->objects_num;obj++)
- { if(InitXforObject(_mainsys,obj,P,Q,matrix_type)<0)
- { free(rule); return(-_rerror); }
- else if ( !MatExist(_mainsys,MATX) )
- continue;
- n=Red(&reducts, MATX);
- CloseMat(_mainsys,MATX);
- red = SelectOneShort( reducts, n );
- for (attr=_mainsys->attributes_num-1;attr>=0;attr--)
- if (ContSetA(reducts+red*size,attr) || ContSetA(Q,attr))
- rule[attr]=GetA(obj,attr);
- else
- rule[attr]=MINUS;
- AddRule(*rules,&count,rule);
- if (n>0) free(reducts);
- reducts=NULL;
+int FastRules(value_type ** rules, setA P, setA Q, int matrix_type)
+{
+ int obj, attr, n, red, count = 0;
+ int size = _mainsys->setAsize;
+ setA reducts = NULL;
+ value_type *rule = NULL;
+
+ *rules = (value_type *) malloc(Asize(_mainsys) * sizeof(value_type));
+ if (*rules == NULL)
+ ERROR(3);
+ if (!MatExist(_mainsys, MATA))
+ ERROR(5);
+ rule =
+ (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+ if (rule == NULL)
+ ERROR(3);
+ for (obj = 0; obj < _mainsys->objects_num; obj++) {
+ if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0) {
+ free(rule);
+ return (-_rerror);
+ }
+ else if (!MatExist(_mainsys, MATX))
+ continue;
+ n = Red(&reducts, MATX);
+ CloseMat(_mainsys, MATX);
+ red = SelectOneShort(reducts, n);
+ for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
+ if (ContSetA(reducts + red * size, attr) || ContSetA(Q, attr))
+ rule[attr] = GetA(obj, attr);
+ else
+ rule[attr] = MINUS;
+ AddRule(*rules, &count, rule);
+ if (n > 0)
+ free(reducts);
+ reducts = NULL;
}
- free(rule);
- if ((*rules=(value_type *)realloc
- (*rules, count*_mainsys->attributes_num*sizeof(value_type))) == NULL)
- ERROR(3);
- return count;
- }
+ free(rule);
+ if ((*rules = (value_type *) realloc
+ (*rules,
+ count * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+ ERROR(3);
+ return count;
+}
-int VeryFastRules(value_type **rules,setA P,setA Q,int matrix_type)
-{ int obj,attr,count=0;
- setA reduct;
- value_type *rule=NULL;
-
- *rules=(value_type *)malloc(Asize(_mainsys)*sizeof(value_type));
- if (*rules==NULL)
- ERROR(3);
- if (!MatExist(_mainsys,MATA))
- ERROR(5);
- rule=(value_type *)malloc(_mainsys->attributes_num*sizeof(value_type));
- if (rule==NULL)
- ERROR(3);
- reduct = InitEmptySetA();
- for(obj=0;obj<_mainsys->objects_num;obj++)
- { if(InitXforObject(_mainsys,obj,P,Q,matrix_type)<0)
- { free(rule); return(-_rerror); }
- else if ( !MatExist(_mainsys,MATX) )
- continue;
- RedOptim(reduct, MATX);
- CloseMat(_mainsys,MATX);
- for (attr=_mainsys->attributes_num-1;attr>=0;attr--)
- if (ContSetA(reduct,attr) || ContSetA(Q,attr) )
- rule[attr]=GetA(obj,attr);
- else
- rule[attr]=MINUS;
- AddRule(*rules,&count,rule);
+int VeryFastRules(value_type ** rules, setA P, setA Q, int matrix_type)
+{
+ int obj, attr, count = 0;
+ setA reduct;
+ value_type *rule = NULL;
+
+ *rules = (value_type *) malloc(Asize(_mainsys) * sizeof(value_type));
+ if (*rules == NULL)
+ ERROR(3);
+ if (!MatExist(_mainsys, MATA))
+ ERROR(5);
+ rule =
+ (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+ if (rule == NULL)
+ ERROR(3);
+ reduct = InitEmptySetA();
+ for (obj = 0; obj < _mainsys->objects_num; obj++) {
+ if (InitXforObject(_mainsys, obj, P, Q, matrix_type) < 0) {
+ free(rule);
+ return (-_rerror);
+ }
+ else if (!MatExist(_mainsys, MATX))
+ continue;
+ RedOptim(reduct, MATX);
+ CloseMat(_mainsys, MATX);
+ for (attr = _mainsys->attributes_num - 1; attr >= 0; attr--)
+ if (ContSetA(reduct, attr) || ContSetA(Q, attr))
+ rule[attr] = GetA(obj, attr);
+ else
+ rule[attr] = MINUS;
+ AddRule(*rules, &count, rule);
}
- free( rule );
- CloseSetA( reduct );
- if ((*rules=(value_type *)realloc
- (*rules, count*_mainsys->attributes_num*sizeof(value_type))) == NULL)
- ERROR(3);
- return count;
+ free(rule);
+ CloseSetA(reduct);
+ if ((*rules = (value_type *) realloc
+ (*rules,
+ count * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+ ERROR(3);
+ return count;
}
-int ApprRules( value_type **rules, setA P, setA Q, int option, int matrix_type )
- { int i,obj,
- num=0, /* total number of rules */
- classnum=0; /* number of rules for class */
- setO processed, /* already covered objects */
- newclass; /* class */
- value_type *rule=NULL, /* single rule */
- *classrules=NULL; /* rules for class */
-
- *rules=(value_type *)malloc( Asize(_mainsys)*sizeof(value_type) );
- if (*rules==NULL)
- ERROR(3);
- if ( !MatExist( _mainsys,MATA ) )
- ERROR(5);
- rule = (value_type *)malloc( _mainsys->attributes_num*sizeof(value_type) );
- if ( rule==NULL )
- ERROR(3);
- processed = InitEmptySetO();
- newclass = InitEmptySetO();
- for( obj=0; obj<_mainsys->objects_num; obj++ )
- if ( !ContSetO( processed, obj ) )
- { ClassSetO( newclass, obj, Q );
- classnum = 0;
- OrSetO( processed, processed, newclass );
- classnum = ApprRulesForClass( &classrules, newclass, P, Q,
- option, matrix_type );
- for ( i=0; i<classnum; i++ )
- AddRule( *rules,&num,classrules+i*_mainsys->attributes_num );
- if ( classnum>0 )
- free( classrules );
- classrules = NULL;
- }
- free( rule );
- CloseSetO( processed );
- CloseSetO( newclass );
- if ( (*rules=(value_type *)realloc
- ( *rules,num*_mainsys->attributes_num*sizeof(value_type) ) )==NULL )
- ERROR(3);
- return num;
- }
+int ApprRules(value_type ** rules, setA P, setA Q, int option,
+ int matrix_type)
+{
+ int i, obj, num = 0, /* total number of rules */
+ classnum = 0; /* number of rules for class */
+ setO processed, /* already covered objects */
+ newclass; /* class */
+ value_type *rule = NULL, /* single rule */
+ *classrules = NULL; /* rules for class */
+ *rules = (value_type *) malloc(Asize(_mainsys) * sizeof(value_type));
+ if (*rules == NULL)
+ ERROR(3);
+ if (!MatExist(_mainsys, MATA))
+ ERROR(5);
+ rule =
+ (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+ if (rule == NULL)
+ ERROR(3);
+ processed = InitEmptySetO();
+ newclass = InitEmptySetO();
+ for (obj = 0; obj < _mainsys->objects_num; obj++)
+ if (!ContSetO(processed, obj)) {
+ ClassSetO(newclass, obj, Q);
+ classnum = 0;
+ OrSetO(processed, processed, newclass);
+ classnum = ApprRulesForClass(&classrules, newclass, P, Q,
+ option, matrix_type);
+ for (i = 0; i < classnum; i++)
+ AddRule(*rules, &num,
+ classrules + i * _mainsys->attributes_num);
+ if (classnum > 0)
+ free(classrules);
+ classrules = NULL;
+ }
+ free(rule);
+ CloseSetO(processed);
+ CloseSetO(newclass);
+ if ((*rules = (value_type *) realloc
+ (*rules,
+ num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+ ERROR(3);
+ return num;
+}
-
-int ApprRulesForClass( value_type **rules, setO set, setA P, setA Q,
- int option, int matrix_type )
- { int j,n,obj,red,
- num=0; /* total number of rules */
- int size=_mainsys->setAsize;
- setA fewred=NULL, /* selected reducts */
- allred=NULL; /* all reducts */
- value_type *rule=NULL; /* single rule */
- setO aclass;
-
- *rules = NULL;
- if( !MatExist( _mainsys,MATA ) )
- ERROR(5);
- rule=(value_type *)malloc( _mainsys->attributes_num*sizeof(value_type) );
- if( rule==NULL )
- ERROR(3);
- aclass = InitEmptySetO();
- if ( option==LOWER ) LowAppr( aclass, set, P, matrix_type );
- else if (option==UPPER ) UppAppr( aclass, set, P, matrix_type );
- else CopySetO( aclass, set );
- for( obj=0; obj<_mainsys->objects_num; obj++ )
- if ( ContSetO( aclass, obj ) )
- { if( InitXforObjectFromClass( _mainsys,obj,P,aclass,matrix_type ) < 0 )
- { free( rule );
- return( -_rerror );
- }
- else if ( !MatExist(_mainsys,MATX) )
- continue;
- n = Red( &allred ,MATX);
- CloseMat(_mainsys,MATX);
- if( n>0 )
- { n = SelectAllShort( &fewred, allred, n );
- free( allred );
- }
- else
- { free( rule );
- return( -_rerror );
- }
- if( ( *rules=(value_type *)realloc
- (*rules,(n+num)*_mainsys->attributes_num*sizeof(value_type)) ) == NULL )
- { free( rule );
- free( fewred );
- return( -_rerror );
- }
- for( red=0; red<n; red++ )
- { for( j=_mainsys->attributes_num-1; j>=0; j-- )
- if( ContSetA( fewred+red*size, j ) || ContSetA( Q,j ) )
- rule[j] = GetA( obj,j );
- else
- rule[j] = MINUS;
- AddRule( *rules,&num,rule );
- }
- }
- if( n>0 )
- free( fewred );
- free( rule );
- if( SelectRules( rules, &num, set, P, FASTOPT ) < 0 )
- return ( -_rerror );
- if ( (*rules=(value_type *)realloc
- ( *rules,num*_mainsys->attributes_num*sizeof(value_type) ) )==NULL )
- ERROR(3);
- return num;
- }
-
+int ApprRulesForClass(value_type ** rules, setO set, setA P, setA Q,
+ int option, int matrix_type)
+{
+ int j, n, obj, red, num = 0; /* total number of rules */
+ int size = _mainsys->setAsize;
+ setA fewred = NULL, /* selected reducts */
+ allred = NULL; /* all reducts */
+ value_type *rule = NULL; /* single rule */
+ setO aclass;
+
+ *rules = NULL;
+ if (!MatExist(_mainsys, MATA))
+ ERROR(5);
+ rule =
+ (value_type *) malloc(_mainsys->attributes_num * sizeof(value_type));
+ if (rule == NULL)
+ ERROR(3);
+ aclass = InitEmptySetO();
+ if (option == LOWER)
+ LowAppr(aclass, set, P, matrix_type);
+ else if (option == UPPER)
+ UppAppr(aclass, set, P, matrix_type);
+ else
+ CopySetO(aclass, set);
+ for (obj = 0; obj < _mainsys->objects_num; obj++)
+ if (ContSetO(aclass, obj)) {
+ if (InitXforObjectFromClass(_mainsys, obj, P, aclass, matrix_type)
+ < 0) {
+ free(rule);
+ return (-_rerror);
+ }
+ else if (!MatExist(_mainsys, MATX))
+ continue;
+ n = Red(&allred, MATX);
+ CloseMat(_mainsys, MATX);
+ if (n > 0) {
+ n = SelectAllShort(&fewred, allred, n);
+ free(allred);
+ }
+ else {
+ free(rule);
+ return (-_rerror);
+ }
+ if ((*rules = (value_type *) realloc
+ (*rules,
+ (n +
+ num) * _mainsys->attributes_num * sizeof(value_type))) ==
+ NULL) {
+ free(rule);
+ free(fewred);
+ return (-_rerror);
+ }
+ for (red = 0; red < n; red++) {
+ for (j = _mainsys->attributes_num - 1; j >= 0; j--)
+ if (ContSetA(fewred + red * size, j) || ContSetA(Q, j))
+ rule[j] = GetA(obj, j);
+ else
+ rule[j] = MINUS;
+ AddRule(*rules, &num, rule);
+ }
+ }
+ if (n > 0)
+ free(fewred);
+ free(rule);
+ if (SelectRules(rules, &num, set, P, FASTOPT) < 0)
+ return (-_rerror);
+ if ((*rules = (value_type *) realloc
+ (*rules,
+ num * _mainsys->attributes_num * sizeof(value_type))) == NULL)
+ ERROR(3);
+ return num;
+}
Modified: grass-addons/raster/mcda/r.roughset/rule2.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rule2.h 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rule2.h 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -15,12 +16,19 @@
* for details.
*
*****************************************************************************/
+
/*** ***/
+
/*** SOME MORE QUERIES FOR SYSTEM ***/
+
/*** ( FINDING RULES ) ***/
+
/*** ***/
+
/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
/*** ***/
+
/*****************************************************************************/
#define BESTOPT 0
@@ -30,64 +38,73 @@
#define LOWER 1
#define UPPER 2
-int AllRules(value_type **rules, setA P, setA Q, int matrix_type);
+int AllRules(value_type ** rules, setA P, setA Q, int matrix_type);
+
/* finds all possible rules for condition attributes P */
/* and decision Q, allocates memory, returns number of rules */
-
-int AllRulesForReducts(value_type **rules, cluster_type *reducts,
+
+int AllRulesForReducts(value_type ** rules, cluster_type * reducts,
int N, setA Q, int matrix_type);
- /* finds all possible rules for each reduct separatly */
- /* allocates memory, returns number of rules */
+ /* finds all possible rules for each reduct separatly */
+ /* allocates memory, returns number of rules */
-int SelectRules( value_type **rules, int *N, setO set, setA P, int option );
+int SelectRules(value_type ** rules, int *N, setO set, setA P, int option);
+
/* reduce set of rules to cover only some objects */
/* on attributes P, reallocates memory and decrease N */
/* option: FASTOPT for shortcomings */
/* BESTOPT for optimal computing */
-
-int BestRules( value_type **rules, setA P, setA Q, int matrix_type );
+
+int BestRules(value_type ** rules, setA P, setA Q, int matrix_type);
+
/* finds minimal set of rules, allocates memory */
/* P - condition attributes; Q - decision attributes */
- /* returns number of rules */
+ /* returns number of rules */
-int BestRulesForClass( value_type **rules, setO set, setA P, setA Q, int matrix_type );
+int BestRulesForClass(value_type ** rules, setO set, setA P, setA Q,
+ int matrix_type);
/* finds minimal set of rules to cover objects from set */
/* P - condition attributes; Q - decision attributes */
- /* allocates memory, returns number of rules */
-
-int Rules( value_type **rules, setA P, setA Q, int matrix_type );
+ /* allocates memory, returns number of rules */
+
+int Rules(value_type ** rules, setA P, setA Q, int matrix_type);
+
/* finds set of rules, allocates memory */
/* P - condition attributes; Q - decision attributes */
- /* returns number of rules */
+ /* returns number of rules */
-int RulesForClass( value_type **rules, setO set, setA P, setA Q, int matrix_type );
+int RulesForClass(value_type ** rules, setO set, setA P, setA Q,
+ int matrix_type);
/* finds set of rules to cover objects from set */
/* P - condition attributes; Q - decision attributes */
- /* allocates memory, returns number of rules */
+ /* allocates memory, returns number of rules */
-int FastRules(value_type **rules,setA P,setA Q, int matrix_type);
+int FastRules(value_type ** rules, setA P, setA Q, int matrix_type);
+
/* finds quickly set of rules, allocates memory */
/* P - condition attributes; Q - decision attributes */
- /* returns number of rules */
+ /* returns number of rules */
-int VeryFastRules(value_type **rules,setA P,setA Q, int matrix_type);
+int VeryFastRules(value_type ** rules, setA P, setA Q, int matrix_type);
+
/* finds very quickly set of rules, allocates memory */
/* P - condition attributes; Q - decision attributes */
- /* returns number of rules */
+ /* returns number of rules */
-int ApprRules( value_type **rules, setA P, setA Q, int option, int matrix_type );
+int ApprRules(value_type ** rules, setA P, setA Q, int option,
+ int matrix_type);
/* finds set of rules for approximated classes */
/* P - condition attributes; Q - decision attributes */
/* option: LOWER - lower approximation - certain rules */
/* UPPER - upper approximation - possible rules */
/* NORMAL - no approximation - normal rules */
- /* allocates memory, returns number of rules */
+ /* allocates memory, returns number of rules */
-int ApprRulesForClass( value_type **rules, setO set, setA P, setA Q,
- int option, int matrix_type );
+int ApprRulesForClass(value_type ** rules, setO set, setA P, setA Q,
+ int option, int matrix_type);
/* finds set of rules for approximated class (set) */
/* P - condition attributes; Q - decision attributes */
/* option: LOWER - lower approximation - certain rules */
/* UPPER - upper approximation - possible rules */
/* NORMAL - no approximation - normal rules */
- /* allocates memory, returns number of rules */
+ /* allocates memory, returns number of rules */
Modified: grass-addons/raster/mcda/r.roughset/rules_extr.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rules_extr.c 2010-04-03 09:17:52 UTC (rev 41683)
+++ grass-addons/raster/mcda/r.roughset/rules_extr.c 2010-04-03 09:29:09 UTC (rev 41684)
@@ -1,3 +1,4 @@
+
/****************************************************************************
*
* MODULE: r.roughset
@@ -33,390 +34,429 @@
#include "rough.h"
#include "localproto.h"
-int rough_analysis(int nrows, int ncols, char *name, int *classify_vect, struct input *attributes, char *file_sample_txt, int strgy, int cls);
+int rough_analysis(int nrows, int ncols, char *name, int *classify_vect,
+ struct input *attributes, char *file_sample_txt, int strgy,
+ int cls);
-void rough_set_library_out(int nrows, int ncols, int nattributes, struct input *attributes, char *file_out_sys);
+void rough_set_library_out(int nrows, int ncols, int nattributes,
+ struct input *attributes, char *file_out_sys);
-void output_to_txt( FILE *file_out_txt, value_type* rules, setA P,setA Q, setA core, setA beg, int n, SYSTEM * sys1, int strgy, int r, int *opr, struct input *attributes);
+void output_to_txt(FILE * file_out_txt, value_type * rules, setA P, setA Q,
+ setA core, setA beg, int n, SYSTEM * sys1, int strgy,
+ int r, int *opr, struct input *attributes);
-void fPrintSetA( FILE *file, setA set );
-void fPrintSetO( FILE *file, setO set );
-void fPrintRules( FILE *file, value_type* rules, int N, int *opr, setA P, setA Q, struct input *attributes);
+void fPrintSetA(FILE * file, setA set);
+void fPrintSetO(FILE * file, setO set);
+void fPrintRules(FILE * file, value_type * rules, int N, int *opr, setA P,
+ setA Q, struct input *attributes);
-float MeanAttrInRule( value_type *rules, int N, setA P );
+float MeanAttrInRule(value_type * rules, int N, setA P);
-int LowRules( value_type **rules, setA P, setA Q, int mat );
-int UppRules( value_type **rules, setA P, setA Q, int mat );
-int NormRules( value_type **rules, setA P, setA Q, int mat );
+int LowRules(value_type ** rules, setA P, setA Q, int mat);
+int UppRules(value_type ** rules, setA P, setA Q, int mat);
+int NormRules(value_type ** rules, setA P, setA Q, int mat);
-int rough_analysis(int nrows, int ncols, char *name, int *classify_vect, struct input *attributes, char *file_sample_txt, int strgy, int cls)
+int rough_analysis(int nrows, int ncols, char *name, int *classify_vect,
+ struct input *attributes, char *file_sample_txt, int strgy,
+ int cls)
{
- SYSTEM *sys1, *sys2; /* Information system descriptor structures.*/
- /* It contains information about the system parameters (number of objects, number of attributes, system name. */
- value_type value, *buf,*rules; /* stores a single value of attribute (used for attribute-value table and rule implementation)*/
- char c;
- int n,j,i,r, *opr;
- setA beg,P,Q,full,core; /*set of attributes*/
- setO train; /*set of object*/
- FILE *file_out_txt; /* pointer to text output file */
- int (*genrules)( value_type**, setA, setA, int );
-
- int nattributes, nobjects=nrows*ncols; /*objects in information system are all raster cells in working location with a defined resolution */
- int row, col,object,attribute; /*index and counter*/
-
- sys1=InitEmptySys(); /* Allocates memory for a system descriptor and returns a pointer.*/
-
- if(file_sample_txt != NULL) /*use sample txt file if input in dec_txt->answer isn't NUL*/
- {name=file_sample_txt;
- G_message("Using %s sys file for rules generation",name);} /* Imports a system from a file of the special format.*/
-
-
- FileToSys(sys1,name); /* Imports a system from a file of the special format.*/
-
- if (_rerror>0)
- { G_fatal_error(" Can't open data file \n");
- return(1);}
-
- strcat(name,".out");
-
- if (!(file_out_txt=fopen(name,"a"))) /*output text file*/
- {G_fatal_error(" Can't open output file \n");
- return(1);}
-
- UseSys(sys1); /* Activates a system. All routines will work on this indicated system data and parameters.*/
-
- if (_rerror>0)
- {G_fatal_error("Can't open information system <%s>\n",sys1->name);
- return(1); }
-
-
- full=InitFullSetA(); /*Initialize a full set. Allocates memory for a set and initialize it with all elements of
- domain based on the active information system */
-
- InitD(sys1); /*Generates MATRIX D from MATRIX A.Connected to sys and filled*/
-
- P=InitEmptySetA(); /* Initialize an empty set. Memory size determined by active information system parameters */
- Q=InitEmptySetA();
+ SYSTEM *sys1, *sys2; /* Information system descriptor structures. */
- nattributes=(AttributesNum(sys1)-1);
-
- /* define attribute */
- for(i=0;i<nattributes;i++)
- {
- AddSetA(P,i); /* Adds a single element to a set */
- }
-
- /* define decision */
- AddSetA(Q,(AttributesNum(sys1)-1));
-
- InitX(sys1,P,Q,MATD); /*Generates MATRIX X from another matrix designed for use in core and reducts queries. */
- core=InitEmptySetA();
- Core(core,MATX); /* Puts a core of the active information system to core. */
-
- RedOptim( core, MATX ); /* Provides the optimized heuristic search for a single reduct */
-
- CloseSetA(core); /* Frees memory allocated for a set */
- n=RedFew(&beg,MATX); /*Finds all reducts shorter than the first one found.*/
- CloseMat(sys1,MATX); /* Closes a matrix. */
-
- if ( n>0 ) free( beg );
+ /* It contains information about the system parameters (number of objects, number of attributes, system name. */
+ value_type value, *buf, *rules; /* stores a single value of attribute (used for attribute-value table and rule implementation) */
+ char c;
+ int n, j, i, r, *opr;
+ setA beg, P, Q, full, core; /*set of attributes */
+ setO train; /*set of object */
+ FILE *file_out_txt; /* pointer to text output file */
+ int (*genrules) (value_type **, setA, setA, int);
- switch ( strgy )
- {
- case 0: genrules = VeryFastRules;
- break;
- case 1: genrules = FastRules;
- break;
- case 2: genrules = Rules;
- break;
- case 3: genrules = BestRules;
- break;
- case 4: genrules = AllRules;
- break;
- case 5: genrules = LowRules;
- break;
- case 6: genrules = UppRules;
- break;
- default: genrules = NormRules;
- break;
- }
+ int nattributes, nobjects = nrows * ncols; /*objects in information system are all raster cells in working location with a defined resolution */
+ int row, col, object, attribute; /*index and counter */
- r = genrules ( &rules, P, Q, MATD ); /* rules generator*/
-
- if (r>0) {opr = StrengthOfRules( rules, r ); } /* Creates a table of rules strengths*/
-
+ sys1 = InitEmptySys(); /* Allocates memory for a system descriptor and returns a pointer. */
+ if (file_sample_txt != NULL) { /*use sample txt file if input in dec_txt->answer isn't NUL */
+ name = file_sample_txt;
+ G_message("Using %s sys file for rules generation", name);
+ } /* Imports a system from a file of the special format. */
+
+
+ FileToSys(sys1, name); /* Imports a system from a file of the special format. */
+
+ if (_rerror > 0) {
+ G_fatal_error(" Can't open data file \n");
+ return (1);
+ }
+
+ strcat(name, ".out");
+
+ if (!(file_out_txt = fopen(name, "a"))) { /*output text file */
+ G_fatal_error(" Can't open output file \n");
+ return (1);
+ }
+
+ UseSys(sys1); /* Activates a system. All routines will work on this indicated system data and parameters. */
+
+ if (_rerror > 0) {
+ G_fatal_error("Can't open information system <%s>\n", sys1->name);
+ return (1);
+ }
+
+
+ full = InitFullSetA(); /*Initialize a full set. Allocates memory for a set and initialize it with all elements of
+ domain based on the active information system */
+
+ InitD(sys1); /*Generates MATRIX D from MATRIX A.Connected to sys and filled */
+
+ P = InitEmptySetA(); /* Initialize an empty set. Memory size determined by active information system parameters */
+ Q = InitEmptySetA();
+
+ nattributes = (AttributesNum(sys1) - 1);
+
+ /* define attribute */
+ for (i = 0; i < nattributes; i++) {
+ AddSetA(P, i); /* Adds a single element to a set */
+ }
+
+ /* define decision */
+ AddSetA(Q, (AttributesNum(sys1) - 1));
+
+ InitX(sys1, P, Q, MATD); /*Generates MATRIX X from another matrix designed for use in core and reducts queries. */
+ core = InitEmptySetA();
+ Core(core, MATX); /* Puts a core of the active information system to core. */
+
+ RedOptim(core, MATX); /* Provides the optimized heuristic search for a single reduct */
+
+ CloseSetA(core); /* Frees memory allocated for a set */
+ n = RedFew(&beg, MATX); /*Finds all reducts shorter than the first one found. */
+ CloseMat(sys1, MATX); /* Closes a matrix. */
+
+ if (n > 0)
+ free(beg);
+
+ switch (strgy) {
+ case 0:
+ genrules = VeryFastRules;
+ break;
+ case 1:
+ genrules = FastRules;
+ break;
+ case 2:
+ genrules = Rules;
+ break;
+ case 3:
+ genrules = BestRules;
+ break;
+ case 4:
+ genrules = AllRules;
+ break;
+ case 5:
+ genrules = LowRules;
+ break;
+ case 6:
+ genrules = UppRules;
+ break;
+ default:
+ genrules = NormRules;
+ break;
+ }
+
+ r = genrules(&rules, P, Q, MATD); /* rules generator */
+
+ if (r > 0) {
+ opr = StrengthOfRules(rules, r);
+ } /* Creates a table of rules strengths */
+
+
/**************************Output text files************************************/
+
/***********print output about sys1 in a txt file (file_out_txt)****************/
- output_to_txt(file_out_txt,rules,P,Q,core,beg,n,sys1,strgy,r,opr,attributes);
-
+ output_to_txt(file_out_txt, rules, P, Q, core, beg, n, sys1, strgy, r,
+ opr, attributes);
+
/**************************close all********************************************/
-
+
//CloseSys(sys1); /* close sys1 */
-
+
/*******************************************************************************/
+
/**************************Classify*********************************************/
-
- sys2=InitEmptySys();
- SetParameters(sys2,nobjects,nattributes); /* assigning system parameters */
- ConnectA(sys2,malloc(MatMemSize(sys2,MATA))); /* Connects MATRIX A to a system descriptor. */
- /*MatMemSize: Returns size of memory used by matrix.*/
- SetName(sys2,"classys");
- UseSys(sys2); /* active system sys2 was created in application and has only MATRIX A */
-
- if (_rerror>0)
- { G_fatal_error("Can't open information system <%s>\n",_mainsys->name);
- return(1); }
-
+
+ sys2 = InitEmptySys();
+ SetParameters(sys2, nobjects, nattributes); /* assigning system parameters */
+ ConnectA(sys2, malloc(MatMemSize(sys2, MATA))); /* Connects MATRIX A to a system descriptor. */
+ /*MatMemSize: Returns size of memory used by matrix. */
+ SetName(sys2, "classys");
+ UseSys(sys2); /* active system sys2 was created in application and has only MATRIX A */
+
+ if (_rerror > 0) {
+ G_fatal_error("Can't open information system <%s>\n", _mainsys->name);
+ return (1);
+ }
+
G_message("Build information system for classification ");
- for(i=0;i<nattributes;i++)
- {
- object=0; /* set object numbers =0 and increase it until rows*cells for each attribute */
- for (row = 0; row < nrows; row++)
- {
- G_percent(row, nrows, 1);
- /* Reads appropriate information into the buffer buf associated with the requested row*/
- G_get_c_raster_row (attributes[i].fd, attributes[i].buf, row);
- for (col=0;col<ncols;col++)
- {
- value = (attributes[i].buf[col]); /*make a cast on the DCELL output value*/
- PutA(_mainsys,object,i,value); /* filling MATRIX A */
- object++;
- }
- }
- }
-
- buf = MatExist(_mainsys,MATA); /*Returns pointer to specified matrix if exists*/
+ for (i = 0; i < nattributes; i++) {
+ object = 0; /* set object numbers =0 and increase it until rows*cells for each attribute */
+ for (row = 0; row < nrows; row++) {
+ G_percent(row, nrows, 1);
+ /* Reads appropriate information into the buffer buf associated with the requested row */
+ G_get_c_raster_row(attributes[i].fd, attributes[i].buf, row);
+ for (col = 0; col < ncols; col++) {
+ value = (attributes[i].buf[col]); /*make a cast on the DCELL output value */
+ PutA(_mainsys, object, i, value); /* filling MATRIX A */
+ object++;
+ }
+ }
+ }
- if (!buf)
- { G_fatal_error("Error in the information system <%s>\n",_mainsys->name);
- return(1); }
-
-
- switch ( cls )
- {
- case 0:
+ buf = MatExist(_mainsys, MATA); /*Returns pointer to specified matrix if exists */
+
+ if (!buf) {
+ G_fatal_error("Error in the information system <%s>\n",
+ _mainsys->name);
+ return (1);
+ }
+
+
+ switch (cls) {
+ case 0:
{
- for (j=0;j<_mainsys->objects_num;j++)
- { /*Chooses the best rule to cover sample. Strategy no. 1*/
- classify_vect[j]=Classify1(buf+j*_mainsys->attributes_num,rules,r,P,Q);
- G_percent(j, _mainsys->objects_num, 1);
- }
+ for (j = 0; j < _mainsys->objects_num; j++) { /*Chooses the best rule to cover sample. Strategy no. 1 */
+ classify_vect[j] =
+ Classify1(buf + j * _mainsys->attributes_num, rules, r, P,
+ Q);
+ G_percent(j, _mainsys->objects_num, 1);
+ }
}
- break;
- case 1:
+ break;
+ case 1:
{
- for (j=0;j<_mainsys->objects_num;j++)
- { /*Chooses the best rule to cover sample. Strategy no. 2*/
- classify_vect[j]=Classify2(buf+j*_mainsys->attributes_num,rules,r,P,Q);
- G_percent(j, _mainsys->objects_num, 1);
- }
+ for (j = 0; j < _mainsys->objects_num; j++) { /*Chooses the best rule to cover sample. Strategy no. 2 */
+ classify_vect[j] =
+ Classify2(buf + j * _mainsys->attributes_num, rules, r, P,
+ Q);
+ G_percent(j, _mainsys->objects_num, 1);
+ }
}
- break;
- case 2:
- {
- for (j=0;j<_mainsys->objects_num;j++)
- { /*Chooses the best rule to cover sample. Strategy no. 3*/
- classify_vect[j]=Classify3(buf+j*_mainsys->attributes_num,rules,r,opr,P,Q);
- G_percent(j, _mainsys->objects_num, 1);
- }
- }
- break;
-
- default: 0;
- break;
- }
+ break;
+ case 2:
+ {
+ for (j = 0; j < _mainsys->objects_num; j++) { /*Chooses the best rule to cover sample. Strategy no. 3 */
+ classify_vect[j] =
+ Classify3(buf + j * _mainsys->attributes_num, rules, r,
+ opr, P, Q);
+ G_percent(j, _mainsys->objects_num, 1);
+ }
+ }
+ break;
-
- G_message("All cells classified (%d)",j);
-
+ default:
+ 0;
+ break;
+ }
+
+
+ G_message("All cells classified (%d)", j);
+
/*****************************************************************************/
- free( rules );
- free( opr );
- CloseSetA(P);
- CloseSetA(Q);
- CloseSetA(full);
- CloseSys(sys2);
- //fclose(file);
- fclose(file_out_txt);
- return (0);
+ free(rules);
+ free(opr);
+ CloseSetA(P);
+ CloseSetA(Q);
+ CloseSetA(full);
+ CloseSys(sys2);
+ //fclose(file);
+ fclose(file_out_txt);
+ return (0);
}
-void rough_set_library_out(int nrows, int ncols, int nattribute, struct input *attributes, char *file_out_sys)
-
+void rough_set_library_out(int nrows, int ncols, int nattribute,
+ struct input *attributes, char *file_out_sys)
{
- int row, col, i, j;
- int value, decvalue;
- int nobject;
- char cell_buf[300];
- FILE *fp; /*file pointer for ASCII output*/
+ int row, col, i, j;
+ int value, decvalue;
+ int nobject;
+ char cell_buf[300];
+ FILE *fp; /*file pointer for ASCII output */
- /* open *.sys file for writing or use stdout */
- if(NULL == (fp = fopen(file_out_sys, "w")))
- G_fatal_error("Not able to open file [%s]",file_out_sys);
+ /* open *.sys file for writing or use stdout */
+ if (NULL == (fp = fopen(file_out_sys, "w")))
+ G_fatal_error("Not able to open file [%s]", file_out_sys);
- fprintf(fp,"NAME: %s\nATTRIBUTES: %d\nOBJECTS: %s\n",file_out_sys,nattribute+1," ");
+ fprintf(fp, "NAME: %s\nATTRIBUTES: %d\nOBJECTS: %s\n", file_out_sys,
+ nattribute + 1, " ");
/************** process the data *************/
-
- G_message("Build information system for rules extraction in %s", file_out_sys);
-
- nobject=0;
-
- for (row = 0; row < nrows; row++)
- {
- for(i=0;i<=nattribute;i++)
- {
- G_get_c_raster_row (attributes[i].fd, attributes[i].buf, row);/* Reads appropriate information into the buffer buf associated with the requested row*/
- }
- for (col=0;col<ncols;col++)
- { /*make a cast on the DCELL output value*/
- decvalue=(int)attributes[nattribute].buf[col];
- if(0<decvalue) /* TODO: correct form will: decval!=null */
- {
- for(j=0;j<nattribute;j++)
- { /*make a cast on the DCELL output value*/
- value = (int)(attributes[j].buf[col]);
- sprintf(cell_buf, "%d",value);
- G_trim_decimal (cell_buf);
- fprintf (fp,"%s ",cell_buf);
- }
- fprintf(fp,"%d\n",decvalue);
- nobject++;
- }
- }
- G_percent(row, nrows, 1);
+
+ G_message("Build information system for rules extraction in %s",
+ file_out_sys);
+
+ nobject = 0;
+
+ for (row = 0; row < nrows; row++) {
+ for (i = 0; i <= nattribute; i++) {
+ G_get_c_raster_row(attributes[i].fd, attributes[i].buf, row); /* Reads appropriate information into the buffer buf associated with the requested row */
+ }
+ for (col = 0; col < ncols; col++) { /*make a cast on the DCELL output value */
+ decvalue = (int)attributes[nattribute].buf[col];
+ if (0 < decvalue) { /* TODO: correct form will: decval!=null */
+ for (j = 0; j < nattribute; j++) { /*make a cast on the DCELL output value */
+ value = (int)(attributes[j].buf[col]);
+ sprintf(cell_buf, "%d", value);
+ G_trim_decimal(cell_buf);
+ fprintf(fp, "%s ", cell_buf);
}
-
- /************** write code file*************/
-
- for(i=0;i<=nattribute;i++)
- {
- fprintf(fp,"\n%s",attributes[i].name);
+ fprintf(fp, "%d\n", decvalue);
+ nobject++;
+ }
}
+ G_percent(row, nrows, 1);
+ }
+ /************** write code file*************/
+
+ for (i = 0; i <= nattribute; i++) {
+ fprintf(fp, "\n%s", attributes[i].name);
+ }
+
/************** write header file*************/
- rewind(fp); /*move file pointer to header file*/
- /* TODO: make a system to detect errors like: G_fatal_error("Not able to write file [%s]",file_out_sys);*/
+ rewind(fp); /*move file pointer to header file */
+ /* TODO: make a system to detect errors like: G_fatal_error("Not able to write file [%s]",file_out_sys); */
- fprintf(fp,"NAME: %s\nATTRIBUTES: %d\nOBJECTS: %d",file_out_sys,nattribute+1,nobject);
+ fprintf(fp, "NAME: %s\nATTRIBUTES: %d\nOBJECTS: %d", file_out_sys,
+ nattribute + 1, nobject);
+
/************** close all and exit ***********/
- fclose(fp);
+ fclose(fp);
}
-void output_to_txt( FILE *file_out_txt, value_type* rules, setA P,setA Q, setA core, setA beg, int n, SYSTEM * sys1, int strgy, int r, int *opr, struct input *attributes)
-{
- int i;
- fprintf(file_out_txt,"Condition attributes are\n");
- fPrintSetA(file_out_txt,P);
- fprintf(file_out_txt,"\nDecision attributes are\n");
- fPrintSetA(file_out_txt,Q);
- fprintf(file_out_txt,"\nDependCoef = %f\n",DependCoef(P,Q,MATD)); /* Returns degree of dependency Q from P in the active information system.*/
- fprintf(file_out_txt,"CORE = ");
- fPrintSetA(file_out_txt,core);
- fprintf(file_out_txt,"\nRedOptim = ");
- fPrintSetA(file_out_txt,core);
- fprintf( file_out_txt,"\nFew reducts ( %i ):\n", n );
-
- for (i=0;i<n;i++)
- {
- fPrintSetA( file_out_txt, beg+i*sys1->setAsize );
- fprintf(file_out_txt,"\n");
- }
-
- fprintf(file_out_txt, "%d strategy of generating rules\n", strgy);
-
- if (r>0)
- { fprintf(file_out_txt,"Rules ( %i )\n", r );
- fPrintRules( file_out_txt, rules, r, opr, P, Q, attributes ); /*print to file generated rules*/
- fprintf(file_out_txt,"Mean number of attributes in rule = %.1f\n",MeanAttrInRule( rules, r, P ));
- }
+void output_to_txt(FILE * file_out_txt, value_type * rules, setA P, setA Q,
+ setA core, setA beg, int n, SYSTEM * sys1, int strgy,
+ int r, int *opr, struct input *attributes)
+{
+ int i;
+
+ fprintf(file_out_txt, "Condition attributes are\n");
+ fPrintSetA(file_out_txt, P);
+ fprintf(file_out_txt, "\nDecision attributes are\n");
+ fPrintSetA(file_out_txt, Q);
+ fprintf(file_out_txt, "\nDependCoef = %f\n", DependCoef(P, Q, MATD)); /* Returns degree of dependency Q from P in the active information system. */
+ fprintf(file_out_txt, "CORE = ");
+ fPrintSetA(file_out_txt, core);
+ fprintf(file_out_txt, "\nRedOptim = ");
+ fPrintSetA(file_out_txt, core);
+ fprintf(file_out_txt, "\nFew reducts ( %i ):\n", n);
+
+ for (i = 0; i < n; i++) {
+ fPrintSetA(file_out_txt, beg + i * sys1->setAsize);
+ fprintf(file_out_txt, "\n");
+ }
+
+ fprintf(file_out_txt, "%d strategy of generating rules\n", strgy);
+
+ if (r > 0) {
+ fprintf(file_out_txt, "Rules ( %i )\n", r);
+ fPrintRules(file_out_txt, rules, r, opr, P, Q, attributes); /*print to file generated rules */
+ fprintf(file_out_txt, "Mean number of attributes in rule = %.1f\n",
+ MeanAttrInRule(rules, r, P));
+ }
}
-void fPrintSetA( FILE *f, setA set )
-{ int attr;
- fprintf(f,"{");
- for (attr=0; attr<_mainsys->attributes_num ;attr++)
- if (ContSetA(set,attr))
- { fprintf(f," %d",attr);
- attr++;
- break;
- }
- for (; attr<_mainsys->attributes_num ;attr++)
- if (ContSetA(set,attr)) fprintf(f,",%d",attr);
- fprintf(f," }");
+void fPrintSetA(FILE * f, setA set)
+{
+ int attr;
+
+ fprintf(f, "{");
+ for (attr = 0; attr < _mainsys->attributes_num; attr++)
+ if (ContSetA(set, attr)) {
+ fprintf(f, " %d", attr);
+ attr++;
+ break;
+ }
+ for (; attr < _mainsys->attributes_num; attr++)
+ if (ContSetA(set, attr))
+ fprintf(f, ",%d", attr);
+ fprintf(f, " }");
}
-void fPrintSetO( FILE *f, setO set )
-{ int obj;
- fprintf(f,"{");
- for (obj=0; obj<_mainsys->objects_num ;obj++)
- if (ContSetO(set,obj))
- { fprintf(f," %d",obj);
- obj++;
- break;
- }
- for (; obj<_mainsys->objects_num ;obj++)
- if (ContSetO(set,obj)) fprintf(f,",%d",obj);
- fprintf(f," }");
+void fPrintSetO(FILE * f, setO set)
+{
+ int obj;
+
+ fprintf(f, "{");
+ for (obj = 0; obj < _mainsys->objects_num; obj++)
+ if (ContSetO(set, obj)) {
+ fprintf(f, " %d", obj);
+ obj++;
+ break;
+ }
+ for (; obj < _mainsys->objects_num; obj++)
+ if (ContSetO(set, obj))
+ fprintf(f, ",%d", obj);
+ fprintf(f, " }");
}
-void fPrintRules( FILE *file, value_type* rules,
- int N, int *opr, setA P, setA Q, struct input *attributes )
-{ int n,j;
-
- for (n=0;n<N;n++)
- { for (j=0;j<_mainsys->attributes_num;j++)
- if ( ContSetA( P,j ) )
- if (rules[n*_mainsys->attributes_num+j]!=MINUS)
- fprintf(file,"%s=%d ", attributes[j].name,rules[n*_mainsys->attributes_num+j]);
- fprintf(file," => ");
- for (j=0;j<_mainsys->attributes_num;j++)
- if ( ContSetA( Q, j ) )
- if ((rules+n*_mainsys->attributes_num)[j]!=MINUS)
- fprintf(file,"%s=%d ", attributes[j].name,(rules+n*_mainsys->attributes_num)[j]);
- fprintf(file," ( %i objects )\n", opr[n] );
- }
- return;
+void fPrintRules(FILE * file, value_type * rules,
+ int N, int *opr, setA P, setA Q, struct input *attributes)
+{
+ int n, j;
+
+ for (n = 0; n < N; n++) {
+ for (j = 0; j < _mainsys->attributes_num; j++)
+ if (ContSetA(P, j))
+ if (rules[n * _mainsys->attributes_num + j] != MINUS)
+ fprintf(file, "%s=%d ", attributes[j].name,
+ rules[n * _mainsys->attributes_num + j]);
+ fprintf(file, " => ");
+ for (j = 0; j < _mainsys->attributes_num; j++)
+ if (ContSetA(Q, j))
+ if ((rules + n * _mainsys->attributes_num)[j] != MINUS)
+ fprintf(file, "%s=%d ", attributes[j].name,
+ (rules + n * _mainsys->attributes_num)[j]);
+ fprintf(file, " ( %i objects )\n", opr[n]);
+ }
+ return;
}
-
-float MeanAttrInRule( value_type *rules, int N, setA P )
-{ int counter=0;
- int i,j;
- int size=_mainsys->attributes_num;
- for (i=0; i<N; i++)
- for (j=0; j<size; j++)
- if ( ContSetA( P, j ) )
- if ( (rules+i*size)[j]!=MINUS ) counter++;
- return (float)counter/N;
+
+float MeanAttrInRule(value_type * rules, int N, setA P)
+{
+ int counter = 0;
+ int i, j;
+ int size = _mainsys->attributes_num;
+
+ for (i = 0; i < N; i++)
+ for (j = 0; j < size; j++)
+ if (ContSetA(P, j))
+ if ((rules + i * size)[j] != MINUS)
+ counter++;
+ return (float)counter / N;
}
-int LowRules( value_type **rules, setA P, setA Q, int mat )
+int LowRules(value_type ** rules, setA P, setA Q, int mat)
{
- return ApprRules( rules, P, Q, LOWER, mat );
+ return ApprRules(rules, P, Q, LOWER, mat);
}
-int UppRules( value_type **rules, setA P, setA Q, int mat )
+int UppRules(value_type ** rules, setA P, setA Q, int mat)
{
- return ApprRules( rules, P, Q, UPPER, mat );
+ return ApprRules(rules, P, Q, UPPER, mat);
}
-int NormRules( value_type **rules, setA P, setA Q, int mat )
+int NormRules(value_type ** rules, setA P, setA Q, int mat)
{
- return ApprRules( rules, P, Q, NORMAL, mat );
+ return ApprRules(rules, P, Q, NORMAL, mat);
}
/* dom 07 dic 2008 07:04:58 CET */
-
-
More information about the grass-commit
mailing list