[GRASS-SVN] r54184 - in grass-addons: grass6/raster/r.in.drsa grass6/raster/r.mcda.ahp grass6/raster/r.mcda.electre grass6/raster/r.mcda.fuzzy grass6/raster/r.mcda.regime grass6/raster/r.mcda.roughset grass6/raster/r.roughset grass6/raster/r.to.drsa grass7/imagery/i.rotate
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Dec 4 10:08:18 PST 2012
Author: neteler
Date: 2012-12-04 10:08:17 -0800 (Tue, 04 Dec 2012)
New Revision: 54184
Modified:
grass-addons/grass6/raster/r.in.drsa/description.html
grass-addons/grass6/raster/r.in.drsa/r.in.drsa.py
grass-addons/grass6/raster/r.mcda.ahp/description.html
grass-addons/grass6/raster/r.mcda.ahp/r.mcda.ahp.py
grass-addons/grass6/raster/r.mcda.electre/description.html
grass-addons/grass6/raster/r.mcda.electre/dominance.c
grass-addons/grass6/raster/r.mcda.electre/local_proto.h
grass-addons/grass6/raster/r.mcda.electre/main.c
grass-addons/grass6/raster/r.mcda.fuzzy/description.html
grass-addons/grass6/raster/r.mcda.fuzzy/fuzzy.c
grass-addons/grass6/raster/r.mcda.fuzzy/local_proto.h
grass-addons/grass6/raster/r.mcda.fuzzy/main.c
grass-addons/grass6/raster/r.mcda.regime/description.html
grass-addons/grass6/raster/r.mcda.regime/local_proto.h
grass-addons/grass6/raster/r.mcda.regime/main.c
grass-addons/grass6/raster/r.mcda.regime/regime.c
grass-addons/grass6/raster/r.mcda.roughset/description.html
grass-addons/grass6/raster/r.mcda.roughset/r.mcda.roughset.py
grass-addons/grass6/raster/r.roughset/description.html
grass-addons/grass6/raster/r.roughset/localproto.h
grass-addons/grass6/raster/r.roughset/main.c
grass-addons/grass6/raster/r.roughset/raccess.c
grass-addons/grass6/raster/r.roughset/raccess.h
grass-addons/grass6/raster/r.roughset/rbasic.c
grass-addons/grass6/raster/r.roughset/rbasic.h
grass-addons/grass6/raster/r.roughset/rclass.c
grass-addons/grass6/raster/r.roughset/rclass.h
grass-addons/grass6/raster/r.roughset/rcore.c
grass-addons/grass6/raster/r.roughset/rcore.h
grass-addons/grass6/raster/r.roughset/reduct1.c
grass-addons/grass6/raster/r.roughset/reduct1.h
grass-addons/grass6/raster/r.roughset/reduct2.c
grass-addons/grass6/raster/r.roughset/reduct2.h
grass-addons/grass6/raster/r.roughset/rerror.h
grass-addons/grass6/raster/r.roughset/rough.h
grass-addons/grass6/raster/r.roughset/rset.c
grass-addons/grass6/raster/r.roughset/rset.h
grass-addons/grass6/raster/r.roughset/rsystem.c
grass-addons/grass6/raster/r.roughset/rsystem.h
grass-addons/grass6/raster/r.roughset/rule1.c
grass-addons/grass6/raster/r.roughset/rule1.h
grass-addons/grass6/raster/r.roughset/rule2.c
grass-addons/grass6/raster/r.roughset/rule2.h
grass-addons/grass6/raster/r.roughset/rules_extr.c
grass-addons/grass6/raster/r.to.drsa/description.html
grass-addons/grass6/raster/r.to.drsa/r.to.drsa.py
grass-addons/grass7/imagery/i.rotate/i.rotate.html
grass-addons/grass7/imagery/i.rotate/main.c
Log:
svn propset
Modified: grass-addons/grass6/raster/r.in.drsa/description.html
===================================================================
--- grass-addons/grass6/raster/r.in.drsa/description.html 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.in.drsa/description.html 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,33 +1,33 @@
-<h2>DESCRIPTION</h2>
-<p>The <em>r.in.drsa</em> module will read a *rls file output from
-jMAF, JAMM or 4eMka2 sofware <a href="http://idss.cs.put.poznan.pl/">
-Laboratory of Intelligent Decision Support Systems - Poznan University.</a>
-and returns maps of the rules </p>
-
-<em>(GRASS python Script)</em>
-
-<h2>NOTES</h2>
-
-
-<h2>TODO</h2>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.roughset.html">r.roughset</a>,
-<a href="r.mcda.regime.html">r.mcda.regime</a>,
-<a href="r.mcda.fuzzy.html">r.mcda.fuzzy</a>
-<a href="r.mcda.electre.html">r.mcda.electre</a>,
-<a href="r.mcda.ahp.html">r.mcda.ahp</a>
-<a href="r.mcda.roughset.html">r.mcda.roughset</a>
-<a href="r.in.drsa.html">r.in.drsa</a>
-<a href="r.to.drsa.html">r.to.drsa</a>
-</em>
-
-<h2>AUTHORS</h2>
-Antonio Boggia - Gianluca Massei<br>
-Department of Economics and Appraisal - University of Perugia - Italy
-<p>
-
-<i>Last changed: $Date: 2012-09-12 22:32:08 +0200 (mer, 12 set 2012) $</i>
+<h2>DESCRIPTION</h2>
+<p>The <em>r.in.drsa</em> module will read a *rls file output from
+jMAF, JAMM or 4eMka2 sofware <a href="http://idss.cs.put.poznan.pl/">
+Laboratory of Intelligent Decision Support Systems - Poznan University.</a>
+and returns maps of the rules </p>
+
+<em>(GRASS python Script)</em>
+
+<h2>NOTES</h2>
+
+
+<h2>TODO</h2>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.roughset.html">r.roughset</a>,
+<a href="r.mcda.regime.html">r.mcda.regime</a>,
+<a href="r.mcda.fuzzy.html">r.mcda.fuzzy</a>
+<a href="r.mcda.electre.html">r.mcda.electre</a>,
+<a href="r.mcda.ahp.html">r.mcda.ahp</a>
+<a href="r.mcda.roughset.html">r.mcda.roughset</a>
+<a href="r.in.drsa.html">r.in.drsa</a>
+<a href="r.to.drsa.html">r.to.drsa</a>
+</em>
+
+<h2>AUTHORS</h2>
+Antonio Boggia - Gianluca Massei<br>
+Department of Economics and Appraisal - University of Perugia - Italy
+<p>
+
+<i>Last changed: $Date$</i>
Property changes on: grass-addons/grass6/raster/r.in.drsa/description.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Property changes on: grass-addons/grass6/raster/r.in.drsa/r.in.drsa.py
___________________________________________________________________
Added: svn:mime-type
+ text/x-python
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.ahp/description.html
===================================================================
--- grass-addons/grass6/raster/r.mcda.ahp/description.html 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.ahp/description.html 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,33 +1,33 @@
-<h2>DESCRIPTION</h2>
-<p>The <em>r.mcda.ahp</em> Generate a raster map classified with analytic hierarchy process (AHP) [Saaty, 1977 and Saaty & Vargas, 1991]</p>
-<em>(GRASS python Script)</em>
-<p></p>
-<h2>NOTES</h2>
-<p>It is mandatory to build a pairwise comparation table with the same order of input of criteria maps in the criteria field.</p>
-<p>Example: r.mcda.ahp criteria=reclass_slope,reclass_sand,reclass_elev pairwise=pairwise output=outputMap</p>
-<p>The file "pairwise" has to have a structure like this:</p>
-<p>#start file</p>
-<p>1.0, 0.2, 3.0</p>
-<p>5.0, 1.0, 5.0</p>
-<p>0.3, 0.2, 1.0</p>
-<p>#comment: order: reclass_slope,reclass_sand,reclass_</p>
-<p>#end file</p>
-The first row and first column are related to the first criteria (reclass_slope in our case); the second row and second column are related to the second criteria (reclass_sand in our case) and the third row and third column are related to the third criteria
- ( reclass_elev in our cas), and so on.
-<p>In the work directory should be generated a log.txt file were you can find additional information like: eigenvectors, eigenvalues, weights</p>
-<h2>TODO</h2>
-<h2>SEE ALSO</h2>
-<em>
-<a href="r.roughset.html">r.roughset</a>,
-<a href="r.mcda.regime.html">r.mcda.regime</a>,
-<a href="r.mcda.fuzzy.html">r.mcda.fuzzy</a>
-<a href="r.mcda.electre.html">r.mcda.electre</a>,
-<a href="r.mcda.roughset.html">r.mcda.roughset</a>
-<a href="r.in.drsa.html">r.in.drsa</a>
-<a href="r.to.drsa.html">r.to.drsa</a>
-</em>
-<h2>AUTHORS</h2>
-Antonio Boggia - Gianluca Massei<br>
-Department of Economics and Appraisal - University of Perugia - Italy
-<p><i>Last changed: $Date: 2012-09-12 22:32:08 +0200 (mer, 12 set 2012) $</i>
-
+<h2>DESCRIPTION</h2>
+<p>The <em>r.mcda.ahp</em> Generate a raster map classified with analytic hierarchy process (AHP) [Saaty, 1977 and Saaty & Vargas, 1991]</p>
+<em>(GRASS python Script)</em>
+<p></p>
+<h2>NOTES</h2>
+<p>It is mandatory to build a pairwise comparation table with the same order of input of criteria maps in the criteria field.</p>
+<p>Example: r.mcda.ahp criteria=reclass_slope,reclass_sand,reclass_elev pairwise=pairwise output=outputMap</p>
+<p>The file "pairwise" has to have a structure like this:</p>
+<p>#start file</p>
+<p>1.0, 0.2, 3.0</p>
+<p>5.0, 1.0, 5.0</p>
+<p>0.3, 0.2, 1.0</p>
+<p>#comment: order: reclass_slope,reclass_sand,reclass_</p>
+<p>#end file</p>
+The first row and first column are related to the first criteria (reclass_slope in our case); the second row and second column are related to the second criteria (reclass_sand in our case) and the third row and third column are related to the third criteria
+ ( reclass_elev in our cas), and so on.
+<p>In the work directory should be generated a log.txt file were you can find additional information like: eigenvectors, eigenvalues, weights</p>
+<h2>TODO</h2>
+<h2>SEE ALSO</h2>
+<em>
+<a href="r.roughset.html">r.roughset</a>,
+<a href="r.mcda.regime.html">r.mcda.regime</a>,
+<a href="r.mcda.fuzzy.html">r.mcda.fuzzy</a>
+<a href="r.mcda.electre.html">r.mcda.electre</a>,
+<a href="r.mcda.roughset.html">r.mcda.roughset</a>
+<a href="r.in.drsa.html">r.in.drsa</a>
+<a href="r.to.drsa.html">r.to.drsa</a>
+</em>
+<h2>AUTHORS</h2>
+Antonio Boggia - Gianluca Massei<br>
+Department of Economics and Appraisal - University of Perugia - Italy
+<p><i>Last changed: $Date$</i>
+
Property changes on: grass-addons/grass6/raster/r.mcda.ahp/description.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Property changes on: grass-addons/grass6/raster/r.mcda.ahp/r.mcda.ahp.py
___________________________________________________________________
Added: svn:mime-type
+ text/x-python
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.electre/description.html
===================================================================
--- grass-addons/grass6/raster/r.mcda.electre/description.html 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.electre/description.html 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,40 +1,40 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.mcda.electre</em> is the implementation of the ELECTRE multicriteria
-algorithm in GRASS GIS environment. It is one of the available tools in the
-r.mcda suite. It requires as an input the list of raster representing the
-criteria to be assessed in the multicriteria evaluation and the vector of
-weights to be assigned. Every single cell of the GRASS region is considered
-as one of the possible alternatives to evaluate and it is described with
-the value assumed for the same cell by the raster used as criteria. There
-are two output files. One represents the spatial distribution of the
-concordance index, the other one of the discordance index. The optimal
-solution is the one presenting the maximum concordance value and the minimum
-discordance value at the same time.
-
-
-<h2>NOTES</h2>
-The module does not standardize the raster-criteria. Therefore, they must
-be prepared before by using, for example, r.mapcalc. The weights vector
-is always normalized so that the sum of the weights is 1.
-
-
-<h2>REFERENCE</h2>
-<p>Roy, B. (1971) Problem and methods with multiple objective functions
- Mathematical programming 1, 239-266.</P>
-<p>Roy, B. (1990): The outranking approach and the foundations of Electre
- methods , Document du LAMSADE, Paris.</P>
-<p>Janssen R. (1994) - Multiobjective decision support for environmental
- management, Kluwer Academic Publishers.</P>
-<p>GRASS Development Team (2008)</P>
-
-<h2>SEE ALSO</h2>
-<em>r.mcda.fuzzy, r.mcda.electre, r.roughet, r.mapcalc</em>
-
-<h2>AUTHORS</h2>
-Antonio Boggia - Gianluca Massei<br>
-Department of Economics and Appraisal - University of Perugia - Italy
-
-
-<p>
-<i>Last changed: $Date: 2011-11-08 22:56:45 +0100 (mar, 08 nov 2011) $</i>
+<h2>DESCRIPTION</h2>
+
+<em>r.mcda.electre</em> is the implementation of the ELECTRE multicriteria
+algorithm in GRASS GIS environment. It is one of the available tools in the
+r.mcda suite. It requires as an input the list of raster representing the
+criteria to be assessed in the multicriteria evaluation and the vector of
+weights to be assigned. Every single cell of the GRASS region is considered
+as one of the possible alternatives to evaluate and it is described with
+the value assumed for the same cell by the raster used as criteria. There
+are two output files. One represents the spatial distribution of the
+concordance index, the other one of the discordance index. The optimal
+solution is the one presenting the maximum concordance value and the minimum
+discordance value at the same time.
+
+
+<h2>NOTES</h2>
+The module does not standardize the raster-criteria. Therefore, they must
+be prepared before by using, for example, r.mapcalc. The weights vector
+is always normalized so that the sum of the weights is 1.
+
+
+<h2>REFERENCE</h2>
+<p>Roy, B. (1971) Problem and methods with multiple objective functions
+ Mathematical programming 1, 239-266.</P>
+<p>Roy, B. (1990): The outranking approach and the foundations of Electre
+ methods , Document du LAMSADE, Paris.</P>
+<p>Janssen R. (1994) - Multiobjective decision support for environmental
+ management, Kluwer Academic Publishers.</P>
+<p>GRASS Development Team (2008)</P>
+
+<h2>SEE ALSO</h2>
+<em>r.mcda.fuzzy, r.mcda.electre, r.roughet, r.mapcalc</em>
+
+<h2>AUTHORS</h2>
+Antonio Boggia - Gianluca Massei<br>
+Department of Economics and Appraisal - University of Perugia - Italy
+
+
+<p>
+<i>Last changed: $Date$</i>
Property changes on: grass-addons/grass6/raster/r.mcda.electre/description.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.electre/dominance.c
===================================================================
--- grass-addons/grass6/raster/r.mcda.electre/dominance.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.electre/dominance.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,116 +1,116 @@
-#include "local_proto.h"
-
-/*
- * global function declaration
- */
-
-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);
-
-
-/*
- * function definitions
- */
-
-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 */
-
- }
-
-}
-
-
-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;
- double *col_sum_conc;
- double *row_sum_disc;
- double *col_sum_disc;
-
- row_sum_conc=G_malloc(ncriteria * nrows * ncols * sizeof(double*));
- col_sum_conc=G_malloc(ncriteria * nrows * ncols * sizeof(double*));
- row_sum_disc=G_malloc(ncriteria * nrows * ncols * sizeof(double*));
- col_sum_disc=G_malloc(ncriteria * nrows * ncols * sizeof(double*));
-
- 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;
- 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++;
- }
- }
-}
+#include "local_proto.h"
+
+/*
+ * global function declaration
+ */
+
+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);
+
+
+/*
+ * function definitions
+ */
+
+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 */
+
+ }
+
+}
+
+
+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;
+ double *col_sum_conc;
+ double *row_sum_disc;
+ double *col_sum_disc;
+
+ row_sum_conc=G_malloc(ncriteria * nrows * ncols * sizeof(double*));
+ col_sum_conc=G_malloc(ncriteria * nrows * ncols * sizeof(double*));
+ row_sum_disc=G_malloc(ncriteria * nrows * ncols * sizeof(double*));
+ col_sum_disc=G_malloc(ncriteria * nrows * ncols * sizeof(double*));
+
+ 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;
+ 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++;
+ }
+ }
+}
Property changes on: grass-addons/grass6/raster/r.mcda.electre/dominance.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.electre/local_proto.h
===================================================================
--- grass-addons/grass6/raster/r.mcda.electre/local_proto.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.electre/local_proto.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,15 +1,15 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include <grass/config.h>
-
-
-struct input
-{
- char *name, *mapset; /* input raster name and mapset name */
- int infd;
- void *inrast; /* input buffer */
-};
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include <grass/config.h>
+
+
+struct input
+{
+ char *name, *mapset; /* input raster name and mapset name */
+ int infd;
+ void *inrast; /* input buffer */
+};
Property changes on: grass-addons/grass6/raster/r.mcda.electre/local_proto.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.electre/main.c
===================================================================
--- grass-addons/grass6/raster/r.mcda.electre/main.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.electre/main.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,232 +1,232 @@
-/****************************************************************************
- *
- * MODULE: r.mcda.electre
- * AUTHORS: Gianluca Massei (g_massa at libero.it) - Antonio Boggia (boggia at unipg.it)
- *
- * PURPOSE: Make a multicriterio decision analysis based on ELECTRE algorthm
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-
-
-#include "local_proto.h"
-
-
-/*
- * main function
- */
-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 *mapset; /* mapset name */
- unsigned char *outrast_concordance, *outrast_discordance; /* output buffer */
- char *message;
- 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 */
-
-
- struct History history; /* holds meta-data (title, comments,..) */
-
- struct GModule *module; /* GRASS module for parsing arguments */
-
- struct Option *criteria, *weight, *discordance, *concordance; /* options */
-
- struct input *attributes; /*storage alla input criteria GRID files and output concordance and discordance GRID files*/
-
-
- /* initialize GIS environment */
- G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */
-
- /* initialize module */
- module = G_define_module();
- module->keywords = _("raster,MCDA");
- 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";
-
- 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->type = TYPE_STRING;
- concordance->required = YES;
- concordance->gisprompt = "new,cell,raster";
- 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->type = TYPE_STRING;
- discordance->required = YES;
- discordance->gisprompt = "new,cell,raster";
- discordance->answer ="discordance";
- discordance->description = "discordance output map";
-
- /* options and flags parser */
- if (G_parser(argc, argv))
- exit(EXIT_FAILURE);
-
-
- G_message("Start: %s",G_date()); /*write calculation start time*/
-
- /* number of file (=criteria) */
- while (criteria->answers[ncriteria]!=NULL)
- {
- ncriteria++;
- }
-
- /* 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*/
-
-
-
- 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);
-
- 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);
-
- 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);
-
- 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);
-
- /*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+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);
-
- /* 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_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_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);
- }
-
-
- G_message("End: %s",G_date());
-
- /* memory cleanup */
- for (i = 0; i<ncriteria; i++)
- G_free(attributes[i].inrast);
-
- G_free(outrast_concordance);
- G_free(outrast_discordance);
- G_free(decision_vol);
-
-
-
- /* closing raster maps */
- for (i = 0; i<ncriteria; i++)
- G_close_cell(attributes[i].infd);
-
- G_close_cell(outfd_concordance);
- G_close_cell(outfd_discordance);
-
- /* add command line incantation to history concordance file */
- G_short_history(result_concordance, "raster", &history);
- G_command_history(&history);
- G_write_history(result_concordance, &history);
-
- /* add command line incantation to history discordance file */
- G_short_history(result_discordance, "raster", &history);
- G_command_history(&history);
- G_write_history(result_discordance, &history);
-
- exit(EXIT_SUCCESS);
-}
-
+/****************************************************************************
+ *
+ * MODULE: r.mcda.electre
+ * AUTHORS: Gianluca Massei (g_massa at libero.it) - Antonio Boggia (boggia at unipg.it)
+ *
+ * PURPOSE: Make a multicriterio decision analysis based on ELECTRE algorthm
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+
+
+#include "local_proto.h"
+
+
+/*
+ * main function
+ */
+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 *mapset; /* mapset name */
+ unsigned char *outrast_concordance, *outrast_discordance; /* output buffer */
+ char *message;
+ 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 */
+
+
+ struct History history; /* holds meta-data (title, comments,..) */
+
+ struct GModule *module; /* GRASS module for parsing arguments */
+
+ struct Option *criteria, *weight, *discordance, *concordance; /* options */
+
+ struct input *attributes; /*storage alla input criteria GRID files and output concordance and discordance GRID files*/
+
+
+ /* initialize GIS environment */
+ G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */
+
+ /* initialize module */
+ module = G_define_module();
+ module->keywords = _("raster,MCDA");
+ 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";
+
+ 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->type = TYPE_STRING;
+ concordance->required = YES;
+ concordance->gisprompt = "new,cell,raster";
+ 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->type = TYPE_STRING;
+ discordance->required = YES;
+ discordance->gisprompt = "new,cell,raster";
+ discordance->answer ="discordance";
+ discordance->description = "discordance output map";
+
+ /* options and flags parser */
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+
+ G_message("Start: %s",G_date()); /*write calculation start time*/
+
+ /* number of file (=criteria) */
+ while (criteria->answers[ncriteria]!=NULL)
+ {
+ ncriteria++;
+ }
+
+ /* 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*/
+
+
+
+ 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);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ /*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+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);
+
+ /* 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_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_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);
+ }
+
+
+ G_message("End: %s",G_date());
+
+ /* memory cleanup */
+ for (i = 0; i<ncriteria; i++)
+ G_free(attributes[i].inrast);
+
+ G_free(outrast_concordance);
+ G_free(outrast_discordance);
+ G_free(decision_vol);
+
+
+
+ /* closing raster maps */
+ for (i = 0; i<ncriteria; i++)
+ G_close_cell(attributes[i].infd);
+
+ G_close_cell(outfd_concordance);
+ G_close_cell(outfd_discordance);
+
+ /* add command line incantation to history concordance file */
+ G_short_history(result_concordance, "raster", &history);
+ G_command_history(&history);
+ G_write_history(result_concordance, &history);
+
+ /* add command line incantation to history discordance file */
+ G_short_history(result_discordance, "raster", &history);
+ G_command_history(&history);
+ G_write_history(result_discordance, &history);
+
+ exit(EXIT_SUCCESS);
+}
+
Property changes on: grass-addons/grass6/raster/r.mcda.electre/main.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.fuzzy/description.html
===================================================================
--- grass-addons/grass6/raster/r.mcda.fuzzy/description.html 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.fuzzy/description.html 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,36 +1,36 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.mcda.fuzzy</em> is the implementation of the FUZZY multicriteria
-algorithm proposed by Yager R., in GRASS GIS environment. It is one of the
-available tools in the r.mcda suite. It requires as an input the list of
-raster representing the criteria to be assessed in the multicriteria
-evaluation and the vector of linguistic modifiers to be assigned. Every
-single cell of the GRASS region is considered as one of the possible
-alternatives to evaluate and it is described with the value assumed for
-the same cell by the raster used as criteria. It is possible to get three
-different output files as the result of the intersection operator, the
-union operator and the ordered weighted averaging (OWA) operator.
-
-
-<h2>NOTES</h2>
-The module does not standardize the raster-criteria. Therefore, they must
-be prepared before by using, for example, r.mapcalc. The linguistic
-modifiers vector is always normalized so that the sum of the weights is 1.
-
-
-<h2>REFERENCE</h2>
-<p>Yager R. (1977) - Multiple objective decision making using fuzzy set,
- International Journal of Man-Machine Studies, 12, 299-322;</P>
-<p>GRASS Development Team (2008)</P>
-
-
-<h2>SEE ALSO</h2>
-<em>r.mcda.regime, r.mcda.electre, r.roughet, r.mapcalc</em>
-
-
-<h2>AUTHORS</h2>
-Antonio Boggia - Gianluca Massei<br>
-Department of Economics and Appraisal - University of Perugia - Italy
-
-<p>
-<i>Last changed: $Date: 2011-11-08 22:56:45 +0100 (mar, 08 nov 2011) $</i>
+<h2>DESCRIPTION</h2>
+
+<em>r.mcda.fuzzy</em> is the implementation of the FUZZY multicriteria
+algorithm proposed by Yager R., in GRASS GIS environment. It is one of the
+available tools in the r.mcda suite. It requires as an input the list of
+raster representing the criteria to be assessed in the multicriteria
+evaluation and the vector of linguistic modifiers to be assigned. Every
+single cell of the GRASS region is considered as one of the possible
+alternatives to evaluate and it is described with the value assumed for
+the same cell by the raster used as criteria. It is possible to get three
+different output files as the result of the intersection operator, the
+union operator and the ordered weighted averaging (OWA) operator.
+
+
+<h2>NOTES</h2>
+The module does not standardize the raster-criteria. Therefore, they must
+be prepared before by using, for example, r.mapcalc. The linguistic
+modifiers vector is always normalized so that the sum of the weights is 1.
+
+
+<h2>REFERENCE</h2>
+<p>Yager R. (1977) - Multiple objective decision making using fuzzy set,
+ International Journal of Man-Machine Studies, 12, 299-322;</P>
+<p>GRASS Development Team (2008)</P>
+
+
+<h2>SEE ALSO</h2>
+<em>r.mcda.regime, r.mcda.electre, r.roughet, r.mapcalc</em>
+
+
+<h2>AUTHORS</h2>
+Antonio Boggia - Gianluca Massei<br>
+Department of Economics and Appraisal - University of Perugia - Italy
+
+<p>
+<i>Last changed: $Date$</i>
Property changes on: grass-addons/grass6/raster/r.mcda.fuzzy/description.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.fuzzy/fuzzy.c
===================================================================
--- grass-addons/grass6/raster/r.mcda.fuzzy/fuzzy.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.fuzzy/fuzzy.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,131 +1,131 @@
-#include "local_proto.h"
-
-/*
- * global function declaration
- */
-
-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);
-
-
-/*
- * function definitions
- */
-
-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 */
-
- }
-
-}
-
-
-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]);
- }
- }
- }
-
- /* 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;
- }
- }
-
- /* 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;
- }
- }
-
-}
+#include "local_proto.h"
+
+/*
+ * global function declaration
+ */
+
+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);
+
+
+/*
+ * function definitions
+ */
+
+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 */
+
+ }
+
+}
+
+
+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]);
+ }
+ }
+ }
+
+ /* 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;
+ }
+ }
+
+ /* 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;
+ }
+ }
+
+}
Property changes on: grass-addons/grass6/raster/r.mcda.fuzzy/fuzzy.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.fuzzy/local_proto.h
===================================================================
--- grass-addons/grass6/raster/r.mcda.fuzzy/local_proto.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.fuzzy/local_proto.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,15 +1,15 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include <grass/config.h>
-
-
-struct input
-{
- char *name, *mapset; /* input raster name and mapset name */
- int infd;
- void *inrast; /* input buffer */
-};
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include <grass/config.h>
+
+
+struct input
+{
+ char *name, *mapset; /* input raster name and mapset name */
+ int infd;
+ void *inrast; /* input buffer */
+};
Property changes on: grass-addons/grass6/raster/r.mcda.fuzzy/local_proto.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.fuzzy/main.c
===================================================================
--- grass-addons/grass6/raster/r.mcda.fuzzy/main.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.fuzzy/main.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,263 +1,263 @@
-
-/****************************************************************************
- *
- * MODULE: r.mcda.electre
- * AUTHORS: Gianluca Massei (g_massa at libero.it) - Antonio Boggia (boggia at unipg.it)
- *
- * PURPOSE: Make a multicriterio decision analysis based on Yager fuzzy algorthm
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-
-
-#include "local_proto.h"
-
-
-/*
- * main function
- */
-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 *mapset; /* mapset name */
- unsigned char *outrast_and, *outrast_or, *outrast_owa; /* output buffer */
- 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;
-
-
- struct History history; /* holds meta-data (title, comments,..) */
-
- struct GModule *module; /* GRASS module for parsing arguments */
-
- struct Option *criteria, *weight, *and, *or, *owa; /* options */
-
- struct input *attributes; /*storage alla input criteria GRID files and output concordance and discordance GRID files */
-
-
- /* initialize GIS environment */
- G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */
-
- /* initialize module */
- module = G_define_module();
- module->keywords = _("raster,fuzzy,MCDA");
- 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->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->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->type = TYPE_STRING;
- and->required = YES;
- and->gisprompt = "new,cell,raster";
- 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->type = TYPE_STRING;
- or->required = YES;
- or->gisprompt = "new,cell,raster";
- 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->type = TYPE_STRING;
- owa->required = YES;
- owa->gisprompt = "new,cell,raster";
- 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 */
-
- /* number of file (=criteria) */
- while (criteria->answers[ncriteria] != NULL)
- {
- ncriteria++;
- }
-
- /* 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 */
-
-
-
- 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);
-
- 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);
-
- 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);
-
- 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_owa) < 0) /* check for legal database file names */
- G_fatal_error(_("<%s> is an illegal file name"), result_owa);
-
- /*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*/
- }
- }
-
- /* 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);
-
- /* 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);
-
- 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);
-
-
- /*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 */
-
- 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_and, outrast_and, DCELL_TYPE) < 0)
- G_fatal_error(_("Failed writing raster map <%s>"), result_and);
-
- 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());
-
- /* memory cleanup */
- 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(decision_vol);
-
-
-
- /* closing raster maps */
- 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);
-
- /* add command line incantation to history AND file */
- G_short_history(result_and, "raster", &history);
- G_command_history(&history);
- G_write_history(result_and, &history);
-
- /* add command line incantation to history OR file */
- G_short_history(result_or, "raster", &history);
- G_command_history(&history);
- G_write_history(result_or, &history);
-
- /* add command line incantation to history OWA file */
- G_short_history(result_owa, "raster", &history);
- G_command_history(&history);
- G_write_history(result_owa, &history);
-
- exit(EXIT_SUCCESS);
-}
+
+/****************************************************************************
+ *
+ * MODULE: r.mcda.electre
+ * AUTHORS: Gianluca Massei (g_massa at libero.it) - Antonio Boggia (boggia at unipg.it)
+ *
+ * PURPOSE: Make a multicriterio decision analysis based on Yager fuzzy algorthm
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+
+
+#include "local_proto.h"
+
+
+/*
+ * main function
+ */
+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 *mapset; /* mapset name */
+ unsigned char *outrast_and, *outrast_or, *outrast_owa; /* output buffer */
+ 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;
+
+
+ struct History history; /* holds meta-data (title, comments,..) */
+
+ struct GModule *module; /* GRASS module for parsing arguments */
+
+ struct Option *criteria, *weight, *and, *or, *owa; /* options */
+
+ struct input *attributes; /*storage alla input criteria GRID files and output concordance and discordance GRID files */
+
+
+ /* initialize GIS environment */
+ G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */
+
+ /* initialize module */
+ module = G_define_module();
+ module->keywords = _("raster,fuzzy,MCDA");
+ 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->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->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->type = TYPE_STRING;
+ and->required = YES;
+ and->gisprompt = "new,cell,raster";
+ 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->type = TYPE_STRING;
+ or->required = YES;
+ or->gisprompt = "new,cell,raster";
+ 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->type = TYPE_STRING;
+ owa->required = YES;
+ owa->gisprompt = "new,cell,raster";
+ 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 */
+
+ /* number of file (=criteria) */
+ while (criteria->answers[ncriteria] != NULL)
+ {
+ ncriteria++;
+ }
+
+ /* 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 */
+
+
+
+ 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);
+
+ 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);
+
+ 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);
+
+ 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_owa) < 0) /* check for legal database file names */
+ G_fatal_error(_("<%s> is an illegal file name"), result_owa);
+
+ /*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*/
+ }
+ }
+
+ /* 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);
+
+ /* 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);
+
+ 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);
+
+
+ /*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 */
+
+ 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_and, outrast_and, DCELL_TYPE) < 0)
+ G_fatal_error(_("Failed writing raster map <%s>"), result_and);
+
+ 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());
+
+ /* memory cleanup */
+ 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(decision_vol);
+
+
+
+ /* closing raster maps */
+ 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);
+
+ /* add command line incantation to history AND file */
+ G_short_history(result_and, "raster", &history);
+ G_command_history(&history);
+ G_write_history(result_and, &history);
+
+ /* add command line incantation to history OR file */
+ G_short_history(result_or, "raster", &history);
+ G_command_history(&history);
+ G_write_history(result_or, &history);
+
+ /* add command line incantation to history OWA file */
+ G_short_history(result_owa, "raster", &history);
+ G_command_history(&history);
+ G_write_history(result_owa, &history);
+
+ exit(EXIT_SUCCESS);
+}
Property changes on: grass-addons/grass6/raster/r.mcda.fuzzy/main.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.regime/description.html
===================================================================
--- grass-addons/grass6/raster/r.mcda.regime/description.html 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.regime/description.html 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,19 +1,19 @@
-<h2>DESCRIPTION</h2>
-<em>r.mcda.regime </em> is the implementation of the REGIME multicriteria algorithm in GRASS GIS environment. It is one of the available tools in the r.mcda suite. It requires as an input the list of raster representing the criteria to be assessed in the multicriteria evaluation and the vector of weights to be assigned. Every single cell of the GRASS region is considered as one of the possible alternatives to evaluate and it is described with the value assumed for the same cell by the raster used as criteria. </P>
-<br>
-<h2>NOTES</h2>
-<p>The module does not standardize the raster-criteria. Therefore, they must be prepared before by using, for example, r.mapcalc. The weights vector is always normalized so that the sum of the weights is 1.</P>
-<br>
-<h2>REFERENCE</h2>
-<p>Janssen R. (1994) - Multiobjective decision support for environmental management, Kluwer Academic Publishers;</P>
-<p>GRASS Development Team (2008);</P>
-<br>
-<h2>SEE ALSO</h2>
-<p><em>r.mcda.fuzzy, r.mcda.electre, r.roughet, r.mapcalc</em></P>
-<br>
-<h2>AUTHORS</h2>
-<p>Antonio Boggia - Gianluca Massei
-<br>Department of Economics and Appraisal - University of Perugia - Italy
-</P>
-<p>
-<i>Last changed: $Date: 2011-11-08 22:56:45 +0100 (mar, 08 nov 2011) $</i>
+<h2>DESCRIPTION</h2>
+<em>r.mcda.regime </em> is the implementation of the REGIME multicriteria algorithm in GRASS GIS environment. It is one of the available tools in the r.mcda suite. It requires as an input the list of raster representing the criteria to be assessed in the multicriteria evaluation and the vector of weights to be assigned. Every single cell of the GRASS region is considered as one of the possible alternatives to evaluate and it is described with the value assumed for the same cell by the raster used as criteria. </P>
+<br>
+<h2>NOTES</h2>
+<p>The module does not standardize the raster-criteria. Therefore, they must be prepared before by using, for example, r.mapcalc. The weights vector is always normalized so that the sum of the weights is 1.</P>
+<br>
+<h2>REFERENCE</h2>
+<p>Janssen R. (1994) - Multiobjective decision support for environmental management, Kluwer Academic Publishers;</P>
+<p>GRASS Development Team (2008);</P>
+<br>
+<h2>SEE ALSO</h2>
+<p><em>r.mcda.fuzzy, r.mcda.electre, r.roughet, r.mapcalc</em></P>
+<br>
+<h2>AUTHORS</h2>
+<p>Antonio Boggia - Gianluca Massei
+<br>Department of Economics and Appraisal - University of Perugia - Italy
+</P>
+<p>
+<i>Last changed: $Date$</i>
Property changes on: grass-addons/grass6/raster/r.mcda.regime/description.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.regime/local_proto.h
===================================================================
--- grass-addons/grass6/raster/r.mcda.regime/local_proto.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.regime/local_proto.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,15 +1,15 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include <grass/config.h>
-
-
-struct input
-{
- char *name, *mapset; /* input raster name and mapset name */
- int infd;
- void *inrast; /* input buffer */
-};
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include <grass/config.h>
+
+
+struct input
+{
+ char *name, *mapset; /* input raster name and mapset name */
+ int infd;
+ void *inrast; /* input buffer */
+};
Property changes on: grass-addons/grass6/raster/r.mcda.regime/local_proto.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.regime/main.c
===================================================================
--- grass-addons/grass6/raster/r.mcda.regime/main.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.regime/main.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,212 +1,212 @@
-
-/****************************************************************************
- *
- * MODULE: r.mcda.electre
- * AUTHORS Gianluca Massei (g_massa at libero.it) - Antonio Boggia (boggia at unipg.it)
- *
- * PURPOSE: Make a multi-criterio decision analysis based on REGIME algorthm
- *
- * COPYRIGHT: (C) G.Massei - A.Boggia (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-
-
-#include "local_proto.h"
-
-
-/*
- * main function
- */
-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 *mapset; /* mapset name */
- unsigned char *outrast_preference; /* output buffer */
- char *message;
- 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;
-
-
- struct History history; /* holds meta-data (title, comments,..) */
-
- struct GModule *module; /* GRASS module for parsing arguments */
-
- struct Option *criteria, *weight, *preference; /* options */
-
- struct input *attributes; /*storage alla input criteria GRID files and output concordance and discordance GRID files */
-
-
- /* initialize GIS environment */
- G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */
-
- /* initialize module */
- module = G_define_module();
- module->keywords = _("raster,MCDA");
- 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";
-
- 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->type = TYPE_STRING;
- preference->required = YES;
- preference->gisprompt = "new,cell,raster";
- preference->answer = "regime_map";
- preference->description = "regime preference output map";
-
-
- /* options and flags parser */
- if (G_parser(argc, argv))
- exit(EXIT_FAILURE);
-
-
- G_message("start: %s", G_date()); /*write calculation start time */
-
- /* number of file (=criteria) */
- while (criteria->answers[ncriteria] != NULL)
- {
- ncriteria++;
- }
-
- /* 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 */
-
-
-
- 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);
-
- 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);
-
- 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);
-
- 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)); */
-
- 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 */
- }
- }
-
- /* Allocate output buffer, use 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);
-
-
- /*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);
- }
- }
- }
-
- 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());
-
- /* memory cleanup */
- for (i = 0; i < ncriteria; i++)
- G_free(attributes[i].inrast);
-
- G_free(outrast_preference);
- G_free(decision_vol);
-
- /* closing raster maps */
- for (i = 0; i < ncriteria; i++)
- G_close_cell(attributes[i].infd);
-
- G_close_cell(outfd_preference);
-
- /* add command line incantation to history regime preference file index */
- G_short_history(result_preference, "raster", &history);
- G_command_history(&history);
- G_write_history(result_preference, &history);
-
- exit(EXIT_SUCCESS);
-}
+
+/****************************************************************************
+ *
+ * MODULE: r.mcda.electre
+ * AUTHORS Gianluca Massei (g_massa at libero.it) - Antonio Boggia (boggia at unipg.it)
+ *
+ * PURPOSE: Make a multi-criterio decision analysis based on REGIME algorthm
+ *
+ * COPYRIGHT: (C) G.Massei - A.Boggia (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+
+
+#include "local_proto.h"
+
+
+/*
+ * main function
+ */
+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 *mapset; /* mapset name */
+ unsigned char *outrast_preference; /* output buffer */
+ char *message;
+ 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;
+
+
+ struct History history; /* holds meta-data (title, comments,..) */
+
+ struct GModule *module; /* GRASS module for parsing arguments */
+
+ struct Option *criteria, *weight, *preference; /* options */
+
+ struct input *attributes; /*storage alla input criteria GRID files and output concordance and discordance GRID files */
+
+
+ /* initialize GIS environment */
+ G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */
+
+ /* initialize module */
+ module = G_define_module();
+ module->keywords = _("raster,MCDA");
+ 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";
+
+ 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->type = TYPE_STRING;
+ preference->required = YES;
+ preference->gisprompt = "new,cell,raster";
+ preference->answer = "regime_map";
+ preference->description = "regime preference output map";
+
+
+ /* options and flags parser */
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+
+ G_message("start: %s", G_date()); /*write calculation start time */
+
+ /* number of file (=criteria) */
+ while (criteria->answers[ncriteria] != NULL)
+ {
+ ncriteria++;
+ }
+
+ /* 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 */
+
+
+
+ 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);
+
+ 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);
+
+ 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);
+
+ 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)); */
+
+ 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 */
+ }
+ }
+
+ /* Allocate output buffer, use 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);
+
+
+ /*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);
+ }
+ }
+ }
+
+ 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());
+
+ /* memory cleanup */
+ for (i = 0; i < ncriteria; i++)
+ G_free(attributes[i].inrast);
+
+ G_free(outrast_preference);
+ G_free(decision_vol);
+
+ /* closing raster maps */
+ for (i = 0; i < ncriteria; i++)
+ G_close_cell(attributes[i].infd);
+
+ G_close_cell(outfd_preference);
+
+ /* add command line incantation to history regime preference file index */
+ G_short_history(result_preference, "raster", &history);
+ G_command_history(&history);
+ G_write_history(result_preference, &history);
+
+ exit(EXIT_SUCCESS);
+}
Property changes on: grass-addons/grass6/raster/r.mcda.regime/main.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.regime/regime.c
===================================================================
--- grass-addons/grass6/raster/r.mcda.regime/regime.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.regime/regime.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,98 +1,98 @@
-#include "local_proto.h"
-
-/*
- * global function declaration
- */
-
-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);
-
-
-/*
- * function definitions
- */
-
-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 */
-
- }
-
-}
-
-
-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;
-
- row_sum_regime=G_malloc(ncriteria * nrows * ncols * sizeof(double*));
-
- 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;
- }
- }
- G_percent(j, nrows*ncols, 2);
- j++; /* increase rows index up to 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);
- }
-}
+#include "local_proto.h"
+
+/*
+ * global function declaration
+ */
+
+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);
+
+
+/*
+ * function definitions
+ */
+
+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 */
+
+ }
+
+}
+
+
+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;
+
+ row_sum_regime=G_malloc(ncriteria * nrows * ncols * sizeof(double*));
+
+ 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;
+ }
+ }
+ G_percent(j, nrows*ncols, 2);
+ j++; /* increase rows index up to 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);
+ }
+}
Property changes on: grass-addons/grass6/raster/r.mcda.regime/regime.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.mcda.roughset/description.html
===================================================================
--- grass-addons/grass6/raster/r.mcda.roughset/description.html 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.mcda.roughset/description.html 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,31 +1,31 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.mcda.roughset</em> is the python implementation of the dominance rough set approach (Domlem algorithm) in GRASS GIS environment. It requires the following input:
-<br>1. the geographical criteria constituting the information system for the rough set analysis; they have to describe environmental, economic or social issues(<b>criteria</b>=<em>name[,name,...]</em>);<br> 2. the preference (<b>preferences</b>=<em>character</em>)for each criteria used in analysis (gain or cost with comma separator)<br>3. the theme in which areas with the issues to be studied are classified (with crescent preference values) (<b>decision</b>=<em>string</em>).
-
-<p>An information system is generated and Domlem algorithm is applied for extraction a minimal set of rules.</P> The algorithm builds two text files (<b>outputTxt</b>=<em>name</em>): the first with isf extension for more deep analysis with non geographic software like 4emka and JAMM ; the second file with rls extension hold all the set of rules generate. An output map (<b>outputMap</b>=<em>string</em>)is generated for region classification with the rules finded and the criteria stored in GRASS geodb.
-
-<h2>NOTES</h2>
-<p> The module can work very slowly with high number of criteria and sample. For bug please contact Gianluca Massei (g_mass at libero.it)</P>
-
-
-<h2>REFERENCE</h2>
-<ol>
- <li><p>Greco S., Matarazzo B., Slowinski R.: <i>Rough sets theory for multicriteria decision analysis</i>. European Journal of Operational Research, 129, 1 (2001) 1-47.</P>
- <li><p>Greco S., Matarazzo B., Slowinski R.:<i> Multicriteria classification by dominance-based rough set approach</i>. In: W.Kloesgen and J.Zytkow (eds.), Handbook of Data Mining and Knowledge Discovery, Oxford University Press, New York, 2002.</P>
- <li><p>Greco S., Matarazzo B., Slowinski, R., Stefanowski, J.: <i>An Algorithm for Induction of Decision Rules Consistent with the Dominance Principle</i>. In W. Ziarko, Y. Yao (eds.): Rough Sets and Current Trends in Computing. Lecture Notes in Artificial Intelligence 2005 (2001) 304 - 313. Springer-Verlag</P>
- <li><p>Greco, S., B. Matarazzo, R. Slowinski and J. Stefanowski:<i> Variable consistency model of dominance-based rough set approach.</i> In W.Ziarko, Y.Yao (eds.): Rough Sets and Current Trends in Computing. Lecture Notes in Artificial Intelligence 2005 (2001) 170 - 181. Springer-Verlag</P>
- <li><p><a href="http://en.wikipedia.org/wiki/Dominance-based_rough_set_approach">http://en.wikipedia.org/wiki/Dominance-based_rough_set_approach</a> - “Dominance-based rough set approach”</P>
- <li><p><a href="http://idss.cs.put.poznan.pl/site/software.html">http://idss.cs.put.poznan.pl/site/software.html</a> - Software from Laboratory of intelligent decision support system in Poznam University of Technology
- </P>
-</ol>
-
-<h2>SEE ALSO</h2>
-<p><em>r.mcda.fuzzy, r.mcda.electre, r.mcda.regime, r.to.drsa, r.in.drsa</em></P>
-
-<h2>AUTHORS</h2>
-Antonio Boggia - Gianluca Massei<br>
-Department of Economics and Appraisal - University of Perugia - Italy
-
-<p>
-<i>Last changed: $Date: 2011-11-08 22:56:45 +0100 (mar, 08 nov 2011) $</i>
+<h2>DESCRIPTION</h2>
+
+<em>r.mcda.roughset</em> is the python implementation of the dominance rough set approach (Domlem algorithm) in GRASS GIS environment. It requires the following input:
+<br>1. the geographical criteria constituting the information system for the rough set analysis; they have to describe environmental, economic or social issues(<b>criteria</b>=<em>name[,name,...]</em>);<br> 2. the preference (<b>preferences</b>=<em>character</em>)for each criteria used in analysis (gain or cost with comma separator)<br>3. the theme in which areas with the issues to be studied are classified (with crescent preference values) (<b>decision</b>=<em>string</em>).
+
+<p>An information system is generated and Domlem algorithm is applied for extraction a minimal set of rules.</P> The algorithm builds two text files (<b>outputTxt</b>=<em>name</em>): the first with isf extension for more deep analysis with non geographic software like 4emka and JAMM ; the second file with rls extension hold all the set of rules generate. An output map (<b>outputMap</b>=<em>string</em>)is generated for region classification with the rules finded and the criteria stored in GRASS geodb.
+
+<h2>NOTES</h2>
+<p> The module can work very slowly with high number of criteria and sample. For bug please contact Gianluca Massei (g_mass at libero.it)</P>
+
+
+<h2>REFERENCE</h2>
+<ol>
+ <li><p>Greco S., Matarazzo B., Slowinski R.: <i>Rough sets theory for multicriteria decision analysis</i>. European Journal of Operational Research, 129, 1 (2001) 1-47.</P>
+ <li><p>Greco S., Matarazzo B., Slowinski R.:<i> Multicriteria classification by dominance-based rough set approach</i>. In: W.Kloesgen and J.Zytkow (eds.), Handbook of Data Mining and Knowledge Discovery, Oxford University Press, New York, 2002.</P>
+ <li><p>Greco S., Matarazzo B., Slowinski, R., Stefanowski, J.: <i>An Algorithm for Induction of Decision Rules Consistent with the Dominance Principle</i>. In W. Ziarko, Y. Yao (eds.): Rough Sets and Current Trends in Computing. Lecture Notes in Artificial Intelligence 2005 (2001) 304 - 313. Springer-Verlag</P>
+ <li><p>Greco, S., B. Matarazzo, R. Slowinski and J. Stefanowski:<i> Variable consistency model of dominance-based rough set approach.</i> In W.Ziarko, Y.Yao (eds.): Rough Sets and Current Trends in Computing. Lecture Notes in Artificial Intelligence 2005 (2001) 170 - 181. Springer-Verlag</P>
+ <li><p><a href="http://en.wikipedia.org/wiki/Dominance-based_rough_set_approach">http://en.wikipedia.org/wiki/Dominance-based_rough_set_approach</a> - “Dominance-based rough set approach”</P>
+ <li><p><a href="http://idss.cs.put.poznan.pl/site/software.html">http://idss.cs.put.poznan.pl/site/software.html</a> - Software from Laboratory of intelligent decision support system in Poznam University of Technology
+ </P>
+</ol>
+
+<h2>SEE ALSO</h2>
+<p><em>r.mcda.fuzzy, r.mcda.electre, r.mcda.regime, r.to.drsa, r.in.drsa</em></P>
+
+<h2>AUTHORS</h2>
+Antonio Boggia - Gianluca Massei<br>
+Department of Economics and Appraisal - University of Perugia - Italy
+
+<p>
+<i>Last changed: $Date$</i>
Property changes on: grass-addons/grass6/raster/r.mcda.roughset/description.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Property changes on: grass-addons/grass6/raster/r.mcda.roughset/r.mcda.roughset.py
___________________________________________________________________
Added: svn:mime-type
+ text/x-python
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/description.html
===================================================================
--- grass-addons/grass6/raster/r.roughset/description.html 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/description.html 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,68 +1,68 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.roughset</em> is the implementation of the rough set theory [1,2] in GRASS GIS environment. It requires the following input:
-<br>1. the geographical attributes constituting the information system for the rough set analysis; they have to describe environmental, economic or social issues(<b>attributes</b>=<em>string[,string,...]</em>);<br> 2.the theme in which areas with the issues to be studied are identified (<b>decision</b>=<em>string</em>).
-
-<p>An information system is generated and the functions of version 2 of rough set library (RSL, ver. 2.0) [3] are applied, following one of the decision strategies available with the option<b>strgy</b>=<em>string.</em></P>
-<p><em>The choice of the classification strategy, </em><em><b>clssfy</b></em><em>=string
-</em><em> is necessary to generate a map based on the attributes and the decision rules. Three options are available:</em><em><I>Classify1,Classify2,Classify3</I></em><em> </em><em>each of them is referred to a different algorithm. [3]. </em><br><br>It is possible to get three different output files; two of them are text files, the third is a raster file: </P>
-<p>a. <I>text file</I> structured following the standard of the rough set library, having the name registered in the <b>outTXT</b><I><SPAN STYLE="font-weight: normal">=string</I> without any additional extension. The file can be used as well with RSL implementation out of GIS environment.</P>
-<p><I>NAME: name of the information system </I></P>
-<p><I>ATTRIBUTES: 4 (number of attributes) </I></P>
-<p><I>OBJECTS: 8 (number of objects)</I></P>
-<p><I>0 0 0 0 </I>
-</P>
-<p><I>1 0 1 1</I></P>
-<p><I>1 1 0 0 </I>
-</P>
-<p><I>0 2 0 1 </I>
-</P>
-<p><I>1 2 0 1 </I>
-</P>
-<p><I>1 0 0 0 </I>
-</P>
-<p><I>1 2 0 1 </I>
-</P>
-<p><I>0 0 1 1 </I>
-</P>
-
-<p>The number of attributes is the number of raster given as input at <b>attributes</b>=<em>string[,string,...]
-</em><em> plus the decision raster </em><em>(</em><em><b>decision</b></em><em>=string) </em><em>located in the last column of the information system, by default. </em></P>
-<p>b. <I>text file</I>, having the name defined in <b>outTXT</b><I><SPAN STYLE="font-weight: normal">=string</I>
-and the .<I>out</I>, extension. It contains the decision rules extracted from the geographic information system; decision rules are expressed as:
- <I>if ... then </I> and they are easy to read and to be interpreted by the user; <br>c. <I>raster, </I>having the name defined in the field <b>outMAP</b><I>=string,
-</I> resulting from the application of the decision rules generated by the geographic information system following one of the classification strategies in <em><b>clssfy</b></em><em>=string.
-</em><em> Rules to apply can derive from an information system generated from the data entered in </em><em><b>attributes</b></em><em>=</em><em>string
-</em><em>and</em><em>
-</em><em><b>decision</b></em><em>=string
-</em><em>or from a text file generated from a previous processing stage. In this case the file structure must be as the one reported in box 1. </em></P>
-
-
-<h2>NOTES</h2>
-<p>The module can process CELL raster, and calculations can be made only with integer (int) variables. This is a constraint imposed by the rough set library. The decision rules, therefore, provide only integer information. </P>
-
-
-<h2>REFERENCE</h2>
-<ol>
- <li><p>Pawlak Z. Rough Sets, International Journal of
- Information and Computer Science Vol. 11, No. 5, 1982, pp.
- 344-356.</P>
- <li><p>Pawlak Z. Rough Sets, Theoretical Aspects of
- Reasoning about Data, Kluwer Academic Publishers, 1991.</P>
- <li><p>Gawrys M., Sienkiewicz J. Rough Set
- Library - User's manual (ver. 2.0), September 1993</P>
- <li><p><a href="http://en.wikipedia.org/wiki/Rough_set">http://en.wikipedia.org/wiki/Rough_set</a>
- - “rough set”</P>
- <p>
- </P>
-</ol>
-
-<h2>SEE ALSO</h2>
-<p><em>r.mcda.fuzzy, r.mcda.electre, r.mcda.regime</em></P>
-
-<h2>AUTHORS</h2>
-Antonio Boggia - Gianluca Massei<br>
-Department of Economics and Appraisal - University of Perugia - Italy
-
-<p>
-<i>Last changed: $Date: 2011-11-08 22:56:45 +0100 (mar, 08 nov 2011) $</i>
+<h2>DESCRIPTION</h2>
+
+<em>r.roughset</em> is the implementation of the rough set theory [1,2] in GRASS GIS environment. It requires the following input:
+<br>1. the geographical attributes constituting the information system for the rough set analysis; they have to describe environmental, economic or social issues(<b>attributes</b>=<em>string[,string,...]</em>);<br> 2.the theme in which areas with the issues to be studied are identified (<b>decision</b>=<em>string</em>).
+
+<p>An information system is generated and the functions of version 2 of rough set library (RSL, ver. 2.0) [3] are applied, following one of the decision strategies available with the option<b>strgy</b>=<em>string.</em></P>
+<p><em>The choice of the classification strategy, </em><em><b>clssfy</b></em><em>=string
+</em><em> is necessary to generate a map based on the attributes and the decision rules. Three options are available:</em><em><I>Classify1,Classify2,Classify3</I></em><em> </em><em>each of them is referred to a different algorithm. [3]. </em><br><br>It is possible to get three different output files; two of them are text files, the third is a raster file: </P>
+<p>a. <I>text file</I> structured following the standard of the rough set library, having the name registered in the <b>outTXT</b><I><SPAN STYLE="font-weight: normal">=string</I> without any additional extension. The file can be used as well with RSL implementation out of GIS environment.</P>
+<p><I>NAME: name of the information system </I></P>
+<p><I>ATTRIBUTES: 4 (number of attributes) </I></P>
+<p><I>OBJECTS: 8 (number of objects)</I></P>
+<p><I>0 0 0 0 </I>
+</P>
+<p><I>1 0 1 1</I></P>
+<p><I>1 1 0 0 </I>
+</P>
+<p><I>0 2 0 1 </I>
+</P>
+<p><I>1 2 0 1 </I>
+</P>
+<p><I>1 0 0 0 </I>
+</P>
+<p><I>1 2 0 1 </I>
+</P>
+<p><I>0 0 1 1 </I>
+</P>
+
+<p>The number of attributes is the number of raster given as input at <b>attributes</b>=<em>string[,string,...]
+</em><em> plus the decision raster </em><em>(</em><em><b>decision</b></em><em>=string) </em><em>located in the last column of the information system, by default. </em></P>
+<p>b. <I>text file</I>, having the name defined in <b>outTXT</b><I><SPAN STYLE="font-weight: normal">=string</I>
+and the .<I>out</I>, extension. It contains the decision rules extracted from the geographic information system; decision rules are expressed as:
+ <I>if ... then </I> and they are easy to read and to be interpreted by the user; <br>c. <I>raster, </I>having the name defined in the field <b>outMAP</b><I>=string,
+</I> resulting from the application of the decision rules generated by the geographic information system following one of the classification strategies in <em><b>clssfy</b></em><em>=string.
+</em><em> Rules to apply can derive from an information system generated from the data entered in </em><em><b>attributes</b></em><em>=</em><em>string
+</em><em>and</em><em>
+</em><em><b>decision</b></em><em>=string
+</em><em>or from a text file generated from a previous processing stage. In this case the file structure must be as the one reported in box 1. </em></P>
+
+
+<h2>NOTES</h2>
+<p>The module can process CELL raster, and calculations can be made only with integer (int) variables. This is a constraint imposed by the rough set library. The decision rules, therefore, provide only integer information. </P>
+
+
+<h2>REFERENCE</h2>
+<ol>
+ <li><p>Pawlak Z. Rough Sets, International Journal of
+ Information and Computer Science Vol. 11, No. 5, 1982, pp.
+ 344-356.</P>
+ <li><p>Pawlak Z. Rough Sets, Theoretical Aspects of
+ Reasoning about Data, Kluwer Academic Publishers, 1991.</P>
+ <li><p>Gawrys M., Sienkiewicz J. Rough Set
+ Library - User's manual (ver. 2.0), September 1993</P>
+ <li><p><a href="http://en.wikipedia.org/wiki/Rough_set">http://en.wikipedia.org/wiki/Rough_set</a>
+ - “rough set”</P>
+ <p>
+ </P>
+</ol>
+
+<h2>SEE ALSO</h2>
+<p><em>r.mcda.fuzzy, r.mcda.electre, r.mcda.regime</em></P>
+
+<h2>AUTHORS</h2>
+Antonio Boggia - Gianluca Massei<br>
+Department of Economics and Appraisal - University of Perugia - Italy
+
+<p>
+<i>Last changed: $Date$</i>
Property changes on: grass-addons/grass6/raster/r.roughset/description.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/localproto.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/localproto.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/localproto.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,15 +1,15 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stddef.h>
-#include <time.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
-
-struct input
-{
- char *name, *mapset;
- int fd;
- CELL *buf;
-};
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stddef.h>
+#include <time.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+
+struct input
+{
+ char *name, *mapset;
+ int fd;
+ CELL *buf;
+};
Property changes on: grass-addons/grass6/raster/r.roughset/localproto.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/main.c
===================================================================
--- grass-addons/grass6/raster/r.roughset/main.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/main.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,276 +1,276 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-
-#include "localproto.h"
-
-
-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 */
-
- RASTER_MAP_TYPE data_type; /* type of the map (CELL/DCELL/...) */
-
- /*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 */
-
- /* initialize GIS environment */
- G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */
-
- /* initialize module */
- module = G_define_module();
- module->keywords = _("raster,geographics knowledge discovery");
- module->description = _("Rough set based geographics knowledge ");
-
-
- /* 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");
-
- 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)");
-
- 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->description = _("Output information system file");
-
- output_map = G_define_option();
- output_map->key = "outMAP";
- output_map->type = TYPE_STRING;
- output_map->required = YES;
- 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!"));
-
- /***********************************************************************/
-
- /********Prepare and controlling Information System files **************/
-
- /***********************************************************************/
-
- /* number of file (=attributes) */
- nattributes = 0;
- while (attr_map->answers[nattributes] != NULL)
- {
- nattributes++;
- }
-
- /* 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;
- else
- strgy = 7;
-
- /*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;
-
-
- /* process the input maps: */
- /* ATTRIBUTES grid */
- 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 * */
-
- }
-
-
- /* 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 vector */
-
- /* 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;
- G_message("%d", c);
- j++;
- }
-
- 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);
-}
-
-/* dom 07 dic 2008 07:05:15 CET */
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+
+#include "localproto.h"
+
+
+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 */
+
+ RASTER_MAP_TYPE data_type; /* type of the map (CELL/DCELL/...) */
+
+ /*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 */
+
+ /* initialize GIS environment */
+ G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */
+
+ /* initialize module */
+ module = G_define_module();
+ module->keywords = _("raster,geographics knowledge discovery");
+ module->description = _("Rough set based geographics knowledge ");
+
+
+ /* 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");
+
+ 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)");
+
+ 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->description = _("Output information system file");
+
+ output_map = G_define_option();
+ output_map->key = "outMAP";
+ output_map->type = TYPE_STRING;
+ output_map->required = YES;
+ 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!"));
+
+ /***********************************************************************/
+
+ /********Prepare and controlling Information System files **************/
+
+ /***********************************************************************/
+
+ /* number of file (=attributes) */
+ nattributes = 0;
+ while (attr_map->answers[nattributes] != NULL)
+ {
+ nattributes++;
+ }
+
+ /* 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;
+ else
+ strgy = 7;
+
+ /*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;
+
+
+ /* process the input maps: */
+ /* ATTRIBUTES grid */
+ 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 * */
+
+ }
+
+
+ /* 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 vector */
+
+ /* 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;
+ G_message("%d", c);
+ j++;
+ }
+
+ 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);
+}
+
+/* dom 07 dic 2008 07:05:15 CET */
Property changes on: grass-addons/grass6/raster/r.roughset/main.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/raccess.c
===================================================================
--- grass-addons/grass6/raster/r.roughset/raccess.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/raccess.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,232 +1,232 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * 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;
-
-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);
-}
-
-void next_of_x(void)
-{
- _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;
- }
- }
- 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);
-}
-
-int end_of_tab(void)
-{
- return (_table_element < _table_end);
-}
-
-void next_of_tab(void)
-{
- (*_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;
-}
-
-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])
- 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;
-}
-
-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;
-
- 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]);
-}
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * 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;
+
+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);
+}
+
+void next_of_x(void)
+{
+ _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;
+ }
+ }
+ 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);
+}
+
+int end_of_tab(void)
+{
+ return (_table_element < _table_end);
+}
+
+void next_of_tab(void)
+{
+ (*_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;
+}
+
+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])
+ 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;
+}
+
+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;
+
+ 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]);
+}
Property changes on: grass-addons/grass6/raster/r.roughset/raccess.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/raccess.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/raccess.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/raccess.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,77 +1,77 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-
-/*** ***/
-
-/*** FUNCTIONS OF ACCESS TO SYSTEM TABLES ***/
-
-/*** ***/
-
-/*** part of the RSL system written by M.Gawrys J. Sienkiewicz ***/
-
-/*** ***/
-
-/*****************************************************************************/
-
-
-#define START_OF_D _table_element=_mainsys->matD,_table_end=_table_element+Dsize(_mainsys)
-#define START_OF_X _table_element=_mainsys->matX,_table_end=_table_element+_mainsys->matXsize
-#define START_OF_MAT(set,num) _table_element=(set),_table_end=_table_element+(num)*_mainsys->setAsize
-#define END_OF_MAT (_table_element<_table_end)
-#define NEXT_OF_MAT _table_element+=_mainsys->setAsize
-#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;
-
-
-int start_of_tab(int matrix_type);
-void next_of_tab(void);
-int end_of_tab(void);
-
-
-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);
-
- /* compares two objects on the sigle attribute atr */
- /* returns 1 if identical, otherwise returns 0 */
-
-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);
-
- /* returns value of attribute atr of object obj */
- /* from matrix A */
-
-int GetDfromA(setA elem, int ob1, int ob2);
-
- /* generate a single element of matrix D into elem */
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+
+/*** ***/
+
+/*** FUNCTIONS OF ACCESS TO SYSTEM TABLES ***/
+
+/*** ***/
+
+/*** part of the RSL system written by M.Gawrys J. Sienkiewicz ***/
+
+/*** ***/
+
+/*****************************************************************************/
+
+
+#define START_OF_D _table_element=_mainsys->matD,_table_end=_table_element+Dsize(_mainsys)
+#define START_OF_X _table_element=_mainsys->matX,_table_end=_table_element+_mainsys->matXsize
+#define START_OF_MAT(set,num) _table_element=(set),_table_end=_table_element+(num)*_mainsys->setAsize
+#define END_OF_MAT (_table_element<_table_end)
+#define NEXT_OF_MAT _table_element+=_mainsys->setAsize
+#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;
+
+
+int start_of_tab(int matrix_type);
+void next_of_tab(void);
+int end_of_tab(void);
+
+
+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);
+
+ /* compares two objects on the sigle attribute atr */
+ /* returns 1 if identical, otherwise returns 0 */
+
+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);
+
+ /* returns value of attribute atr of object obj */
+ /* from matrix A */
+
+int GetDfromA(setA elem, int ob1, int ob2);
+
+ /* generate a single element of matrix D into elem */
Property changes on: grass-addons/grass6/raster/r.roughset/raccess.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rbasic.c
===================================================================
--- grass-addons/grass6/raster/r.roughset/rbasic.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rbasic.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,631 +1,631 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * 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 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 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;
-}
-
-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 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;
-}
-
-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);
- 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 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 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;
-}
-
-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 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;
-}
-
-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;
-}
-
-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);
- }
- }
- 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 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 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;
-}
-
-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 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;
-}
-
-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;
-}
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * 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 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 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;
+}
+
+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 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;
+}
+
+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);
+ 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 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 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;
+}
+
+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 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;
+}
+
+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;
+}
+
+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);
+ }
+ }
+ 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 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 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;
+}
+
+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 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;
+}
+
+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;
+}
Property changes on: grass-addons/grass6/raster/r.roughset/rbasic.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rbasic.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/rbasic.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rbasic.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,99 +1,99 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-
-/*** ***/
-
-/*** BASIC QUERRIES FOR SYSTEM ***/
-
-/*** ***/
-
-/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
-
-/*** ***/
-
-/*****************************************************************************/
-
-
-/* If a function from this section value a set, this set should be */
-/* 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);
-
- /* 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);
-
- /* 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);
-
- /* 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);
-
- /* 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);
-
- /* 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);
-
- /* 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);
-
- /* 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);
-
- /* 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);
-
- /* significance of attribute attr */
- /* in the set P, relatively to Q */
-
-
-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" */
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+
+/*** ***/
+
+/*** BASIC QUERRIES FOR SYSTEM ***/
+
+/*** ***/
+
+/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
+/*** ***/
+
+/*****************************************************************************/
+
+
+/* If a function from this section value a set, this set should be */
+/* 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);
+
+ /* 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);
+
+ /* 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);
+
+ /* 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);
+
+ /* 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);
+
+ /* 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);
+
+ /* 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);
+
+ /* 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);
+
+ /* 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);
+
+ /* significance of attribute attr */
+ /* in the set P, relatively to Q */
+
+
+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" */
Property changes on: grass-addons/grass6/raster/r.roughset/rbasic.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rclass.c
===================================================================
--- grass-addons/grass6/raster/r.roughset/rclass.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rclass.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,248 +1,248 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-/*** ***/
-/*** SOME MORE QUERIES FOR SYSTEM ***/
-/*** ( CLASSIFICATION ) ***/
-/*** ***/
-/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
-/*** ***/
-/*****************************************************************************/
-
-
-#include <stdlib.h>
-#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 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;
-}
-
-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);
- }
- 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 *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 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;
-}
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+/*** ***/
+/*** SOME MORE QUERIES FOR SYSTEM ***/
+/*** ( CLASSIFICATION ) ***/
+/*** ***/
+/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+/*** ***/
+/*****************************************************************************/
+
+
+#include <stdlib.h>
+#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 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;
+}
+
+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);
+ }
+ 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 *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 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;
+}
Property changes on: grass-addons/grass6/raster/r.roughset/rclass.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rclass.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/rclass.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rclass.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,82 +1,82 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * 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);
-
- /* compares decisions of two rules */
- /* returns 1 if equal */
-
-int StrengthOfRule(value_type * rule);
-
- /* return a number of objects covered by rule (strength) */
-
-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);
-
- /* finds a set of objects covered by rule */
-
-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);
-
- /* 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);
-
- /* 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);
-
- /* 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);
- /* 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 */
- /* returns index of a proper rule */
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * 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);
+
+ /* compares decisions of two rules */
+ /* returns 1 if equal */
+
+int StrengthOfRule(value_type * rule);
+
+ /* return a number of objects covered by rule (strength) */
+
+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);
+
+ /* finds a set of objects covered by rule */
+
+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);
+
+ /* 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);
+
+ /* 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);
+
+ /* 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);
+ /* 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 */
+ /* returns index of a proper rule */
Property changes on: grass-addons/grass6/raster/r.roughset/rclass.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rcore.c
===================================================================
--- grass-addons/grass6/raster/r.roughset/rcore.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rcore.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,364 +1,364 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-/*** ***/
-/*** SOME MORE QUERIES FOR SYSTEM ***/
-/*** ( FINDING CORES AND CHECKING REDUCTS ) ***/
-/*** ***/
-/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
-/*** ***/
-/*****************************************************************************/
-
-
-#include "rough.h"
-#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 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);
- }
- 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;
- }
- if (flag)
- break;
- }
- if (no1 == 1)
- core[pcluster] |= ELEM_OF_MAT[pcluster];
- }
- 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 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 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);
-}
-
-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 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;
-}
-
-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 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;
-
- 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;
-}
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+/*** ***/
+/*** SOME MORE QUERIES FOR SYSTEM ***/
+/*** ( FINDING CORES AND CHECKING REDUCTS ) ***/
+/*** ***/
+/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+/*** ***/
+/*****************************************************************************/
+
+
+#include "rough.h"
+#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 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);
+ }
+ 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;
+ }
+ if (flag)
+ break;
+ }
+ if (no1 == 1)
+ core[pcluster] |= ELEM_OF_MAT[pcluster];
+ }
+ 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 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 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);
+}
+
+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 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;
+}
+
+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 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;
+
+ 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;
+}
Property changes on: grass-addons/grass6/raster/r.roughset/rcore.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rcore.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/rcore.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rcore.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,80 +1,80 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * 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);
-
- /* 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);
-
- /* finds a core of P relativly to Q */
-
-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);
-
- /* 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);
-
- /* 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);
-
- /* return 1 if red is Q-cover in P */
- /* otherwise returns 0 */
-
-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);
-
- /* returns 1 if red is a Q-relative reduct of P */
- /* otherwise returns 0 */
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * 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);
+
+ /* 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);
+
+ /* finds a core of P relativly to Q */
+
+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);
+
+ /* 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);
+
+ /* 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);
+
+ /* return 1 if red is Q-cover in P */
+ /* otherwise returns 0 */
+
+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);
+
+ /* returns 1 if red is a Q-relative reduct of P */
+ /* otherwise returns 0 */
Property changes on: grass-addons/grass6/raster/r.roughset/rcore.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/reduct1.c
===================================================================
--- grass-addons/grass6/raster/r.roughset/reduct1.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/reduct1.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,1305 +1,1305 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * 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;
- }
- }
- }
- 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;
- }
- 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;
-
- 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);
- }
- 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;
- }
- 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);
-}
-
-
-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;
- }
- 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;
- }
- 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);
-}
-
-
-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;
-
- 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);
- }
- 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);
-}
-
-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);
- }
- 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);
-}
-
-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 ((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);
-}
-
-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;
- 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);
-}
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * 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;
+ }
+ }
+ }
+ 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;
+ }
+ 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;
+
+ 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);
+ }
+ 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;
+ }
+ 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);
+}
+
+
+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;
+ }
+ 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;
+ }
+ 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);
+}
+
+
+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;
+
+ 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);
+ }
+ 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);
+}
+
+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);
+ }
+ 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);
+}
+
+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 ((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);
+}
+
+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;
+ 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);
+}
Property changes on: grass-addons/grass6/raster/r.roughset/reduct1.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/reduct1.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/reduct1.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/reduct1.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,78 +1,78 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * 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);
-
- /* finds all reducts for information system, */
- /* sets red to yhe allocated reducts table */
- /* function returns number of reducts */
-
-
-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);
-
- /* 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);
-
- /* like RedLess, but reducts are Q-relative of P */
-
-
-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);
-
- /* like RedSetA, but reducts are Q-relative of P */
-
-
-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);
-
- /* like RedFirst, but reducts are Q-relative of P */
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * 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);
+
+ /* finds all reducts for information system, */
+ /* sets red to yhe allocated reducts table */
+ /* function returns number of reducts */
+
+
+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);
+
+ /* 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);
+
+ /* like RedLess, but reducts are Q-relative of P */
+
+
+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);
+
+ /* like RedSetA, but reducts are Q-relative of P */
+
+
+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);
+
+ /* like RedFirst, but reducts are Q-relative of P */
Property changes on: grass-addons/grass6/raster/r.roughset/reduct1.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/reduct2.c
===================================================================
--- grass-addons/grass6/raster/r.roughset/reduct2.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/reduct2.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,236 +1,236 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * 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 i;
- 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);
- 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;
- }
- 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;
-}
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * 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 i;
+ 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);
+ 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;
+ }
+ 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;
+}
Property changes on: grass-addons/grass6/raster/r.roughset/reduct2.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/reduct2.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/reduct2.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/reduct2.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,74 +1,74 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * 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);
-
- /* heuristicly searches for a single reduct and stores it in red */
-
-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);
-
- /* 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);
-
- /* 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);
-
- /* 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);
-
- /* 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);
-
- /* returns index of the single shortest reduct */
- /* from the table of num reducts pointed by reds */
-
-int SelectAllShort(setA * newreds, setA reds, int num);
-
- /* copies all the shortest reducts */
- /* from the table of num reducts pointed by reds */
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * 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);
+
+ /* heuristicly searches for a single reduct and stores it in red */
+
+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);
+
+ /* 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);
+
+ /* 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);
+
+ /* 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);
+
+ /* 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);
+
+ /* returns index of the single shortest reduct */
+ /* from the table of num reducts pointed by reds */
+
+int SelectAllShort(setA * newreds, setA reds, int num);
+
+ /* copies all the shortest reducts */
+ /* from the table of num reducts pointed by reds */
Property changes on: grass-addons/grass6/raster/r.roughset/reduct2.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rerror.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/rerror.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rerror.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,45 +1,45 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * 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"
-};
-
-#define ErrorPrint() {printf("ERROR no: %i: %s\n",_rerror,errcodes[_rerror]);_rerror=0;}
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * 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"
+};
+
+#define ErrorPrint() {printf("ERROR no: %i: %s\n",_rerror,errcodes[_rerror]);_rerror=0;}
Property changes on: grass-addons/grass6/raster/r.roughset/rerror.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rough.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/rough.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rough.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,73 +1,73 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * 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 ***********************************/
-
-#define MATA 0
-#define MATD 1
-#define MATX 2
-
-#define ERROR(a) { _rerror=a; return -a; }
-
-typedef unsigned int cluster_type;
-typedef unsigned int value_type;
-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;
-
-/************** H-FILES CONTAINING DECLARATIONS OF FUNCTIONS *********/
-
-#include "rset.h"
-#include "rsystem.h"
-#include "raccess.h"
-#include "rbasic.h"
-#include "rcore.h"
-#include "reduct1.h"
-#include "reduct2.h"
-#include "rule1.h"
-#include "rule2.h"
-#include "rclass.h"
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * 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 ***********************************/
+
+#define MATA 0
+#define MATD 1
+#define MATX 2
+
+#define ERROR(a) { _rerror=a; return -a; }
+
+typedef unsigned int cluster_type;
+typedef unsigned int value_type;
+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;
+
+/************** H-FILES CONTAINING DECLARATIONS OF FUNCTIONS *********/
+
+#include "rset.h"
+#include "rsystem.h"
+#include "raccess.h"
+#include "rbasic.h"
+#include "rcore.h"
+#include "reduct1.h"
+#include "reduct2.h"
+#include "rule1.h"
+#include "rule2.h"
+#include "rclass.h"
Property changes on: grass-addons/grass6/raster/r.roughset/rough.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rset.c
===================================================================
--- grass-addons/grass6/raster/r.roughset/rset.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rset.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,500 +1,500 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-/*** ***/
-/*** OPERATIONS ON SETS OF ATTRIBUTES AND OBJECTS ***/
-/*** ***/
-/*** part of the RSL system written by M.Gawrys J. Sienkiewicz ***/
-/*** ***/
-/*****************************************************************************/
-
-
-#include "rough.h"
-#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;
-}
-
-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 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;
-}
-
-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;
-}
-
-void TabToSetA(setA set, int num, int tab[])
-{
- int atr;
-
- ClearSetA(set);
- for (atr = 0; atr < num; atr++)
- AddSetA(set, tab[atr]);
-}
-
-void TabToSetO(setO set, int num, int tab[])
-{
- int obj;
-
- ClearSetO(set);
- for (obj = 0; obj < num; obj++)
- AddSetO(set, tab[obj]);
-}
-
-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);
-}
-
-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);
-}
-
-void CloseSetA(setA set)
-{
- free(set);
-}
-
-void CloseSetO(setA set)
-{
- free(set);
-}
-
-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;
-}
-
-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 AndSetO(setO and, setO s1, setO s2)
-{
- int cluster;
-
- for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
- and[cluster] = s1[cluster] & s2[cluster];
- return;
-}
-
-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 DifSetO(setO dif, setO s1, setO s2)
-{
- int cluster;
-
- for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
- dif[cluster] = s1[cluster] & ~s2[cluster];
- return;
-}
-
-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;
-}
-
-
-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;
-}
-
-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;
-}
-
-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;
-}
-
-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++;
- 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 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;
-}
-
-int SizeSetA(void)
-{
- 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);
-}
-
-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;
-}
-
-
-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");
-}
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+/*** ***/
+/*** OPERATIONS ON SETS OF ATTRIBUTES AND OBJECTS ***/
+/*** ***/
+/*** part of the RSL system written by M.Gawrys J. Sienkiewicz ***/
+/*** ***/
+/*****************************************************************************/
+
+
+#include "rough.h"
+#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;
+}
+
+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 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;
+}
+
+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;
+}
+
+void TabToSetA(setA set, int num, int tab[])
+{
+ int atr;
+
+ ClearSetA(set);
+ for (atr = 0; atr < num; atr++)
+ AddSetA(set, tab[atr]);
+}
+
+void TabToSetO(setO set, int num, int tab[])
+{
+ int obj;
+
+ ClearSetO(set);
+ for (obj = 0; obj < num; obj++)
+ AddSetO(set, tab[obj]);
+}
+
+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);
+}
+
+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);
+}
+
+void CloseSetA(setA set)
+{
+ free(set);
+}
+
+void CloseSetO(setA set)
+{
+ free(set);
+}
+
+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;
+}
+
+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 AndSetO(setO and, setO s1, setO s2)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
+ and[cluster] = s1[cluster] & s2[cluster];
+ return;
+}
+
+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 DifSetO(setO dif, setO s1, setO s2)
+{
+ int cluster;
+
+ for (cluster = _mainsys->setOsize - 1; cluster >= 0; cluster--)
+ dif[cluster] = s1[cluster] & ~s2[cluster];
+ return;
+}
+
+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;
+}
+
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+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++;
+ 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 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;
+}
+
+int SizeSetA(void)
+{
+ 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);
+}
+
+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;
+}
+
+
+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");
+}
Property changes on: grass-addons/grass6/raster/r.roughset/rset.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rset.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/rset.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rset.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,165 +1,165 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-
-/*** ***/
-
-/*** OPERATIONS ON SETS OF ATTRIBUTES AND OBJECTS ***/
-
-/*** ***/
-
-/*** part of the RSL system written by M.Gawrys J. Sienkiewicz ***/
-
-/*** ***/
-
-/*****************************************************************************/
-
-
-#include <stdarg.h>
-
-extern cluster_type _mask[];
-extern int _cluster_bytes;
-extern int _cluster_bits;
-
-setO InitEmptySetO(void);
-setA InitEmptySetA(void);
-
- /* allocates memory for set and initializes it */
- /* 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[]);
-
- /* sets a set with num elements of table tab */
-
-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);
-
- /* puts union of s1 and s2 to or */
-
-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);
-
- /* puts complement of s1 in s2 to dif */
-
-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);
-
- /* adds element to set */
-
-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);
-
- /* return 1 if set big contains set small */
- /* otherwise returns 0 */
-
-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);
-
- /* 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);
-
- /* copy source to dest */
-
-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);
-
- /* puts into set all object that have value val */
- /* on attribute attr */
-
-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 */
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+
+/*** ***/
+
+/*** OPERATIONS ON SETS OF ATTRIBUTES AND OBJECTS ***/
+
+/*** ***/
+
+/*** part of the RSL system written by M.Gawrys J. Sienkiewicz ***/
+
+/*** ***/
+
+/*****************************************************************************/
+
+
+#include <stdarg.h>
+
+extern cluster_type _mask[];
+extern int _cluster_bytes;
+extern int _cluster_bits;
+
+setO InitEmptySetO(void);
+setA InitEmptySetA(void);
+
+ /* allocates memory for set and initializes it */
+ /* 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[]);
+
+ /* sets a set with num elements of table tab */
+
+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);
+
+ /* puts union of s1 and s2 to or */
+
+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);
+
+ /* puts complement of s1 in s2 to dif */
+
+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);
+
+ /* adds element to set */
+
+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);
+
+ /* return 1 if set big contains set small */
+ /* otherwise returns 0 */
+
+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);
+
+ /* 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);
+
+ /* copy source to dest */
+
+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);
+
+ /* puts into set all object that have value val */
+ /* on attribute attr */
+
+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 */
Property changes on: grass-addons/grass6/raster/r.roughset/rset.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rsystem.c
===================================================================
--- grass-addons/grass6/raster/r.roughset/rsystem.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rsystem.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,564 +1,564 @@
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors and Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-/*** ***/
-/*** SYSTEM HANDLING FUNCTIONS ***/
-/*** ***/
-/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
-/*** ***/
-/*****************************************************************************/
-
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "rough.h"
-
-SYSTEM *_mainsys=NULL;
-int _rerror=0;
-
-SYSTEM *InitEmptySys(void)
-{
- SYSTEM *sys;
- int i;
- cluster_type mask=1;
- if ((sys=(SYSTEM *)malloc(sizeof(SYSTEM)))==NULL)
- {
- _rerror=3;
- return NULL;
- }
- for (i=0; i<_cluster_bits; i++)
- {
- _mask[i]=mask;
- mask <<= 1;
- }
- sys->attributes_num=0;
- sys->objects_num=0;
- sys->description=NULL;
- sys->descr_size=0;
- sys->setAsize=0;
- sys->setOsize=0;
- sys->matA=NULL;
- sys->matD=NULL;
- sys->matX=NULL;
- sys->matXsize=0;
- return sys;
-}
-
-void SetParameters(SYSTEM *sys,int obj_num,int attr_num)
-{
- sys->attributes_num=attr_num;
- sys->objects_num=obj_num;
- sys->setAsize=1+(attr_num-1)/_cluster_bits;
- sys->setOsize=1+(obj_num-1)/_cluster_bits;
-}
-
-void ConnectDescr(SYSTEM *sys,void *descr,int size)
-{
- sys->description=descr;
- sys->descr_size=size;
-}
-
-void SetName(SYSTEM *sys,char *name)
-{
- strncpy(sys->name,name,50);
-}
-
-int FileToSys(SYSTEM *sys,char *filename)
-{
- FILE *source;
- value_type *buf;
- int descr_size,matAsize;
- long len1,len2;
- char string[50];
- int c,n=0;
- if (sys->matA!=NULL)
- {
- free(sys->matA);
- sys->matA=NULL;
- }
- if (sys->matD!=NULL)
- {
- free(sys->matD);
- sys->matD=NULL;
- }
- if (sys->matX!=NULL)
- {
- free(sys->matX);
- sys->matX=NULL;
- }
- if (sys->description!=NULL)
- {
- free(sys->description);
- sys->description=NULL;
- }
- if ((source=fopen(filename,"r"))==NULL)
- ERROR(1)
- if (!fscanf(source,"NAME%c",string))
- ERROR(2)
- if (string[0]!=':') ERROR(2)
- if (!fgets(sys->name,48,source))
- ERROR(2)
- if (sys->name[strlen(sys->name)-1]=='\n')
- sys->name[strlen(sys->name)-1]='\0';
- else
- while (fgetc(source)!='\n' && !feof(source));
- if (!fscanf(source,"ATTRIBUTES:%i\n",&(sys->attributes_num)))
- ERROR(2)
- if (!fscanf(source,"OBJECTS:%i\n",&(sys->objects_num)))
- ERROR(2)
- sys->setAsize=1+(sys->attributes_num-1)/_cluster_bits;
- sys->setOsize=1+(sys->objects_num-1)/_cluster_bits;
- matAsize=(sys->objects_num)*(sys->attributes_num);
- if ((buf=(value_type*)(setA)malloc(sizeof(value_type)*matAsize))==NULL)
- ERROR(3)
- while (!feof(source) && n<matAsize)
- if (fscanf(source,"%s",string)==NULL)
- ERROR(2)
- else if (string[0]=='?' || string[0]=='*')
- buf[n++]=(value_type)-1;
- else if (sscanf(string,"%d",&c)==NULL)
- ERROR(2)
- else buf[n++]=(value_type)c;
- sys->matA=buf;
- while (isspace(fgetc(source)));
- if (!feof(source))
- {
- len1=ftell(source)-1;
- fseek(source,0l,SEEK_END);
- len2=ftell(source);
- fseek(source,len1,SEEK_SET);
- descr_size=(int)(len2-len1);
- buf=(value_type *)(setA)malloc(descr_size);
- fread(buf,sizeof(char),descr_size,source);
- sys->description=buf;
- sys->descr_size=descr_size;
- }
- fclose(source);
- return 1;
-}
-
-void ConnectA(SYSTEM *sys,value_type *buf)
-{
- sys->matA=buf;
-}
-
-void PutA(SYSTEM *sys,int obj,int atr,value_type val)
-{
- (sys->matA)[obj*(sys->attributes_num)+atr]=val;
-}
-
-int FillAfromAscii(SYSTEM *sys,FILE *file)
-{
- int k=0,j;
- while (!feof(file)&&(k<Asize(sys)))
- {
- if (fscanf(file,"%d",&j)==NULL) ERROR(2);
- *(sys->matA+k++)=j;
- }
- return 0;
-}
-
-int InitD(SYSTEM *sys)
-{
- cluster_type *buf;
- int nby=(sys->attributes_num)/_cluster_bits; /* number of full clusters in element of tableD */
- int nbi=sys->attributes_num%_cluster_bits; /* number of bits in the last cluster */
- int atrnum=sys->attributes_num; /* number of attributes */
- int row,column,cluster,bit;
- value_type *A=sys->matA;
- cluster_type val,*ptr;
- if (A==NULL)
- ERROR(5);
- if ((buf=(setA)malloc(MatMemSize(sys,MATD)))==NULL)
- ERROR(3);
- ptr=buf;
- for (row=1;row<sys->objects_num;row++)
- for (column=0;column<row;column++)
- {
- for (cluster=0;cluster<nby;cluster++)
- {
- val=0;
- for (bit=0;bit<_cluster_bits;bit++)
- if (A[row*atrnum+_cluster_bits*cluster+bit]!=A[column*atrnum+_cluster_bits*cluster+bit] &&
- A[row*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1 &&
- A[column*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1 )
- val=val|_mask[bit];
- *ptr=val;
- ptr++;
- }
- if (nbi)
- {
- val=0;
- for (bit=0;bit<nbi;bit++)
- if (A[row*atrnum+_cluster_bits*cluster+bit]!=A[column*atrnum+_cluster_bits*cluster+bit] &&
- A[row*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1 &&
- A[column*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1 )
- val=val|_mask[bit];
- *ptr=val;
- ptr++;
- }
- }
- sys->matD=buf;
- return MatMemSize(sys,MATD);
-}
-
-int InitX(SYSTEM* sys,setA P,setA Q,int matrix_type)
-{
- setA head,tail,el,el1;
- int memo=1,count=0,no,dif,size,MEMOKWANT=Asize(_mainsys);
- size=_mainsys->setAsize;
- if ((head=(setA)malloc(MEMOKWANT))==NULL) ERROR(3);
- tail=head;
- el=InitEmptySetA();
- for (start_of_tab(matrix_type);end_of_tab();next_of_tab())
- {
- if ( !InterSetA(_table_element,Q) ) continue;
- AndSetA(el,P,_table_element);
- if ( IsEmptySetA(el) ) continue;
- no=0;
- dif=0;
- for (el1=head;el1<tail;el1+=size)
- if (InSetA(el,el1))
- {
- no=1;
- break;
- }
- else
- {
- if (InSetA(el1,el)) dif+=size,count--;
- else if (dif) CopySetA(el1-dif,el1);
- }
- if (!no)
- {
- if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
- if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
- {
- CloseSetA(el);
- ERROR(3);
- }
- CopySetA(head+count*size,el);
- count++;
- tail=head+count*size;
- }
- }
- CloseSetA(el);
- if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL) ERROR(3);
- sys->matX=head;
- sys->matXsize=count*size;
- return(count);
-}
-
-int InitXforObject(SYSTEM* sys,int obj,setA P,setA Q,int matrix_type)
-{
- setA head,tail,el,el1;
- int memo=1,count=0,no,dif,MEMOKWANT=Asize(_mainsys);
- int size=_mainsys->setAsize;
- int obj2;
- if ((head=(setA)malloc(MEMOKWANT))==NULL)
- ERROR(3);
- tail=head;
- el=InitEmptySetA();
- for (obj2=0; obj2<_mainsys->objects_num; obj2++)
- {
- if ( obj==obj2 ) continue;
- if ( matrix_type==MATA ) GetDfromA( el, obj, obj2 );
- else
- {
- _table_element=GetD( obj, obj2 );
- CopySetA( el, _table_element );
- }
- if ( !InterSetA(el,Q) ) continue;
- AndSetA(el,P,el);
- if ( IsEmptySetA(el) ) continue;
- no=0;
- dif=0;
- for (el1=head;el1<tail;el1+=size)
- if (InSetA(el,el1))
- {
- no=1;
- break;
- }
- else
- {
- if (InSetA(el1,el)) dif+=size,count--;
- else if (dif) CopySetA(el1-dif,el1);
- }
- if (!no)
- {
- if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
- if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
- {
- CloseSetA(el);
- ERROR(3);
- }
- CopySetA(head+count*size,el);
- count++;
- tail=head+count*size;
- }
- }
- CloseSetA(el);
- if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL)
- if (count>0) ERROR(3);
- sys->matX=head;
- sys->matXsize=count*size;
- return(count);
-}
-
-int InitXforObjects(SYSTEM* sys,setO objects,setA P,setA Q,int matrix_type)
-{
- setA head,tail,el,el1;
- int memo=1,count=0,no,dif,size,MEMOKWANT=Asize(_mainsys);
- size=_mainsys->setAsize;
- if ((head=(setA)malloc(MEMOKWANT))==NULL) ERROR(3);
- tail=head;
- el=InitEmptySetA();
- for (start_of_tab(matrix_type);end_of_tab();next_of_tab())
- {
- if ( !ContSetO(objects,_table_row) &&
- !ContSetO(objects,_table_column) ) continue;
- if ( !InterSetA(_table_element,Q) ) continue;
- AndSetA(el,P,_table_element);
- if ( IsEmptySetA(el) ) continue;
- no=0;
- dif=0;
- for (el1=head;el1<tail;el1+=size)
- if (InSetA(el,el1))
- {
- no=1;
- break;
- }
- else
- {
- if (InSetA(el1,el)) dif+=size,count--;
- else if (dif) CopySetA(el1-dif,el1);
- }
- if (!no)
- {
- if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
- if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
- {
- CloseSetA(el);
- ERROR(3);
- }
- CopySetA(head+count*size,el);
- count++;
- tail=head+count*size;
- }
- }
- CloseSetA(el);
- if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL) ERROR(3);
- sys->matX=head;
- sys->matXsize=count*size;
- return(count);
-}
-
-int InitXforObjectFromClass(SYSTEM* sys,int obj,setA P,setO aclass,int matrix_type)
-{
- setA head,tail,el,el1;
- int memo=1,count=0,no,dif,MEMOKWANT=Asize(_mainsys);
- int size=_mainsys->setAsize;
- int obj2;
- if ((head=(setA)malloc(MEMOKWANT))==NULL) ERROR(3);
- tail=head;
- el=InitEmptySetA();
- for (obj2=0; obj2<_mainsys->objects_num; obj2++)
- {
- if ( ContSetO( aclass, obj2 ) ) continue;
- if ( matrix_type==MATA ) GetDfromA( el, obj, obj2 );
- else
- {
- _table_element=GetD( obj, obj2 );
- CopySetA( el, _table_element );
- }
- AndSetA(el,P,el);
- if ( IsEmptySetA(el) ) continue;
- no=0;
- dif=0;
- for (el1=head;el1<tail;el1+=size)
- if (InSetA(el,el1))
- {
- no=1;
- break;
- }
- else
- {
- if (InSetA(el1,el)) dif+=size,count--;
- else if (dif) CopySetA(el1-dif,el1);
- }
- if (!no)
- {
- if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
- if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
- {
- CloseSetA(el);
- ERROR(3);
- }
- CopySetA(head+count*size,el);
- count++;
- tail=head+count*size;
- }
- }
- CloseSetA(el);
- if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL) ERROR(3);
- sys->matX=head;
- sys->matXsize=count*size;
- return(count);
-}
-
-
-
-void UseSys(SYSTEM *sys)
-{
- _mainsys=sys;
-}
-
-int SysToFile(SYSTEM *sys,char *filename)
-{
- FILE *output;
- int attr,obj;
- if ((output=fopen(filename,"wb"))==NULL)
- ERROR(1)
- if (!fprintf(output,"NAME: %s\n",sys->name))
- ERROR(4)
- if (!fprintf(output,"ATTRIBUTES: %i\n",sys->attributes_num))
- ERROR(4);
- if (!fprintf(output,"OBJECTS: %i\n\n",sys->objects_num))
- ERROR(4);
- for (obj=0;obj<sys->objects_num;obj++)
- {
- for (attr=0;attr<sys->attributes_num;attr++)
- if (sys->matA[obj*sys->attributes_num+attr]==(value_type)-1 )
- {
- if (!fprintf(output,"%c ",'?'))
- ERROR(4)
- }
- else if (!fprintf(output,"%i ",sys->matA[obj*sys->attributes_num+attr]))
- ERROR(4)
- fprintf(output,"\n");
- }
- if (sys->descr_size!=0)
- {
- fprintf(output,"\n");
- fwrite(sys->description,sizeof(char),sys->descr_size,output);
- }
- fclose(output);
- return 1;
-}
-
-void CloseSys(SYSTEM *sys)
-{
- if (sys->matA) free(sys->matA);
- if (sys->matD) free(sys->matD);
- if (sys->matX) free(sys->matX);
- if (sys->description) free(sys->description);
- free(sys);
-}
-
-void CloseMat(SYSTEM *sys, int matrix_type)
-{
- switch (matrix_type)
- {
- case (MATA): if (sys->matA) free(sys->matA);
- sys->matA=NULL;
- return;
- case (MATD): if (sys->matD) free(sys->matD);
- sys->matD=NULL;
- return;
- case (MATX): if (sys->matX) free(sys->matX);
- sys->matX=NULL;
- return;
- default:
- _rerror=8;
- }
-}
-
-void DisconMat(SYSTEM *sys, int matrix_type)
-{
- switch (matrix_type)
- {
- case (MATA): sys->matA=NULL;
- return;
- case (MATD): sys->matD=NULL;
- return;
- case (MATX): sys->matX=NULL;
- return;
- default:
- _rerror=8;
- }
-}
-
-unsigned int Asize(SYSTEM *sys)
-{
- return (unsigned int)(sys->attributes_num)
- *(unsigned int)(sys->objects_num);
-}
-
-unsigned int Dsize(SYSTEM *sys)
-{
- return (unsigned int)(sys->objects_num-1)
- *(unsigned int)(sys->objects_num)/2
- *(unsigned int)(sys->setAsize);
-}
-
-unsigned int Xsize(SYSTEM *sys)
-{
- return sys->matXsize;
-}
-
-unsigned int MatMemSize(SYSTEM *sys,int matrix_type)
-{
- switch (matrix_type)
- {
- case (MATA): return Asize(sys)*sizeof(value_type);
- case (MATD): return Dsize(sys)*sizeof(cluster_type);
- case (MATX): return Xsize(sys)*sizeof(cluster_type);
- }
- ERROR(8)
-}
-
-void *MatExist(SYSTEM *sys,int matrix_type)
-{
- switch (matrix_type)
- {
- case (MATA): return (void *)sys->matA;
- case (MATD): return (void *)sys->matD;
- case (MATX): return (void *)sys->matX;
- }
- _rerror=8;
- return NULL;
-}
-
-int ObjectsNum(SYSTEM *sys)
-{
- return sys->objects_num ;
-}
-
-int AttributesNum(SYSTEM *sys)
-{
- return sys->attributes_num;
-}
-
-void *Description(SYSTEM *sys)
-{
- return sys->description;
-}
-
-char *SysName(SYSTEM *sys)
-{
- return sys->name;
-}
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors and Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+/*** ***/
+/*** SYSTEM HANDLING FUNCTIONS ***/
+/*** ***/
+/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+/*** ***/
+/*****************************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "rough.h"
+
+SYSTEM *_mainsys=NULL;
+int _rerror=0;
+
+SYSTEM *InitEmptySys(void)
+{
+ SYSTEM *sys;
+ int i;
+ cluster_type mask=1;
+ if ((sys=(SYSTEM *)malloc(sizeof(SYSTEM)))==NULL)
+ {
+ _rerror=3;
+ return NULL;
+ }
+ for (i=0; i<_cluster_bits; i++)
+ {
+ _mask[i]=mask;
+ mask <<= 1;
+ }
+ sys->attributes_num=0;
+ sys->objects_num=0;
+ sys->description=NULL;
+ sys->descr_size=0;
+ sys->setAsize=0;
+ sys->setOsize=0;
+ sys->matA=NULL;
+ sys->matD=NULL;
+ sys->matX=NULL;
+ sys->matXsize=0;
+ return sys;
+}
+
+void SetParameters(SYSTEM *sys,int obj_num,int attr_num)
+{
+ sys->attributes_num=attr_num;
+ sys->objects_num=obj_num;
+ sys->setAsize=1+(attr_num-1)/_cluster_bits;
+ sys->setOsize=1+(obj_num-1)/_cluster_bits;
+}
+
+void ConnectDescr(SYSTEM *sys,void *descr,int size)
+{
+ sys->description=descr;
+ sys->descr_size=size;
+}
+
+void SetName(SYSTEM *sys,char *name)
+{
+ strncpy(sys->name,name,50);
+}
+
+int FileToSys(SYSTEM *sys,char *filename)
+{
+ FILE *source;
+ value_type *buf;
+ int descr_size,matAsize;
+ long len1,len2;
+ char string[50];
+ int c,n=0;
+ if (sys->matA!=NULL)
+ {
+ free(sys->matA);
+ sys->matA=NULL;
+ }
+ if (sys->matD!=NULL)
+ {
+ free(sys->matD);
+ sys->matD=NULL;
+ }
+ if (sys->matX!=NULL)
+ {
+ free(sys->matX);
+ sys->matX=NULL;
+ }
+ if (sys->description!=NULL)
+ {
+ free(sys->description);
+ sys->description=NULL;
+ }
+ if ((source=fopen(filename,"r"))==NULL)
+ ERROR(1)
+ if (!fscanf(source,"NAME%c",string))
+ ERROR(2)
+ if (string[0]!=':') ERROR(2)
+ if (!fgets(sys->name,48,source))
+ ERROR(2)
+ if (sys->name[strlen(sys->name)-1]=='\n')
+ sys->name[strlen(sys->name)-1]='\0';
+ else
+ while (fgetc(source)!='\n' && !feof(source));
+ if (!fscanf(source,"ATTRIBUTES:%i\n",&(sys->attributes_num)))
+ ERROR(2)
+ if (!fscanf(source,"OBJECTS:%i\n",&(sys->objects_num)))
+ ERROR(2)
+ sys->setAsize=1+(sys->attributes_num-1)/_cluster_bits;
+ sys->setOsize=1+(sys->objects_num-1)/_cluster_bits;
+ matAsize=(sys->objects_num)*(sys->attributes_num);
+ if ((buf=(value_type*)(setA)malloc(sizeof(value_type)*matAsize))==NULL)
+ ERROR(3)
+ while (!feof(source) && n<matAsize)
+ if (fscanf(source,"%s",string)==NULL)
+ ERROR(2)
+ else if (string[0]=='?' || string[0]=='*')
+ buf[n++]=(value_type)-1;
+ else if (sscanf(string,"%d",&c)==NULL)
+ ERROR(2)
+ else buf[n++]=(value_type)c;
+ sys->matA=buf;
+ while (isspace(fgetc(source)));
+ if (!feof(source))
+ {
+ len1=ftell(source)-1;
+ fseek(source,0l,SEEK_END);
+ len2=ftell(source);
+ fseek(source,len1,SEEK_SET);
+ descr_size=(int)(len2-len1);
+ buf=(value_type *)(setA)malloc(descr_size);
+ fread(buf,sizeof(char),descr_size,source);
+ sys->description=buf;
+ sys->descr_size=descr_size;
+ }
+ fclose(source);
+ return 1;
+}
+
+void ConnectA(SYSTEM *sys,value_type *buf)
+{
+ sys->matA=buf;
+}
+
+void PutA(SYSTEM *sys,int obj,int atr,value_type val)
+{
+ (sys->matA)[obj*(sys->attributes_num)+atr]=val;
+}
+
+int FillAfromAscii(SYSTEM *sys,FILE *file)
+{
+ int k=0,j;
+ while (!feof(file)&&(k<Asize(sys)))
+ {
+ if (fscanf(file,"%d",&j)==NULL) ERROR(2);
+ *(sys->matA+k++)=j;
+ }
+ return 0;
+}
+
+int InitD(SYSTEM *sys)
+{
+ cluster_type *buf;
+ int nby=(sys->attributes_num)/_cluster_bits; /* number of full clusters in element of tableD */
+ int nbi=sys->attributes_num%_cluster_bits; /* number of bits in the last cluster */
+ int atrnum=sys->attributes_num; /* number of attributes */
+ int row,column,cluster,bit;
+ value_type *A=sys->matA;
+ cluster_type val,*ptr;
+ if (A==NULL)
+ ERROR(5);
+ if ((buf=(setA)malloc(MatMemSize(sys,MATD)))==NULL)
+ ERROR(3);
+ ptr=buf;
+ for (row=1;row<sys->objects_num;row++)
+ for (column=0;column<row;column++)
+ {
+ for (cluster=0;cluster<nby;cluster++)
+ {
+ val=0;
+ for (bit=0;bit<_cluster_bits;bit++)
+ if (A[row*atrnum+_cluster_bits*cluster+bit]!=A[column*atrnum+_cluster_bits*cluster+bit] &&
+ A[row*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1 &&
+ A[column*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1 )
+ val=val|_mask[bit];
+ *ptr=val;
+ ptr++;
+ }
+ if (nbi)
+ {
+ val=0;
+ for (bit=0;bit<nbi;bit++)
+ if (A[row*atrnum+_cluster_bits*cluster+bit]!=A[column*atrnum+_cluster_bits*cluster+bit] &&
+ A[row*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1 &&
+ A[column*atrnum+_cluster_bits*cluster+bit]!=(value_type)-1 )
+ val=val|_mask[bit];
+ *ptr=val;
+ ptr++;
+ }
+ }
+ sys->matD=buf;
+ return MatMemSize(sys,MATD);
+}
+
+int InitX(SYSTEM* sys,setA P,setA Q,int matrix_type)
+{
+ setA head,tail,el,el1;
+ int memo=1,count=0,no,dif,size,MEMOKWANT=Asize(_mainsys);
+ size=_mainsys->setAsize;
+ if ((head=(setA)malloc(MEMOKWANT))==NULL) ERROR(3);
+ tail=head;
+ el=InitEmptySetA();
+ for (start_of_tab(matrix_type);end_of_tab();next_of_tab())
+ {
+ if ( !InterSetA(_table_element,Q) ) continue;
+ AndSetA(el,P,_table_element);
+ if ( IsEmptySetA(el) ) continue;
+ no=0;
+ dif=0;
+ for (el1=head;el1<tail;el1+=size)
+ if (InSetA(el,el1))
+ {
+ no=1;
+ break;
+ }
+ else
+ {
+ if (InSetA(el1,el)) dif+=size,count--;
+ else if (dif) CopySetA(el1-dif,el1);
+ }
+ if (!no)
+ {
+ if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
+ if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
+ {
+ CloseSetA(el);
+ ERROR(3);
+ }
+ CopySetA(head+count*size,el);
+ count++;
+ tail=head+count*size;
+ }
+ }
+ CloseSetA(el);
+ if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL) ERROR(3);
+ sys->matX=head;
+ sys->matXsize=count*size;
+ return(count);
+}
+
+int InitXforObject(SYSTEM* sys,int obj,setA P,setA Q,int matrix_type)
+{
+ setA head,tail,el,el1;
+ int memo=1,count=0,no,dif,MEMOKWANT=Asize(_mainsys);
+ int size=_mainsys->setAsize;
+ int obj2;
+ if ((head=(setA)malloc(MEMOKWANT))==NULL)
+ ERROR(3);
+ tail=head;
+ el=InitEmptySetA();
+ for (obj2=0; obj2<_mainsys->objects_num; obj2++)
+ {
+ if ( obj==obj2 ) continue;
+ if ( matrix_type==MATA ) GetDfromA( el, obj, obj2 );
+ else
+ {
+ _table_element=GetD( obj, obj2 );
+ CopySetA( el, _table_element );
+ }
+ if ( !InterSetA(el,Q) ) continue;
+ AndSetA(el,P,el);
+ if ( IsEmptySetA(el) ) continue;
+ no=0;
+ dif=0;
+ for (el1=head;el1<tail;el1+=size)
+ if (InSetA(el,el1))
+ {
+ no=1;
+ break;
+ }
+ else
+ {
+ if (InSetA(el1,el)) dif+=size,count--;
+ else if (dif) CopySetA(el1-dif,el1);
+ }
+ if (!no)
+ {
+ if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
+ if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
+ {
+ CloseSetA(el);
+ ERROR(3);
+ }
+ CopySetA(head+count*size,el);
+ count++;
+ tail=head+count*size;
+ }
+ }
+ CloseSetA(el);
+ if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL)
+ if (count>0) ERROR(3);
+ sys->matX=head;
+ sys->matXsize=count*size;
+ return(count);
+}
+
+int InitXforObjects(SYSTEM* sys,setO objects,setA P,setA Q,int matrix_type)
+{
+ setA head,tail,el,el1;
+ int memo=1,count=0,no,dif,size,MEMOKWANT=Asize(_mainsys);
+ size=_mainsys->setAsize;
+ if ((head=(setA)malloc(MEMOKWANT))==NULL) ERROR(3);
+ tail=head;
+ el=InitEmptySetA();
+ for (start_of_tab(matrix_type);end_of_tab();next_of_tab())
+ {
+ if ( !ContSetO(objects,_table_row) &&
+ !ContSetO(objects,_table_column) ) continue;
+ if ( !InterSetA(_table_element,Q) ) continue;
+ AndSetA(el,P,_table_element);
+ if ( IsEmptySetA(el) ) continue;
+ no=0;
+ dif=0;
+ for (el1=head;el1<tail;el1+=size)
+ if (InSetA(el,el1))
+ {
+ no=1;
+ break;
+ }
+ else
+ {
+ if (InSetA(el1,el)) dif+=size,count--;
+ else if (dif) CopySetA(el1-dif,el1);
+ }
+ if (!no)
+ {
+ if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
+ if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
+ {
+ CloseSetA(el);
+ ERROR(3);
+ }
+ CopySetA(head+count*size,el);
+ count++;
+ tail=head+count*size;
+ }
+ }
+ CloseSetA(el);
+ if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL) ERROR(3);
+ sys->matX=head;
+ sys->matXsize=count*size;
+ return(count);
+}
+
+int InitXforObjectFromClass(SYSTEM* sys,int obj,setA P,setO aclass,int matrix_type)
+{
+ setA head,tail,el,el1;
+ int memo=1,count=0,no,dif,MEMOKWANT=Asize(_mainsys);
+ int size=_mainsys->setAsize;
+ int obj2;
+ if ((head=(setA)malloc(MEMOKWANT))==NULL) ERROR(3);
+ tail=head;
+ el=InitEmptySetA();
+ for (obj2=0; obj2<_mainsys->objects_num; obj2++)
+ {
+ if ( ContSetO( aclass, obj2 ) ) continue;
+ if ( matrix_type==MATA ) GetDfromA( el, obj, obj2 );
+ else
+ {
+ _table_element=GetD( obj, obj2 );
+ CopySetA( el, _table_element );
+ }
+ AndSetA(el,P,el);
+ if ( IsEmptySetA(el) ) continue;
+ no=0;
+ dif=0;
+ for (el1=head;el1<tail;el1+=size)
+ if (InSetA(el,el1))
+ {
+ no=1;
+ break;
+ }
+ else
+ {
+ if (InSetA(el1,el)) dif+=size,count--;
+ else if (dif) CopySetA(el1-dif,el1);
+ }
+ if (!no)
+ {
+ if ((memo*MEMOKWANT)<((count+1)*size*_cluster_bytes))
+ if ((head=(setA)realloc(head,++memo*MEMOKWANT))==NULL)
+ {
+ CloseSetA(el);
+ ERROR(3);
+ }
+ CopySetA(head+count*size,el);
+ count++;
+ tail=head+count*size;
+ }
+ }
+ CloseSetA(el);
+ if ((head=(setA)realloc(head,count*size*_cluster_bytes))==NULL) ERROR(3);
+ sys->matX=head;
+ sys->matXsize=count*size;
+ return(count);
+}
+
+
+
+void UseSys(SYSTEM *sys)
+{
+ _mainsys=sys;
+}
+
+int SysToFile(SYSTEM *sys,char *filename)
+{
+ FILE *output;
+ int attr,obj;
+ if ((output=fopen(filename,"wb"))==NULL)
+ ERROR(1)
+ if (!fprintf(output,"NAME: %s\n",sys->name))
+ ERROR(4)
+ if (!fprintf(output,"ATTRIBUTES: %i\n",sys->attributes_num))
+ ERROR(4);
+ if (!fprintf(output,"OBJECTS: %i\n\n",sys->objects_num))
+ ERROR(4);
+ for (obj=0;obj<sys->objects_num;obj++)
+ {
+ for (attr=0;attr<sys->attributes_num;attr++)
+ if (sys->matA[obj*sys->attributes_num+attr]==(value_type)-1 )
+ {
+ if (!fprintf(output,"%c ",'?'))
+ ERROR(4)
+ }
+ else if (!fprintf(output,"%i ",sys->matA[obj*sys->attributes_num+attr]))
+ ERROR(4)
+ fprintf(output,"\n");
+ }
+ if (sys->descr_size!=0)
+ {
+ fprintf(output,"\n");
+ fwrite(sys->description,sizeof(char),sys->descr_size,output);
+ }
+ fclose(output);
+ return 1;
+}
+
+void CloseSys(SYSTEM *sys)
+{
+ if (sys->matA) free(sys->matA);
+ if (sys->matD) free(sys->matD);
+ if (sys->matX) free(sys->matX);
+ if (sys->description) free(sys->description);
+ free(sys);
+}
+
+void CloseMat(SYSTEM *sys, int matrix_type)
+{
+ switch (matrix_type)
+ {
+ case (MATA): if (sys->matA) free(sys->matA);
+ sys->matA=NULL;
+ return;
+ case (MATD): if (sys->matD) free(sys->matD);
+ sys->matD=NULL;
+ return;
+ case (MATX): if (sys->matX) free(sys->matX);
+ sys->matX=NULL;
+ return;
+ default:
+ _rerror=8;
+ }
+}
+
+void DisconMat(SYSTEM *sys, int matrix_type)
+{
+ switch (matrix_type)
+ {
+ case (MATA): sys->matA=NULL;
+ return;
+ case (MATD): sys->matD=NULL;
+ return;
+ case (MATX): sys->matX=NULL;
+ return;
+ default:
+ _rerror=8;
+ }
+}
+
+unsigned int Asize(SYSTEM *sys)
+{
+ return (unsigned int)(sys->attributes_num)
+ *(unsigned int)(sys->objects_num);
+}
+
+unsigned int Dsize(SYSTEM *sys)
+{
+ return (unsigned int)(sys->objects_num-1)
+ *(unsigned int)(sys->objects_num)/2
+ *(unsigned int)(sys->setAsize);
+}
+
+unsigned int Xsize(SYSTEM *sys)
+{
+ return sys->matXsize;
+}
+
+unsigned int MatMemSize(SYSTEM *sys,int matrix_type)
+{
+ switch (matrix_type)
+ {
+ case (MATA): return Asize(sys)*sizeof(value_type);
+ case (MATD): return Dsize(sys)*sizeof(cluster_type);
+ case (MATX): return Xsize(sys)*sizeof(cluster_type);
+ }
+ ERROR(8)
+}
+
+void *MatExist(SYSTEM *sys,int matrix_type)
+{
+ switch (matrix_type)
+ {
+ case (MATA): return (void *)sys->matA;
+ case (MATD): return (void *)sys->matD;
+ case (MATX): return (void *)sys->matX;
+ }
+ _rerror=8;
+ return NULL;
+}
+
+int ObjectsNum(SYSTEM *sys)
+{
+ return sys->objects_num ;
+}
+
+int AttributesNum(SYSTEM *sys)
+{
+ return sys->attributes_num;
+}
+
+void *Description(SYSTEM *sys)
+{
+ return sys->description;
+}
+
+char *SysName(SYSTEM *sys)
+{
+ return sys->name;
+}
Property changes on: grass-addons/grass6/raster/r.roughset/rsystem.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rsystem.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/rsystem.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rsystem.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,172 +1,172 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-
-/*** ***/
-
-/*** SYSTEM HANDLING FUNCTIONS ***/
-
-/*** ***/
-
-/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
-
-/*** ***/
-
-/*****************************************************************************/
-
-#include <stdio.h>
-
-extern SYSTEM *_mainsys;
-
- /* active information system */
-
-extern int _rerror;
-
- /* error code */
-
-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);
-
- /* puts system parameters to the system descriptor */
-
-void ConnectDescr(SYSTEM * sys, void *descr, int size);
-
- /* connects additional description to the system descriptor */
-
-void SetName(SYSTEM * sys, char *name);
-
- /* puts system name to the system descriptor */
-
-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);
-
- /* exports system descriptor, additional description */
- /* and matrix A to a special format file */
-
-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);
-
- /* sets value to element of matrix A */
-
-int FillAfromAscii(SYSTEM * sys, FILE * file);
-
- /* fills matrix A with the values from Ascii file */
-
-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);
-
- /* 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);
-
- /* works like InitX but considers only single column of MATD */
-
-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 matrix_type);
- /* works like InitX, conciders only specified objects */
- /* initialization is done with respect to objects from */
- /* outside of aclass */
-
-void UseSys(SYSTEM * sys);
-
- /* makes indicated system active, from now on */
- /* all query routines will operate only on it */
-
-void CloseSys(SYSTEM * sys);
-
- /* frees memory allocated for all matrixes, */
- /* system descriptor and additional description */
-
-void CloseMat(SYSTEM * sys, int matrix_type);
-
- /* disconnects matrix X from the system descriptor */
- /* and frees memory */
-
-void DisconMat(SYSTEM * sys, int matrix_type);
-
- /* disconnects matrix from the system descriptor */
- /* does not free memory */
-
-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);
-
- /* returns number of memory clusters for matrix D */
- /* memory size = Dsize * sizeof(cluster_type) */
- /* system parameters should be valued */
-
-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);
-
- /* 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);
-
- /* returns number of objects in the system */
-
-int AttributesNum(SYSTEM * sys);
-
- /* returns number of attributes in the system */
-
-void *Description(SYSTEM * sys);
-
- /* returns pointer to additional description */
-
-char *SysName(SYSTEM * sys);
-
- /* returns system name */
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+
+/*** ***/
+
+/*** SYSTEM HANDLING FUNCTIONS ***/
+
+/*** ***/
+
+/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
+/*** ***/
+
+/*****************************************************************************/
+
+#include <stdio.h>
+
+extern SYSTEM *_mainsys;
+
+ /* active information system */
+
+extern int _rerror;
+
+ /* error code */
+
+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);
+
+ /* puts system parameters to the system descriptor */
+
+void ConnectDescr(SYSTEM * sys, void *descr, int size);
+
+ /* connects additional description to the system descriptor */
+
+void SetName(SYSTEM * sys, char *name);
+
+ /* puts system name to the system descriptor */
+
+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);
+
+ /* exports system descriptor, additional description */
+ /* and matrix A to a special format file */
+
+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);
+
+ /* sets value to element of matrix A */
+
+int FillAfromAscii(SYSTEM * sys, FILE * file);
+
+ /* fills matrix A with the values from Ascii file */
+
+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);
+
+ /* 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);
+
+ /* works like InitX but considers only single column of MATD */
+
+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 matrix_type);
+ /* works like InitX, conciders only specified objects */
+ /* initialization is done with respect to objects from */
+ /* outside of aclass */
+
+void UseSys(SYSTEM * sys);
+
+ /* makes indicated system active, from now on */
+ /* all query routines will operate only on it */
+
+void CloseSys(SYSTEM * sys);
+
+ /* frees memory allocated for all matrixes, */
+ /* system descriptor and additional description */
+
+void CloseMat(SYSTEM * sys, int matrix_type);
+
+ /* disconnects matrix X from the system descriptor */
+ /* and frees memory */
+
+void DisconMat(SYSTEM * sys, int matrix_type);
+
+ /* disconnects matrix from the system descriptor */
+ /* does not free memory */
+
+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);
+
+ /* returns number of memory clusters for matrix D */
+ /* memory size = Dsize * sizeof(cluster_type) */
+ /* system parameters should be valued */
+
+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);
+
+ /* 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);
+
+ /* returns number of objects in the system */
+
+int AttributesNum(SYSTEM * sys);
+
+ /* returns number of attributes in the system */
+
+void *Description(SYSTEM * sys);
+
+ /* returns pointer to additional description */
+
+char *SysName(SYSTEM * sys);
+
+ /* returns system name */
Property changes on: grass-addons/grass6/raster/r.roughset/rsystem.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rule1.c
===================================================================
--- grass-addons/grass6/raster/r.roughset/rule1.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rule1.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,55 +1,55 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * 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));
-}
-
-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;
-}
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * 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));
+}
+
+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;
+}
Property changes on: grass-addons/grass6/raster/r.roughset/rule1.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rule1.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/rule1.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rule1.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,48 +1,48 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * 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);
-
- /* copies a rule from source to dest */
-
-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);
-
- /* adds new rule to array of rules */
- /* if the rule is unique size is incremented */
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * 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);
+
+ /* copies a rule from source to dest */
+
+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);
+
+ /* adds new rule to array of rules */
+ /* if the rule is unique size is incremented */
Property changes on: grass-addons/grass6/raster/r.roughset/rule1.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rule2.c
===================================================================
--- grass-addons/grass6/raster/r.roughset/rule2.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rule2.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,666 +1,666 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-/*** ***/
-/*** SOME MORE QUERIES FOR SYSTEM ***/
-/*** ( FINDING RULES ) ***/
-/*** ***/
-/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
-/*** ***/
-/*****************************************************************************/
-
-
-#include "rough.h"
-#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;
-
- *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;
-}
-
-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 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;
- }
- }
- 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);
- }
- if (option == BESTOPT)
- {
- i = Red(&red, MATX);
- j = SelectOneShort(red, i);
- }
- 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);
- }
- 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 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;
-}
-
-
-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 */
-
- *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;
- }
- 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);
- }
- 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 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;
-}
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+/*** ***/
+/*** SOME MORE QUERIES FOR SYSTEM ***/
+/*** ( FINDING RULES ) ***/
+/*** ***/
+/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+/*** ***/
+/*****************************************************************************/
+
+
+#include "rough.h"
+#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;
+
+ *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;
+}
+
+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 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;
+ }
+ }
+ 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);
+ }
+ if (option == BESTOPT)
+ {
+ i = Red(&red, MATX);
+ j = SelectOneShort(red, i);
+ }
+ 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);
+ }
+ 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 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;
+}
+
+
+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 */
+
+ *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;
+ }
+ 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);
+ }
+ 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 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;
+}
Property changes on: grass-addons/grass6/raster/r.roughset/rule2.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rule2.h
===================================================================
--- grass-addons/grass6/raster/r.roughset/rule2.h 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rule2.h 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,110 +1,110 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) GRASS Development Team (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
-
-/*** ***/
-
-/*** SOME MORE QUERIES FOR SYSTEM ***/
-
-/*** ( FINDING RULES ) ***/
-
-/*** ***/
-
-/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
-
-/*** ***/
-
-/*****************************************************************************/
-
-#define BESTOPT 0
-#define FASTOPT 1
-
-#define NORMAL 0
-#define LOWER 1
-#define UPPER 2
-
-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 N, setA Q, int matrix_type);
- /* 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);
-
- /* 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);
-
- /* finds minimal set of rules, allocates memory */
- /* P - condition attributes; Q - decision attributes */
- /* returns number of rules */
-
-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);
-
- /* finds set of rules, allocates memory */
- /* P - condition attributes; Q - decision attributes */
- /* returns number of rules */
-
-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 */
-
-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 */
-
-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 */
-
-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 */
-
-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 */
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) GRASS Development Team (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+
+/*** ***/
+
+/*** SOME MORE QUERIES FOR SYSTEM ***/
+
+/*** ( FINDING RULES ) ***/
+
+/*** ***/
+
+/*** part of the RSL system written by M.Gawrys J.Sienkiewicz ***/
+
+/*** ***/
+
+/*****************************************************************************/
+
+#define BESTOPT 0
+#define FASTOPT 1
+
+#define NORMAL 0
+#define LOWER 1
+#define UPPER 2
+
+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 N, setA Q, int matrix_type);
+ /* 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);
+
+ /* 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);
+
+ /* finds minimal set of rules, allocates memory */
+ /* P - condition attributes; Q - decision attributes */
+ /* returns number of rules */
+
+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);
+
+ /* finds set of rules, allocates memory */
+ /* P - condition attributes; Q - decision attributes */
+ /* returns number of rules */
+
+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 */
+
+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 */
+
+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 */
+
+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 */
+
+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 */
Property changes on: grass-addons/grass6/raster/r.roughset/rule2.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.roughset/rules_extr.c
===================================================================
--- grass-addons/grass6/raster/r.roughset/rules_extr.c 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.roughset/rules_extr.c 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,489 +1,489 @@
-
-/****************************************************************************
- *
- * MODULE: r.roughset
- * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
- * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
- * Rough Set Library (RSL) ver. 2 original develop:
- * M.Gawrys - J.Sienkiewicz
- *
- * PURPOSE: Geographics rough set analisys and knowledge discovery
- *
- * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
-/************************************************************************
-** EXTRACT RULE FROM GEOGRAPHICS THEMES (Based on Rough Set Library
-** written by M.Gawrys J.Sienkiewiczbrary )
-**
-** The RSL defines three types to be used in applications:
-** setA - set of attributes,
-** setO - set of objects and
-** SYSTEM - information system descriptor.
-
-** The descriptor contains pointers to the information system data matrices:
-** - MATRIX A, is the attribute-value table.
-** - MATRIX D, is the discernibility matrix
-** - MATRIX X, is called a reduced discernibility matrix.
-
-/***********************************************************************/
-
-#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);
-
-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 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);
-
-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)
-{
- 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();
-
- 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);
-
- /**************************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);
- }
-
- 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 */
-
- 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);
- }
- }
- 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);
- }
- }
- 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;
- }
-
-
- 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);
-}
-
-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 */
-
- /* 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, " ");
-
- /************** 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);
- }
-
- /************** 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); */
-
- fprintf(fp, "NAME: %s\nATTRIBUTES: %d\nOBJECTS: %d", file_out_sys,
- nattribute + 1, nobject);
-
- /************** close all and exit ***********/
-
- 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 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 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;
-}
-
-int LowRules(value_type ** rules, setA P, setA Q, int mat)
-{
- return ApprRules(rules, P, Q, LOWER, mat);
-}
-
-int UppRules(value_type ** rules, setA P, setA Q, int mat)
-{
- return ApprRules(rules, P, Q, UPPER, mat);
-}
-
-int NormRules(value_type ** rules, setA P, setA Q, int mat)
-{
- return ApprRules(rules, P, Q, NORMAL, mat);
-}
-
-
-/* dom 07 dic 2008 07:04:58 CET */
+
+/****************************************************************************
+ *
+ * MODULE: r.roughset
+ * AUTHOR(S): GRASS module authors ad Rough Set Library (RSL) maintain:
+ * G.Massei (g_massa at libero.it)-A.Boggia (boggia at unipg.it)
+ * Rough Set Library (RSL) ver. 2 original develop:
+ * M.Gawrys - J.Sienkiewicz
+ *
+ * PURPOSE: Geographics rough set analisys and knowledge discovery
+ *
+ * COPYRIGHT: (C) A.Boggia - G.Massei (2008)
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+/************************************************************************
+** EXTRACT RULE FROM GEOGRAPHICS THEMES (Based on Rough Set Library
+** written by M.Gawrys J.Sienkiewiczbrary )
+**
+** The RSL defines three types to be used in applications:
+** setA - set of attributes,
+** setO - set of objects and
+** SYSTEM - information system descriptor.
+
+** The descriptor contains pointers to the information system data matrices:
+** - MATRIX A, is the attribute-value table.
+** - MATRIX D, is the discernibility matrix
+** - MATRIX X, is called a reduced discernibility matrix.
+
+/***********************************************************************/
+
+#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);
+
+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 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);
+
+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)
+{
+ 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();
+
+ 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);
+
+ /**************************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);
+ }
+
+ 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 */
+
+ 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);
+ }
+ }
+ 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);
+ }
+ }
+ 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;
+ }
+
+
+ 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);
+}
+
+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 */
+
+ /* 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, " ");
+
+ /************** 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);
+ }
+
+ /************** 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); */
+
+ fprintf(fp, "NAME: %s\nATTRIBUTES: %d\nOBJECTS: %d", file_out_sys,
+ nattribute + 1, nobject);
+
+ /************** close all and exit ***********/
+
+ 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 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 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;
+}
+
+int LowRules(value_type ** rules, setA P, setA Q, int mat)
+{
+ return ApprRules(rules, P, Q, LOWER, mat);
+}
+
+int UppRules(value_type ** rules, setA P, setA Q, int mat)
+{
+ return ApprRules(rules, P, Q, UPPER, mat);
+}
+
+int NormRules(value_type ** rules, setA P, setA Q, int mat)
+{
+ return ApprRules(rules, P, Q, NORMAL, mat);
+}
+
+
+/* dom 07 dic 2008 07:04:58 CET */
Property changes on: grass-addons/grass6/raster/r.roughset/rules_extr.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass-addons/grass6/raster/r.to.drsa/description.html
===================================================================
--- grass-addons/grass6/raster/r.to.drsa/description.html 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass6/raster/r.to.drsa/description.html 2012-12-04 18:08:17 UTC (rev 54184)
@@ -1,35 +1,35 @@
-<h2>DESCRIPTION</h2>
-
-The <em>r.ro.drsa</em> module will export raster maps as a *isf file
-readable in jMAF, JAMM or 4eMka2 sofware <a href="http://idss.cs.put.poznan.pl/">Laboratory of Intelligent Decision Support Systems - Poznan University.</a>
-<p>
-<em>(GRASS python Script)</em>
-
-<h2>NOTES</h2>
-
-
-<p>
-This module, as all GRASS raster modules, will export cells based on the
-current region settings. See the <em>g.region</em> module for details.
-
-
-<h2>TODO</h2>
-
-
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.roughset.html">r.roughset</a>,
-<a href="r.mcda.regime.html">r.mcda.regime</a>,
-<a href="r.mcda.fuzzy.html">r.mcda.fuzzy</a>
-<a href="r.mcda.electre.html">r.mcda.electre</a>,
-<a href="r.in.drsa.html">r.in.drsa</a>
-</em>
-
-<h2>AUTHORS</h2>
-Antonio Boggia - Gianluca Massei<br>
-Department of Economics and Appraisal - University of Perugia - Italy
-<p>
-<i>Last changed: $Date: 2012-09-12 22:32:08 +0200 (mer, 12 set 2012) $</i>
+<h2>DESCRIPTION</h2>
+
+The <em>r.ro.drsa</em> module will export raster maps as a *isf file
+readable in jMAF, JAMM or 4eMka2 sofware <a href="http://idss.cs.put.poznan.pl/">Laboratory of Intelligent Decision Support Systems - Poznan University.</a>
+<p>
+<em>(GRASS python Script)</em>
+
+<h2>NOTES</h2>
+
+
+<p>
+This module, as all GRASS raster modules, will export cells based on the
+current region settings. See the <em>g.region</em> module for details.
+
+
+<h2>TODO</h2>
+
+
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.roughset.html">r.roughset</a>,
+<a href="r.mcda.regime.html">r.mcda.regime</a>,
+<a href="r.mcda.fuzzy.html">r.mcda.fuzzy</a>
+<a href="r.mcda.electre.html">r.mcda.electre</a>,
+<a href="r.in.drsa.html">r.in.drsa</a>
+</em>
+
+<h2>AUTHORS</h2>
+Antonio Boggia - Gianluca Massei<br>
+Department of Economics and Appraisal - University of Perugia - Italy
+<p>
+<i>Last changed: $Date$</i>
Property changes on: grass-addons/grass6/raster/r.to.drsa/description.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Property changes on: grass-addons/grass6/raster/r.to.drsa/r.to.drsa.py
___________________________________________________________________
Added: svn:mime-type
+ text/x-python
Added: svn:eol-style
+ native
Modified: grass-addons/grass7/imagery/i.rotate/i.rotate.html
===================================================================
--- grass-addons/grass7/imagery/i.rotate/i.rotate.html 2012-12-04 18:05:00 UTC (rev 54183)
+++ grass-addons/grass7/imagery/i.rotate/i.rotate.html 2012-12-04 18:08:17 UTC (rev 54184)
@@ -21,4 +21,4 @@
<p>
-<i>Last changed: $Date: 2012-11-20 07:16:20 +1000 $</i>
+<i>Last changed: $Date$</i>
Property changes on: grass-addons/grass7/imagery/i.rotate/i.rotate.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Property changes on: grass-addons/grass7/imagery/i.rotate/main.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list