[GRASS-SVN] r33802 - in grass-addons/raster: . mcda mcda/r.mcda.electre mcda/r.mcda.fuzzy mcda/r.mcda.regime mcda/r.roughset

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 10 06:38:39 EDT 2008


Author: gianluca
Date: 2008-10-10 06:38:38 -0400 (Fri, 10 Oct 2008)
New Revision: 33802

Added:
   grass-addons/raster/mcda/
   grass-addons/raster/mcda/Makefile
   grass-addons/raster/mcda/README.txt
   grass-addons/raster/mcda/r.mcda.electre/
   grass-addons/raster/mcda/r.mcda.electre/COMMENTS
   grass-addons/raster/mcda/r.mcda.electre/Makefile
   grass-addons/raster/mcda/r.mcda.electre/dominance.c
   grass-addons/raster/mcda/r.mcda.electre/local_proto.h
   grass-addons/raster/mcda/r.mcda.electre/main.c
   grass-addons/raster/mcda/r.mcda.electre/r.mcda.electre.html
   grass-addons/raster/mcda/r.mcda.electre/r.mcda.electre.tmp.html
   grass-addons/raster/mcda/r.mcda.fuzzy/
   grass-addons/raster/mcda/r.mcda.fuzzy/COMMENTS
   grass-addons/raster/mcda/r.mcda.fuzzy/Makefile
   grass-addons/raster/mcda/r.mcda.fuzzy/fuzzy.c
   grass-addons/raster/mcda/r.mcda.fuzzy/local_proto.h
   grass-addons/raster/mcda/r.mcda.fuzzy/main.c
   grass-addons/raster/mcda/r.mcda.fuzzy/r.mcda.fuzzy.html
   grass-addons/raster/mcda/r.mcda.regime/
   grass-addons/raster/mcda/r.mcda.regime/COMMENTS
   grass-addons/raster/mcda/r.mcda.regime/Makefile
   grass-addons/raster/mcda/r.mcda.regime/local_proto.h
   grass-addons/raster/mcda/r.mcda.regime/main.c
   grass-addons/raster/mcda/r.mcda.regime/r.mcda.regime.html
   grass-addons/raster/mcda/r.mcda.regime/r.mcda.regime.tmp.html
   grass-addons/raster/mcda/r.mcda.regime/regime.c
   grass-addons/raster/mcda/r.roughset/
   grass-addons/raster/mcda/r.roughset/Makefile
   grass-addons/raster/mcda/r.roughset/README.txt
   grass-addons/raster/mcda/r.roughset/VERSIONE.txt
   grass-addons/raster/mcda/r.roughset/description.html
   grass-addons/raster/mcda/r.roughset/localproto.h
   grass-addons/raster/mcda/r.roughset/main.c
   grass-addons/raster/mcda/r.roughset/r.roughset.tmp.html
   grass-addons/raster/mcda/r.roughset/raccess.c
   grass-addons/raster/mcda/r.roughset/raccess.h
   grass-addons/raster/mcda/r.roughset/rbasic.c
   grass-addons/raster/mcda/r.roughset/rbasic.h
   grass-addons/raster/mcda/r.roughset/rclass.c
   grass-addons/raster/mcda/r.roughset/rclass.h
   grass-addons/raster/mcda/r.roughset/rcore.c
   grass-addons/raster/mcda/r.roughset/rcore.h
   grass-addons/raster/mcda/r.roughset/reduct1.c
   grass-addons/raster/mcda/r.roughset/reduct1.h
   grass-addons/raster/mcda/r.roughset/reduct2.c
   grass-addons/raster/mcda/r.roughset/reduct2.h
   grass-addons/raster/mcda/r.roughset/rerror.h
   grass-addons/raster/mcda/r.roughset/rough.h
   grass-addons/raster/mcda/r.roughset/rset.c
   grass-addons/raster/mcda/r.roughset/rset.h
   grass-addons/raster/mcda/r.roughset/rsystem.c
   grass-addons/raster/mcda/r.roughset/rsystem.h
   grass-addons/raster/mcda/r.roughset/rule1.c
   grass-addons/raster/mcda/r.roughset/rule1.h
   grass-addons/raster/mcda/r.roughset/rule2.c
   grass-addons/raster/mcda/r.roughset/rule2.h
   grass-addons/raster/mcda/r.roughset/rules_extr.c
Log:
geographics multi-criteria analysis and discovery knowledg

Added: grass-addons/raster/mcda/Makefile
===================================================================
--- grass-addons/raster/mcda/Makefile	                        (rev 0)
+++ grass-addons/raster/mcda/Makefile	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,15 @@
+
+MODULE_TOPDIR = ../..
+
+SUBDIRS = \
+	r.mcda.electre \
+	r.mcda.fuzzy \
+	r.mcda.regime \
+	r.roughset 
+	
+
+include $(MODULE_TOPDIR)/include/Make/Dir.make
+
+default: parsubdirs
+
+clean: cleansubdirs

Added: grass-addons/raster/mcda/README.txt
===================================================================
--- grass-addons/raster/mcda/README.txt	                        (rev 0)
+++ grass-addons/raster/mcda/README.txt	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,10 @@
+release 24 august 2008
+
+r.mcda package:
+->r.mcda.electre
+->r.mcda.fuzzy
+->r.mcda.regime
+->r.roughset
+
+gianluca massei (g_massa at libero.it)
+

Added: grass-addons/raster/mcda/r.mcda.electre/COMMENTS
===================================================================
--- grass-addons/raster/mcda/r.mcda.electre/COMMENTS	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.electre/COMMENTS	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,211 @@
+From: Glynn Clements <glynn.clements at virgin.net>
+Date: Tue, 5 Mar 2002 16:44:33 +0000
+To: Markus Neteler <neteler at itc.it>
+Subject: Re: Question on raster programming
+
+
+Markus Neteler wrote:
+
+> may I ask you for some assistance for a simple example on
+> GRASS raster programming? 
+> I would like to have r.example as reference for raster
+> programming. The module will do nothing exciting but show
+> how to deal with the different precisions.
+> 
+> the line in question is the inner col-loop, where I
+> copy the cell values from the old to the new map.
+> It does not compile due to the variable definition.
+> 
+> In old modules I have seen ugly things to deal with
+> INT, FCELL and DCELL (lots of cases etc). Probably it
+> is much more simple using the
+> 
+> void *inrast;
+> 
+> definition on top. But then, I don't understand to access
+> it... Yes, programming newbie question. Perhaps you have the
+> patience to help me. I have several older modules in the queue
+> which I would like to release after an update. Before hacking
+> in lots of case statements, I prefer to learn the up-to-date
+> method.
+
+If you want to handle multiple data types, you generally[1] have to
+use a switch statement.
+
+[1] If you are only copying values, you can use other methods (e.g. 
+memcpy), but if you wish to actually process the cell values, they
+need to be stored in a variable of the appropriate type.
+
+Suppose you wanted the equivalent of:
+
+	r.mapcalc 'out = f(in)'
+
+The main loop would look something like:
+
+	extern CELL  f_c(CELL);
+	extern FCELL f_f(FCELL);
+	extern DCELL f_d(DCELL);
+
+	...
+
+	for (col=0; col < ncols; col++)
+	{
+		CELL c;
+		FCELL f;
+		DCELL d;
+
+		switch (data_type)
+		{
+		case CELL_TYPE:
+			c = ((CELL *) inrast)[col];
+			c = f_c(c);
+			((CELL *) outrast)[col] = c;
+			break;
+		case FCELL_TYPE:
+			f = ((FCELL *) inrast)[col];
+			f = f_f(f);
+			((FCELL *) outrast)[col] = f;
+			break;
+		case DCELL_TYPE:
+			d = ((DCELL *) inrast)[col];
+			d = f_d(d);
+			((DCELL *) outrast)[col] = d;
+			break;
+		}
+	}
+
+In the most extreme case, you might have nested switch statements to
+deal with all of the different combinations of input/output types.
+
+If it isn't important that the operation is done at the map's native
+precision, a simpler approach is to just use DCELL values and let the
+G_{get,put}_*_row functions handle the conversion, e.g.
+
+        DCELL f_d(DCELL x)
+        {
+           /* some function */     
+           return x;
+        }
+
+	extern DCELL f_d(DCELL);
+
+	...
+
+	DCELL *inrast = G_allocate_d_raster_buf();
+	DCELL *outrast = G_allocate_d_raster_buf();
+
+	for (row = 0; row < nrows; row++)
+	{
+		if (G_get_d_raster_row (infd, inrast, row) < 0)
+			G_fatal_error(...);
+		
+		for (col=0; col < ncols; col++)
+		 	outrast[col] = f_d(inrast[col]);
+
+		if (G_put_d_raster_row (outfd, outrast) < 0)
+			G_fatal_error(...);
+	}
+
+One other comment about the example: it isn't necessary to use
+sprintf() to format error messages; G_fatal_error() takes a format
+string and arguments, e.g.
+
+	G_fatal_error("cell file [%s] not found", name);
+
+-- 
+Glynn Clements <glynn.clements at virgin.net>
+
+From: Glynn Clements <glynn.clements at virgin.net>
+Date: Thu, 7 Mar 2002 16:51:43 +0000
+To: Markus Neteler <neteler at itc.it>
+Subject: Re: Question on raster programming
+
+
+Markus Neteler wrote:
+
+> What do you think about the macro method implemented in
+> r.sunmask (src/raster/r.sunmask/)? Is that a good
+> or possibly slowing down the module for FCELL and DCELL
+> (in fact it's incredible slow, just for INT DEMs it is acceptable).
+
+In the case of r.sunmask, the raster_value() macro/function is
+pointless. The data is always converted to DCELL before being used;
+the code should just allocate DCELL buffers and read the data with
+G_get_d_raster_row().
+
+As for speed, I wouldn't have thought that type-handling logic would
+be significant compared to the amount of work that's done in the
+various G_get_*_row() functions.
+
+Most code should probably just work with DCELL values, and let libgis
+perform the conversions, unless the code is only applicable to CELL
+values, or it handles CELL values differently.
+
+-- 
+Glynn Clements <glynn.clements at virgin.net>
+
+
+Markus Neteler wrote:
+
+> sorry to bother you again. I am now continuing to write
+> r.example (which just copies a file) to have an example
+> on raster programming. Maybe you recall our conversation on
+> that some time ago (find it attached as well).
+> 
+> A remaining question is how to define this:
+> 
+>         extern CELL  f_c(CELL);
+>         extern FCELL f_f(FCELL);
+>         extern DCELL f_d(DCELL);
+> 
+> f_c, f_f, f_d
+> 
+> Sorry for this question, but I am clueless here.
+
+For copying a file, these would just be identity functions, e.g.
+
+	CELL f_c(CELL x)
+	{
+		return x;
+	}
+
+Actually, there aren't many things which you could do within that
+framework. For most practical applications, a cell in the output map
+would depend upon more than just the corresponding cell in a single
+input map. You would typically have multiple input maps, and/or use
+the values of multiple cells in computing the value of each output
+cell.
+
+Some other points:
+
+1. Copying input parameters into a buffer, i.e.:
+
+	strcpy (name, option.input->answer);
+	strcpy (result, option.output->answer);
+
+is usually unnecessary. Furthermore, it's something which should be
+discouraged, due to the usual problems with fixed-size buffers.
+
+2. Pre-formatting error/warning messages, e.g.:
+
+        if (mapset == NULL)
+        {
+                char buf[200];
+                sprintf (buf, "cell file [%s] not found", name);
+                G_fatal_error (buf);
+        }
+
+is unnecessary, as G_fatal_error() and G_warning() already do this,
+e.g.
+
+        if (!mapset)
+                G_fatal_error("cell file [%s] not found", name);
+
+3. Ideally, all abnormal exits would be via G_fatal_error(), rather
+than calling exit() directly.
+
+4. The value passed to exit() should be non-negative. exit(-1) is just
+a confusing way of writing exit(255).
+
+-- 
+Glynn Clements <glynn.clements at virgin.net>


Property changes on: grass-addons/raster/mcda/r.mcda.electre/COMMENTS
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/raster/mcda/r.mcda.electre/Makefile
===================================================================
--- grass-addons/raster/mcda/r.mcda.electre/Makefile	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.electre/Makefile	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,12 @@
+# fix this relative to include/
+# or use absolute path to the GRASS source code
+MODULE_TOPDIR = ../../..
+
+PGM = r.mcda.electre
+
+LIBES= $(GISLIB) $(GMATHLIB)
+DEPENDENCIES = $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd


Property changes on: grass-addons/raster/mcda/r.mcda.electre/Makefile
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/raster/mcda/r.mcda.electre/dominance.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.electre/dominance.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.electre/dominance.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,103 @@
+#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 **concordance_mat, double **discordance_mat, 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 **concordance_mat, double **discordance_mat, 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;
+	
+	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++)
+					{
+					for(i=0;i<ncriteria;i++)
+						{
+						if(decision_vol[row1][col1][i]>=decision_vol[row2][col2][i])
+							{concordance_mat[k][j]=concordance_mat[k][j]+weight_vect[i];}
+							
+						if((decision_vol[row1][col1][i]-decision_vol[row2][col2][i])>concordance_mat[k][j])
+							{discordance_mat[k][j]=(decision_vol[row2][col2][i]-decision_vol[row1][col1][i]);}
+						}
+					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++)
+			{
+			row_sum_conc=col_sum_conc=row_sum_disc=col_sum_disc=0;
+			 /* da un valore incrementale ad ogni ciclo per progredire nella concordance_mat */
+			for(i=0;i<nrows*ncols;i++)
+				{
+				/*concordance index */
+				row_sum_conc=row_sum_conc+concordance_mat[cont][i];
+				col_sum_conc=row_sum_conc+concordance_mat[i][cont];
+				/*discordance index */
+				row_sum_disc=row_sum_disc+discordance_mat[cont][i];
+				col_sum_disc=row_sum_disc+discordance_mat[i][cont];
+				}
+			cont++;
+			decision_vol[row1][col1][ncriteria]=row_sum_conc-col_sum_conc;/*fill matrix with concordance index for each DCELL*/
+			decision_vol[row1][col1][ncriteria+1]=row_sum_disc-col_sum_disc;/*fill matrix with discordance index for each DCELL*/
+			}
+		}
+}
+

Added: grass-addons/raster/mcda/r.mcda.electre/local_proto.h
===================================================================
--- grass-addons/raster/mcda/r.mcda.electre/local_proto.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.electre/local_proto.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +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 */
+};

Added: grass-addons/raster/mcda/r.mcda.electre/main.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.electre/main.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.electre/main.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,239 @@
+/****************************************************************************
+ *
+ * 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, **concordance_mat, **discordance_mat, ***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();
+
+	concordance_mat=G_alloc_matrix((nrows*ncols),(nrows*ncols)); /* dinamicaly allocation memory and set value=0 */
+	discordance_mat=G_alloc_matrix((nrows*ncols),(nrows*ncols));
+
+	/*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);
+
+				}
+			}
+		}
+
+	G_message("build matrix: %s",G_date());
+
+	build_dominance_matrix(nrows,ncols,ncriteria,weight_vect,concordance_mat,discordance_mat, 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_matrix(concordance_mat);
+	G_free_matrix(discordance_mat);
+	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);
+}
+
+

Added: grass-addons/raster/mcda/r.mcda.electre/r.mcda.electre.html
===================================================================
--- grass-addons/raster/mcda/r.mcda.electre/r.mcda.electre.html	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.electre/r.mcda.electre.html	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head><title>r.mcda.electre</title></head>
+<body>
+<h2 style="text-align: justify;">DESCRIPTION</h2>
+<div style="text-align: justify;"><span style="font-weight: bold;">r.mcda.electre </span>implementa
+l'algoritmo di analisi multi-criterio "ELECTRE" in ambiente GRASS GIS e
+costituisce uno dei tools disponibili nella suite r.mcda.<br>
+Richiede
+in input la lista dei raster che rappresentano i &nbsp;criteri da
+utilizzare nell'analisi multicriterio e il vettore dei pesi da inserire&nbsp; nello
+<span style="font-style: italic;">stesso ordine</span> di immissione di quello dei criteri. <br>
+Ogni singola i-esima cella della region di GRASS è considerata come una
+delle possibili alternative da valutare ed è descritta dai valori
+assunti per la stessa cella dai raster indicati come criteri.<br>L'output
+è costituito da due file di cui uno rappresenta la distribuzione
+spaziale dell'indice di concordanza ed uno quella dell'indice di
+discordanza. La localizzazione ottimale è quella che contemporaneamente
+ha ilmassimo valore di concordanza ed il minimo valore di discordanza
+rispetto ai criteri inseriti<br>
+<br>
+</div>
+<h2 style="text-align: justify;">NOTES</h2>
+<div style="text-align: justify;">Il modulo non opera
+alcun tipo di standardizzazione sui raster dei criteri che, pertanto, devono
+essere preventivemente preparati utilizzando, ad esempio, r.mapcalc. Il
+vettore dei pesi, invece, viene normalizzato sempre ad 1, quindi se
+l'immissione è già standardizzata il valore di ponderazione rimane
+inalterato, altrimente viene eseguito il calcolo che riporta la somma
+dei pesi ad un valore pari a 1.
+</div><h2 style="text-align: justify;">REFERENCE</h2>
+<div style="text-align: justify;">Roy, B. (1971) Problem and methods with multiple objective funtions Mathemathical programming 1, 239-266.<br>Roy, B. (1990): The outranking approach and the foundations of Electre methods , Document du LAMSADE, Paris.<br>Janssen R. (1994) - Multiobjective decision support for enviromental management, Kluwe Accademic Publishers.<br><br>GRASS Development Team (2008)<br><br></div><h2 style="text-align: justify;">SEE ALSO</h2>
+<div style="text-align: justify;"><em>r.mcda.regime,
+r.mcda.fuzzy, r.roughet, r.mapcalc</em><br>
+<em></em><em></em></div>
+<h2 style="text-align: justify;">AUTHORS</h2>
+<div style="text-align: justify;">Gianluca Massei - Antonio Boggia - Dipartimento di Scienze Economico Estimative e degli Alimenti - Università di Perugia - Italy
+</div>
+
+<p><i><br>
+</i></p>
+</body></html>
\ No newline at end of file

Added: grass-addons/raster/mcda/r.mcda.electre/r.mcda.electre.tmp.html
===================================================================
--- grass-addons/raster/mcda/r.mcda.electre/r.mcda.electre.tmp.html	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.electre/r.mcda.electre.tmp.html	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,44 @@
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head><title>r.mcda.electre</title></head>
+<body>
+<h2 style="text-align: justify;">DESCRIPTION</h2>
+<div style="text-align: justify;"><span style="font-weight: bold;">r.mcda.electre </span>implementa
+l'algoritmo di analisi multi-criterio "ELECTRE" in ambiente GRASS GIS e
+costituisce uno dei tools disponibili nella suite r.mcda.<br>
+Richiede
+in input la lista dei raster che rappresentano i &nbsp;criteri da
+utilizzare nell'analisi multicriterio e il vettore dei pesi da inserire&nbsp; nello
+<span style="font-style: italic;">stesso ordine</span> di immissione di quello dei criteri. <br>
+Ogni singola i-esima cella della region di GRASS è considerata come una
+delle possibili alternative da valutare ed è descritta dai valori
+assunti per la stessa cella dai raster indicati come criteri.<br>L'output
+è costituito da due file di cui uno rappresenta la distribuzione
+spaziale dell'indice di concordanza ed uno quella dell'indice di
+discordanza. La localizzazione ottimale è quella che contemporaneamente
+ha ilmassimo valore di concordanza ed il minimo valore di discordanza
+rispetto ai criteri inseriti<br>
+<br>
+</div>
+<h2 style="text-align: justify;">NOTES</h2>
+<div style="text-align: justify;">Il modulo non opera
+alcun tipo di standardizzazione sui raster dei criteri che, pertanto, devono
+essere preventivemente preparati utilizzando, ad esempio, r.mapcalc. Il
+vettore dei pesi, invece, viene normalizzato sempre ad 1, quindi se
+l'immissione è già standardizzata il valore di ponderazione rimane
+inalterato, altrimente viene eseguito il calcolo che riporta la somma
+dei pesi ad un valore pari a 1.
+</div><h2 style="text-align: justify;">REFERENCE</h2>
+<div style="text-align: justify;">Yager R. (1977) -
+Multiple objective decision making using fuzzy set, Internationale
+Journal of Man-Machine Studies, 12, 299-322<br><br>GRASS Development Team (2008)<br><br></div><h2 style="text-align: justify;">SEE ALSO</h2>
+<div style="text-align: justify;"><em>r.mcda.regime,
+r.mcda.fuzzy, r.roughet, r.mapcalc</em><br>
+<em></em><em></em></div>
+<h2 style="text-align: justify;">AUTHORS</h2>
+<div style="text-align: justify;">Gianluca Massei - Antonio Boggia - Dipartimento di Scienze Economico Estimative e degli Alimenti - Università di Perugia - Italy
+</div>
+
+<p><i><br>
+</i></p>
+</body></html>
\ No newline at end of file

Added: grass-addons/raster/mcda/r.mcda.fuzzy/COMMENTS
===================================================================
--- grass-addons/raster/mcda/r.mcda.fuzzy/COMMENTS	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.fuzzy/COMMENTS	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,211 @@
+From: Glynn Clements <glynn.clements at virgin.net>
+Date: Tue, 5 Mar 2002 16:44:33 +0000
+To: Markus Neteler <neteler at itc.it>
+Subject: Re: Question on raster programming
+
+
+Markus Neteler wrote:
+
+> may I ask you for some assistance for a simple example on
+> GRASS raster programming? 
+> I would like to have r.example as reference for raster
+> programming. The module will do nothing exciting but show
+> how to deal with the different precisions.
+> 
+> the line in question is the inner col-loop, where I
+> copy the cell values from the old to the new map.
+> It does not compile due to the variable definition.
+> 
+> In old modules I have seen ugly things to deal with
+> INT, FCELL and DCELL (lots of cases etc). Probably it
+> is much more simple using the
+> 
+> void *inrast;
+> 
+> definition on top. But then, I don't understand to access
+> it... Yes, programming newbie question. Perhaps you have the
+> patience to help me. I have several older modules in the queue
+> which I would like to release after an update. Before hacking
+> in lots of case statements, I prefer to learn the up-to-date
+> method.
+
+If you want to handle multiple data types, you generally[1] have to
+use a switch statement.
+
+[1] If you are only copying values, you can use other methods (e.g. 
+memcpy), but if you wish to actually process the cell values, they
+need to be stored in a variable of the appropriate type.
+
+Suppose you wanted the equivalent of:
+
+	r.mapcalc 'out = f(in)'
+
+The main loop would look something like:
+
+	extern CELL  f_c(CELL);
+	extern FCELL f_f(FCELL);
+	extern DCELL f_d(DCELL);
+
+	...
+
+	for (col=0; col < ncols; col++)
+	{
+		CELL c;
+		FCELL f;
+		DCELL d;
+
+		switch (data_type)
+		{
+		case CELL_TYPE:
+			c = ((CELL *) inrast)[col];
+			c = f_c(c);
+			((CELL *) outrast)[col] = c;
+			break;
+		case FCELL_TYPE:
+			f = ((FCELL *) inrast)[col];
+			f = f_f(f);
+			((FCELL *) outrast)[col] = f;
+			break;
+		case DCELL_TYPE:
+			d = ((DCELL *) inrast)[col];
+			d = f_d(d);
+			((DCELL *) outrast)[col] = d;
+			break;
+		}
+	}
+
+In the most extreme case, you might have nested switch statements to
+deal with all of the different combinations of input/output types.
+
+If it isn't important that the operation is done at the map's native
+precision, a simpler approach is to just use DCELL values and let the
+G_{get,put}_*_row functions handle the conversion, e.g.
+
+        DCELL f_d(DCELL x)
+        {
+           /* some function */     
+           return x;
+        }
+
+	extern DCELL f_d(DCELL);
+
+	...
+
+	DCELL *inrast = G_allocate_d_raster_buf();
+	DCELL *outrast = G_allocate_d_raster_buf();
+
+	for (row = 0; row < nrows; row++)
+	{
+		if (G_get_d_raster_row (infd, inrast, row) < 0)
+			G_fatal_error(...);
+		
+		for (col=0; col < ncols; col++)
+		 	outrast[col] = f_d(inrast[col]);
+
+		if (G_put_d_raster_row (outfd, outrast) < 0)
+			G_fatal_error(...);
+	}
+
+One other comment about the example: it isn't necessary to use
+sprintf() to format error messages; G_fatal_error() takes a format
+string and arguments, e.g.
+
+	G_fatal_error("cell file [%s] not found", name);
+
+-- 
+Glynn Clements <glynn.clements at virgin.net>
+
+From: Glynn Clements <glynn.clements at virgin.net>
+Date: Thu, 7 Mar 2002 16:51:43 +0000
+To: Markus Neteler <neteler at itc.it>
+Subject: Re: Question on raster programming
+
+
+Markus Neteler wrote:
+
+> What do you think about the macro method implemented in
+> r.sunmask (src/raster/r.sunmask/)? Is that a good
+> or possibly slowing down the module for FCELL and DCELL
+> (in fact it's incredible slow, just for INT DEMs it is acceptable).
+
+In the case of r.sunmask, the raster_value() macro/function is
+pointless. The data is always converted to DCELL before being used;
+the code should just allocate DCELL buffers and read the data with
+G_get_d_raster_row().
+
+As for speed, I wouldn't have thought that type-handling logic would
+be significant compared to the amount of work that's done in the
+various G_get_*_row() functions.
+
+Most code should probably just work with DCELL values, and let libgis
+perform the conversions, unless the code is only applicable to CELL
+values, or it handles CELL values differently.
+
+-- 
+Glynn Clements <glynn.clements at virgin.net>
+
+
+Markus Neteler wrote:
+
+> sorry to bother you again. I am now continuing to write
+> r.example (which just copies a file) to have an example
+> on raster programming. Maybe you recall our conversation on
+> that some time ago (find it attached as well).
+> 
+> A remaining question is how to define this:
+> 
+>         extern CELL  f_c(CELL);
+>         extern FCELL f_f(FCELL);
+>         extern DCELL f_d(DCELL);
+> 
+> f_c, f_f, f_d
+> 
+> Sorry for this question, but I am clueless here.
+
+For copying a file, these would just be identity functions, e.g.
+
+	CELL f_c(CELL x)
+	{
+		return x;
+	}
+
+Actually, there aren't many things which you could do within that
+framework. For most practical applications, a cell in the output map
+would depend upon more than just the corresponding cell in a single
+input map. You would typically have multiple input maps, and/or use
+the values of multiple cells in computing the value of each output
+cell.
+
+Some other points:
+
+1. Copying input parameters into a buffer, i.e.:
+
+	strcpy (name, option.input->answer);
+	strcpy (result, option.output->answer);
+
+is usually unnecessary. Furthermore, it's something which should be
+discouraged, due to the usual problems with fixed-size buffers.
+
+2. Pre-formatting error/warning messages, e.g.:
+
+        if (mapset == NULL)
+        {
+                char buf[200];
+                sprintf (buf, "cell file [%s] not found", name);
+                G_fatal_error (buf);
+        }
+
+is unnecessary, as G_fatal_error() and G_warning() already do this,
+e.g.
+
+        if (!mapset)
+                G_fatal_error("cell file [%s] not found", name);
+
+3. Ideally, all abnormal exits would be via G_fatal_error(), rather
+than calling exit() directly.
+
+4. The value passed to exit() should be non-negative. exit(-1) is just
+a confusing way of writing exit(255).
+
+-- 
+Glynn Clements <glynn.clements at virgin.net>


Property changes on: grass-addons/raster/mcda/r.mcda.fuzzy/COMMENTS
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/raster/mcda/r.mcda.fuzzy/Makefile
===================================================================
--- grass-addons/raster/mcda/r.mcda.fuzzy/Makefile	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.fuzzy/Makefile	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,12 @@
+# fix this relative to include/
+# or use absolute path to the GRASS source code
+MODULE_TOPDIR = ../../..
+
+PGM = r.mcda.fuzzy
+
+LIBES= $(GISLIB) $(GMATHLIB)
+DEPENDENCIES = $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd


Property changes on: grass-addons/raster/mcda/r.mcda.fuzzy/Makefile
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/raster/mcda/r.mcda.fuzzy/fuzzy.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.fuzzy/fuzzy.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.fuzzy/fuzzy.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,119 @@
+#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;
+			}
+		}
+	
+}
+

Added: grass-addons/raster/mcda/r.mcda.fuzzy/local_proto.h
===================================================================
--- grass-addons/raster/mcda/r.mcda.fuzzy/local_proto.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.fuzzy/local_proto.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +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 */
+};

Added: grass-addons/raster/mcda/r.mcda.fuzzy/main.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.fuzzy/main.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.fuzzy/main.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,256 @@
+/****************************************************************************
+ *
+ * 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);
+}
+
+

Added: grass-addons/raster/mcda/r.mcda.fuzzy/r.mcda.fuzzy.html
===================================================================
--- grass-addons/raster/mcda/r.mcda.fuzzy/r.mcda.fuzzy.html	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.fuzzy/r.mcda.fuzzy.html	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,45 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head><title>r.mcda.fuzzy</title></head>
+
+<body>
+<h2 style="text-align: justify;">DESCRIPTION</h2>
+<div style="text-align: justify;"><span style="font-weight: bold;">r.mcda.fuzzy </span>implementa
+l'algoritmo di analisi multi-criterio "fuzzy" proposta da Yager R. in ambiente GRASS GIS e
+costituisce uno dei tools disponibili nella suite r.mcda.<br>
+Richiede
+in input la lista dei raster che rappresentano i &nbsp;criteri da
+utilizzare nell'analisi multicriterio e il vettore dei modificatori linguistici da inserire nello
+<span style="font-style: italic;">stesso ordine</span> di immissione di quello dei criteri. <br>
+Ogni singola i-esima cella della region di GRASS è considerata come una
+delle possibili alternative da valutare ed è descritta dai valori
+assunti per la stessa cella dai raster indicati come criteri.<br>Il
+modulo restituisce tre differenti file, uno derivante dall'applicazione
+del criterio di intersezione, uno di unione ed uno di "ordered weighted
+averaging" (OWA).<br>
+<br>
+</div>
+<h2 style="text-align: justify;">NOTES</h2>
+<div style="text-align: justify;">Il modulo non opera
+alcun tipo di standardizzazione sui raster dei criteri, pertanto questi devono
+essere preventivemente preparati utilizzando, ad esempio, r.mapcalc. Il
+vettore dei modificatori linguistici, invece, viene normalizzato sempre ad 1, quindi se
+l'immissione è già standardizzata il relativo valore rimane
+inalterato, altrimente viene eseguito il calcolo che riporta la somma
+dei modificatori ad un valore pari a 1.
+</div>
+<h2 style="text-align: justify;">REFERENCE</h2>
+<div style="text-align: justify;">Yager R. (1977) - Multiple objective decision making using fuzzy set, Internationale Journal of Man-Machine Studies, 12, 299-322<br><br>GRASS Development Team (2008)<br>
+<br>
+</div>
+<h2 style="text-align: justify;">SEE ALSO</h2>
+<div style="text-align: justify;"><em>r.mcda.regime,
+r.mcda.electre, r.roughet, r.mapcalc</em><br>
+<em></em><em></em></div>
+<h2 style="text-align: justify;">AUTHORS</h2>
+<div style="text-align: justify;">
+Janssen R. (1994) - Multiobjective decision support for enviromental management, Kluwe Accademic Publishers.
+</div>
+
+<p><i><br>
+</i></p>
+</body></html>
\ No newline at end of file

Added: grass-addons/raster/mcda/r.mcda.regime/COMMENTS
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/COMMENTS	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.regime/COMMENTS	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,211 @@
+From: Glynn Clements <glynn.clements at virgin.net>
+Date: Tue, 5 Mar 2002 16:44:33 +0000
+To: Markus Neteler <neteler at itc.it>
+Subject: Re: Question on raster programming
+
+
+Markus Neteler wrote:
+
+> may I ask you for some assistance for a simple example on
+> GRASS raster programming? 
+> I would like to have r.example as reference for raster
+> programming. The module will do nothing exciting but show
+> how to deal with the different precisions.
+> 
+> the line in question is the inner col-loop, where I
+> copy the cell values from the old to the new map.
+> It does not compile due to the variable definition.
+> 
+> In old modules I have seen ugly things to deal with
+> INT, FCELL and DCELL (lots of cases etc). Probably it
+> is much more simple using the
+> 
+> void *inrast;
+> 
+> definition on top. But then, I don't understand to access
+> it... Yes, programming newbie question. Perhaps you have the
+> patience to help me. I have several older modules in the queue
+> which I would like to release after an update. Before hacking
+> in lots of case statements, I prefer to learn the up-to-date
+> method.
+
+If you want to handle multiple data types, you generally[1] have to
+use a switch statement.
+
+[1] If you are only copying values, you can use other methods (e.g. 
+memcpy), but if you wish to actually process the cell values, they
+need to be stored in a variable of the appropriate type.
+
+Suppose you wanted the equivalent of:
+
+	r.mapcalc 'out = f(in)'
+
+The main loop would look something like:
+
+	extern CELL  f_c(CELL);
+	extern FCELL f_f(FCELL);
+	extern DCELL f_d(DCELL);
+
+	...
+
+	for (col=0; col < ncols; col++)
+	{
+		CELL c;
+		FCELL f;
+		DCELL d;
+
+		switch (data_type)
+		{
+		case CELL_TYPE:
+			c = ((CELL *) inrast)[col];
+			c = f_c(c);
+			((CELL *) outrast)[col] = c;
+			break;
+		case FCELL_TYPE:
+			f = ((FCELL *) inrast)[col];
+			f = f_f(f);
+			((FCELL *) outrast)[col] = f;
+			break;
+		case DCELL_TYPE:
+			d = ((DCELL *) inrast)[col];
+			d = f_d(d);
+			((DCELL *) outrast)[col] = d;
+			break;
+		}
+	}
+
+In the most extreme case, you might have nested switch statements to
+deal with all of the different combinations of input/output types.
+
+If it isn't important that the operation is done at the map's native
+precision, a simpler approach is to just use DCELL values and let the
+G_{get,put}_*_row functions handle the conversion, e.g.
+
+        DCELL f_d(DCELL x)
+        {
+           /* some function */     
+           return x;
+        }
+
+	extern DCELL f_d(DCELL);
+
+	...
+
+	DCELL *inrast = G_allocate_d_raster_buf();
+	DCELL *outrast = G_allocate_d_raster_buf();
+
+	for (row = 0; row < nrows; row++)
+	{
+		if (G_get_d_raster_row (infd, inrast, row) < 0)
+			G_fatal_error(...);
+		
+		for (col=0; col < ncols; col++)
+		 	outrast[col] = f_d(inrast[col]);
+
+		if (G_put_d_raster_row (outfd, outrast) < 0)
+			G_fatal_error(...);
+	}
+
+One other comment about the example: it isn't necessary to use
+sprintf() to format error messages; G_fatal_error() takes a format
+string and arguments, e.g.
+
+	G_fatal_error("cell file [%s] not found", name);
+
+-- 
+Glynn Clements <glynn.clements at virgin.net>
+
+From: Glynn Clements <glynn.clements at virgin.net>
+Date: Thu, 7 Mar 2002 16:51:43 +0000
+To: Markus Neteler <neteler at itc.it>
+Subject: Re: Question on raster programming
+
+
+Markus Neteler wrote:
+
+> What do you think about the macro method implemented in
+> r.sunmask (src/raster/r.sunmask/)? Is that a good
+> or possibly slowing down the module for FCELL and DCELL
+> (in fact it's incredible slow, just for INT DEMs it is acceptable).
+
+In the case of r.sunmask, the raster_value() macro/function is
+pointless. The data is always converted to DCELL before being used;
+the code should just allocate DCELL buffers and read the data with
+G_get_d_raster_row().
+
+As for speed, I wouldn't have thought that type-handling logic would
+be significant compared to the amount of work that's done in the
+various G_get_*_row() functions.
+
+Most code should probably just work with DCELL values, and let libgis
+perform the conversions, unless the code is only applicable to CELL
+values, or it handles CELL values differently.
+
+-- 
+Glynn Clements <glynn.clements at virgin.net>
+
+
+Markus Neteler wrote:
+
+> sorry to bother you again. I am now continuing to write
+> r.example (which just copies a file) to have an example
+> on raster programming. Maybe you recall our conversation on
+> that some time ago (find it attached as well).
+> 
+> A remaining question is how to define this:
+> 
+>         extern CELL  f_c(CELL);
+>         extern FCELL f_f(FCELL);
+>         extern DCELL f_d(DCELL);
+> 
+> f_c, f_f, f_d
+> 
+> Sorry for this question, but I am clueless here.
+
+For copying a file, these would just be identity functions, e.g.
+
+	CELL f_c(CELL x)
+	{
+		return x;
+	}
+
+Actually, there aren't many things which you could do within that
+framework. For most practical applications, a cell in the output map
+would depend upon more than just the corresponding cell in a single
+input map. You would typically have multiple input maps, and/or use
+the values of multiple cells in computing the value of each output
+cell.
+
+Some other points:
+
+1. Copying input parameters into a buffer, i.e.:
+
+	strcpy (name, option.input->answer);
+	strcpy (result, option.output->answer);
+
+is usually unnecessary. Furthermore, it's something which should be
+discouraged, due to the usual problems with fixed-size buffers.
+
+2. Pre-formatting error/warning messages, e.g.:
+
+        if (mapset == NULL)
+        {
+                char buf[200];
+                sprintf (buf, "cell file [%s] not found", name);
+                G_fatal_error (buf);
+        }
+
+is unnecessary, as G_fatal_error() and G_warning() already do this,
+e.g.
+
+        if (!mapset)
+                G_fatal_error("cell file [%s] not found", name);
+
+3. Ideally, all abnormal exits would be via G_fatal_error(), rather
+than calling exit() directly.
+
+4. The value passed to exit() should be non-negative. exit(-1) is just
+a confusing way of writing exit(255).
+
+-- 
+Glynn Clements <glynn.clements at virgin.net>


Property changes on: grass-addons/raster/mcda/r.mcda.regime/COMMENTS
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/raster/mcda/r.mcda.regime/Makefile
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/Makefile	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.regime/Makefile	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,12 @@
+# fix this relative to include/
+# or use absolute path to the GRASS source code
+MODULE_TOPDIR = ../../..
+
+PGM = r.mcda.regime
+
+LIBES= $(GISLIB) $(GMATHLIB)
+DEPENDENCIES = $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd


Property changes on: grass-addons/raster/mcda/r.mcda.regime/Makefile
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/raster/mcda/r.mcda.regime/local_proto.h
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/local_proto.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.regime/local_proto.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +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 */
+};

Added: grass-addons/raster/mcda/r.mcda.regime/main.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/main.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.regime/main.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,207 @@
+/****************************************************************************
+ *
+ * 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) 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_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, **regime_mat, ***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();
+
+	regime_mat=G_alloc_matrix((nrows*ncols),(nrows*ncols)); /* dinamicaly allocation memory and set value=0 */
+
+	/*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,regime_mat,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_matrix(regime_mat);
+	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);
+}
+
+

Added: grass-addons/raster/mcda/r.mcda.regime/r.mcda.regime.html
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/r.mcda.regime.html	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.regime/r.mcda.regime.html	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head><title>r.mcda.regime</title></head>
+<body>
+<h2 style="text-align: justify;">DESCRIPTION</h2>
+<div style="text-align: justify;"><span style="font-weight: bold;">r.mcda.regime </span>implementa
+l'algoritmo di analisi multi-criterio "REGIME" in ambiente GRASS GIS e
+costituisce uno dei tools disponibili nella suite r.mcda.<br>Richiede
+in input la lista dei raster che rappresentano i &nbsp;criteri da
+utilizzare nell'analisi multicriterio e il vettore dei pesi da inserire nello
+<span style="font-style: italic;">stesso ordine</span> di immissione di quello dei criteri.&nbsp;<br>
+Ogni singola i-esima cella della region di GRASS è considerata come una
+delle possibili alternative da valutare ed è descritta dai valori
+assunti per la stessa cella dai raster indicati come criteri.&nbsp;
+<br>
+</div>
+<h2 style="text-align: justify;">NOTES</h2>
+<div style="text-align: justify;">Il modulo non opera
+alcun tipo di standardizzazione sui raster dei criteri che, pertanto, devono
+essere preventivemente preparati utilizzando, ad esempio, r.mapcalc. Il
+vettore dei pesi, invece, viene normalizzato sempre ad 1, quindi se
+l'immissione è già standardizzata il valore di ponderazione rimane
+inalterato, altrimente viene eseguito il calcolo che riporta la somma
+dei pesi ad un valore pari a 1.
+</div>
+<h2 style="text-align: justify;">REFERENCE</h2>
+<div style="text-align: justify;"><br>
+Janssen R. (1994) - Multiobjective decision support for enviromental management, Kluwe Accademic Publishers.<br><br>GRASS Development Team (2008)<br><br><br>
+</div>
+<h2 style="text-align: justify;">SEE ALSO</h2>
+<div style="text-align: justify;"><em>r.mcda.fuzzy,
+r.mcda.electre, r.roughet, r.mapcalc</em><br>
+<em></em><em></em></div>
+<h2 style="text-align: justify;">AUTHORS</h2>
+<div style="text-align: justify;">Antonio Boggia - Gianluca Massei&nbsp;-
+Dipartimento di Scienze Economico Estimative e degli Alimenti -
+Università di Perugia - Italy
+</div>
+<p style="text-align: justify;">&nbsp;
+</p>
+<p><i><br>
+</i></p>
+</body></html>
\ No newline at end of file

Added: grass-addons/raster/mcda/r.mcda.regime/r.mcda.regime.tmp.html
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/r.mcda.regime.tmp.html	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.regime/r.mcda.regime.tmp.html	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,43 @@
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head><title>r.mcda.regime</title></head>
+<body>
+<h2 style="text-align: justify;">DESCRIPTION</h2>
+<div style="text-align: justify;"><span style="font-weight: bold;">r.mcda.regime </span>implementa
+l'algoritmo di analisi multi-criterio "REGIME" in ambiente GRASS GIS e
+costituisce uno dei tools disponibili nella suite r.mcda.<br>Richiede
+in input la lista dei raster che rappresentano i &nbsp;criteri da
+utilizzare nell'analisi multicriterio e il vettore dei pesi da inserire nello
+<span style="font-style: italic;">stesso ordine</span> di immissione di quello dei criteri.&nbsp;<br>
+Ogni singola i-esima cella della region di GRASS è considerata come una
+delle possibili alternative da valutare ed è descritta dai valori
+assunti per la stessa cella dai raster indicati come criteri.&nbsp;
+<br>
+</div>
+<h2 style="text-align: justify;">NOTES</h2>
+<div style="text-align: justify;">Il modulo non opera
+alcun tipo di standardizzazione sui raster dei criteri che, pertanto, devono
+essere preventivemente preparati utilizzando, ad esempio, r.mapcalc. Il
+vettore dei pesi, invece, viene normalizzato sempre ad 1, quindi se
+l'immissione è già standardizzata il valore di ponderazione rimane
+inalterato, altrimente viene eseguito il calcolo che riporta la somma
+dei pesi ad un valore pari a 1.
+</div>
+<h2 style="text-align: justify;">REFERENCE</h2>
+<div style="text-align: justify;"><br>
+Janssen R. (1994) - Multiobjective decision support for enviromental management, Kluwe Accademic Publishers.<br><br>GRASS Development Team (2008)<br><br><br>
+</div>
+<h2 style="text-align: justify;">SEE ALSO</h2>
+<div style="text-align: justify;"><em>r.mcda.fuzzy,
+r.mcda.electre, r.roughet, r.mapcalc</em><br>
+<em></em><em></em></div>
+<h2 style="text-align: justify;">AUTHORS</h2>
+<div style="text-align: justify;">Antonio Boggia - Gianluca Massei&nbsp;-
+Dipartimento di Scienze Economico Estimative e degli Alimenti -
+Università di Perugia - Italy
+</div>
+<p style="text-align: justify;">&nbsp;
+</p>
+<p><i><br>
+</i></p>
+</body></html>
\ No newline at end of file

Added: grass-addons/raster/mcda/r.mcda.regime/regime.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/regime.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.mcda.regime/regime.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +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 **regime_mat, 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 **regime_mat, double ***decision_vol)
+{		
+	int row1,col1,row2,col2;
+	int i,j,k,cont;
+	double row_sum_regime;
+	
+	k=0;	/* make pairwise comparation and built regime 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++)
+					{
+					for(i=0;i<ncriteria;i++)
+						{
+						if(decision_vol[row1][col1][i]>decision_vol[row2][col2][i])
+							regime_mat[k][j]=(regime_mat[k][j])+(1*weight_vect[i]);
+						else if(decision_vol[row1][col1][i]<decision_vol[row2][col2][i])
+							regime_mat[k][j]=(regime_mat[k][j])+(-1*weight_vect[i]);
+						else
+							regime_mat[k][j]=regime_mat[k][j];	
+						}
+					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;	
+	for(row1=0;row1<nrows;row1++)
+		{
+		G_percent(row1, nrows, 2);
+		for(col1=0;col1<ncols;col1++)
+			{
+			row_sum_regime=0;
+			 /* increase one value in regime_mat for each cicle */
+			for(i=0;i<nrows*ncols;i++)
+				{
+				/*regime index */
+				row_sum_regime=row_sum_regime+regime_mat[cont][i];
+				}
+			cont++;
+			decision_vol[row1][col1][ncriteria]=row_sum_regime/(nrows*ncols-1);/*fill matrix with regime index for each DCELL*/
+			}
+		}
+}
+

Added: grass-addons/raster/mcda/r.roughset/Makefile
===================================================================
--- grass-addons/raster/mcda/r.roughset/Makefile	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/Makefile	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,15 @@
+
+MODULE_TOPDIR = ../..
+
+SUBDIRS = \
+	r.mcda.electre \
+	r.mcda.fuzzy \
+	r.mcda.regime \
+	r.roughset 
+	
+
+include $(MODULE_TOPDIR)/include/Make/Dir.make
+
+default: parsubdirs
+
+clean: cleansubdirs

Added: grass-addons/raster/mcda/r.roughset/README.txt
===================================================================
--- grass-addons/raster/mcda/r.roughset/README.txt	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/README.txt	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,10 @@
+release 24 august 2008
+
+r.mcda package:
+->r.mcda.electre
+->r.mcda.fuzzy
+->r.mcda.regime
+->r.roughset
+
+gianluca massei (g_massa at libero.it)
+

Added: grass-addons/raster/mcda/r.roughset/VERSIONE.txt
===================================================================
--- grass-addons/raster/mcda/r.roughset/VERSIONE.txt	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/VERSIONE.txt	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,3 @@
+versione stabile 18 giugno 2008
+
+autore: gianluca massei
\ No newline at end of file


Property changes on: grass-addons/raster/mcda/r.roughset/VERSIONE.txt
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/raster/mcda/r.roughset/description.html
===================================================================
--- grass-addons/raster/mcda/r.roughset/description.html	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/description.html	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head><title>r.roughset</title></head>
+<body><h2 style="text-align: justify;">NAME</h2><div style="text-align: justify;">
+<em><b>r.roughset</b></em>  - Rough set based geographics knowledg 
+</div><h2 style="text-align: justify;">KEYWORDS</h2><div style="text-align: justify;">
+raster,&nbsp;geographics knowledg<span style="font-weight: bold;"> </span>discovery
+</div><h2 style="text-align: justify;">SYNOPSIS</h2><div style="text-align: justify;">
+<b>r.roughset</b><br>
+<b>r.roughset help</b><br>
+<b>r.roughset</b> <b>attributes</b>=<em>string</em>[,<i>string</i>,...] <b>decision</b>=<em>string</em> <b>strategy</b>=<em>string</em> <b>InfoSys</b>=<em>string</em>  [--<b>verbose</b>]  [--<b>quiet</b>] 
+
+
+</div><h3 style="text-align: justify;">Parameters:</h3><div style="text-align: justify;">
+</div><dl style="text-align: justify;"><dt><b>attributes</b>=<em>string[,<i>string</i>,...]</em></dt><dd>Input geographics attributes in information system</dd><dt><b>decision</b>=<em>string</em></dt><dd>Input geographics decision in information system</dd><dt><b>strategy</b>=<em>string</em></dt><dd>Choose strategy for generating rules</dd><dd>Options: <em>Very fast,Fast,Medium,Best,All,Low,Upp,Normal</em></dd><dt><b>InfoSys</b>=<em>string</em></dt><dd>Output information system file</dd><dd>Default: <em>InfoSys</em></dd></dl><br><br><h2 style="text-align: justify;">DESCRIPTION</h2><div style="text-align: justify;">
+
+<b>r.roughset&nbsp;</b>è un modulo che consente&nbsp;l'applicazione
+della rough set theory [] a database geografici in ambiente GRASS GIS.
+L'input è costituito da due gruppi di dati: <br>1. gli attributi
+geografici che costituiscono il sistema informativo della rough set
+analisys e che si ritiene siano sufficienti a descrivere&nbsp;un
+determinato fenomeno naturale, sociale od economico (<b>attributes</b>=<em>string[,<i>string</i>,...]</em>);<br>2.
+il tematismo decisionale nel quale sono identificate le aree per cui il
+fenomeno da studaire si è presentato con una certa modalità(<b>decision</b>=<em>string</em>);<br>Il
+sistema informativo così generato viene trattato con le funzioni della
+versione 2 delle rough set library (RSL, ver. 2.0)&nbsp; [1993,
+M.Gawrys, J.Sienkiewicz] secondo una delle strategie decisionali
+disponibili (<b>strategy</b>=<em>string</em>).<br><br>L'output è costituito da tre differenti files testuali, con prefisso definito dall'utente nel campo <b>InfoSys</b>=<em>string, </em>e in dettaglio:<br>a.
+file testo strutturato secondo lo standard suggerito dalla rough set
+library, contraddistinto dallo stesso nome indicato nel campo InfoSys
+senza ulteriori suffissi; non riveste particolare interesse per
+l'utente a meno che non si vogliano utilizare le RSL al di fuori
+dall'ambiente GIS;<br>b. file testo, contraddistinto dal suffisso .out,
+contenente le regole decisionali estratte dal sistema informativo
+geografico, oltre che il core e&nbsp;&nbsp;i ridotti; le regole
+decisionali sono nella forma: &nbsp;<span style="font-style: italic;">if ... then </span>e sono facilmente leggibile ed interpretabili dall'analista per finalità descritive del fenomeno oggetto di studio;<br>c.
+file shell bash, contraddistinto dal suffisso .out.sh, che serve ad
+elaborare i file utilizzati quali attributi nel sistema informativo
+e&nbsp; generare un nuovo file di classificazione e previsione del
+fenomeno oggetto di studio secondo le regole decisionali estratte; in
+altri termini serve e trasferire le regole decisionali al contesto
+geografico. Per fare ciò è sufficiente lanciare ilfile di shell
+all'interno di una sessione di GRASS e può essere opportunamente
+modificato per adattare gli output alle esigenze dell'utente.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#769;<br><br></div><h2 style="text-align: justify;">NOTES</h2><div style="text-align: justify;">Il
+modulo è in grado di trattare raster di qualsiasi tipo
+(CELL,FCELL,DCELL) ma le elaborazioni vengono eseguite tutte su
+variabili di tipo intero (int) perchè questo è imposto dalle rough set
+library. Le regole decisionali, conseguentemente, restituiscono
+informazioni esclusivamente di tipo intero.<br></div><h2 style="text-align: justify;">REFERENCE</h2><div style="text-align: justify;">Pawlak Z. Rough Sets, International Journal of Information&nbsp;and Computer Science Vol. 11, No. 5, 1982, pp. 344-356.<br>Pawlak&#8217;91 Pawlak Z. Rough Sets, Theoretical Aspects of Reasoning&nbsp;about Data, Kluwer Academic Publishers, 1991.<br>Gawrys M.,&nbsp;Sienkiewicz J. Rough Set Library - User's manual&nbsp;(ver. 2.0), September 1993<br><br><br>
+
+</div><h2 style="text-align: justify;">SEE ALSO</h2><div style="text-align: justify;">
+<em>r.mcda.fuzzy, r.mcda.electre, r.mcda.regime</em><br><em></em><em><a href="r.rescale.html"></a></em>
+
+</div><h2 style="text-align: justify;">AUTHORS</h2><div style="text-align: justify;">
+Gianluca Massei - Antonio Boggia - Dipartimento di Scienze Economico Estimative e degli Alimenti - Università di Perugia - Italy</div><p style="text-align: justify;"><br>
+
+</p><p><i><br></i></p></body></html>
\ No newline at end of file

Added: grass-addons/raster/mcda/r.roughset/localproto.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/localproto.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/localproto.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,20 @@
+#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;
+	DCELL *buf;
+};
+
+
+
+
+

Added: grass-addons/raster/mcda/r.roughset/main.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/main.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/main.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,234 @@
+/****************************************************************************
+ *
+ * MODULE:       r.roughset
+ * AUTHOR(S):    Gianluca Massei (g_massa at libero.it) - Antonio Boggia (boggia at unipg.it)
+ *		         M.Gawrys - J.Sienkiewicz original authors of RSl ver. 2
+ *
+ * PURPOSE:      Geographics rough set analisys and knowledge discovery (based on RSL system 
+                    by M.Gawrys J.Sienkiewicz)
+ *
+ * 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 "localproto.h"
+
+
+void rough_sel_library_out(int nrows, int ncols, int nattribute, struct input *attributes, char *fileOutput);
+
+
+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, nattribute;	/* index and  files number*/
+    int nrows, ncols;
+    int strgy;			/* strategy rules extraction index*/
+
+    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 *attribute, *decision, *strategy, *output;	/* 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 knowledg ");
+
+
+    /* Define the different options as defined in gis.h */
+    attribute = G_define_option() ;
+    attribute->key        = "attributes";
+    attribute->type       = TYPE_STRING;
+    attribute->required   = YES;
+    attribute->multiple   = YES;
+    attribute->gisprompt  = "old,cell,raster" ;
+    attribute->description = "Input geographics attributes in information system";
+
+    decision = G_define_option() ;
+    decision->key        = "decision";
+    decision->type       = TYPE_STRING;
+    decision->required   = YES;
+    decision->gisprompt  = "old,cell,raster" ;
+    decision->description = "Input geographics decision in information system";
+
+    strategy = G_define_option() ;
+    strategy->key        = "strategy";
+    strategy->type       = TYPE_STRING;
+    strategy->required   = YES;
+    strategy->options	 = "Very fast,Fast,Medium,Best,All,Low,Upp,Normal";
+    strategy->description = "Choose strategy for generating rules";
+
+    output = G_define_option();
+    output->key = "InfoSys";
+    output->type = TYPE_STRING;
+    output->required = YES;
+    output->gisprompt = "new_file,file,output";
+    output->answer ="InfoSys";
+    output->description = "Output information system file";
+
+
+    /* options and flags parser */
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+
+
+/***********************************************************************/
+/********Prepare and controlling Information System files **************/
+/***********************************************************************/
+
+       /* number of file (=attributes) */
+    nattribute=0;
+    while (attribute->answers[nattribute]!=NULL)
+    	{
+    		nattribute++;
+    	}
+
+
+/*Convert strategy answer in index.  strcmp return 0 if answer is the passed string*/
+    if(strcmp(strategy->answer,"Very fast")==0)
+    	strgy=0;
+    else if(strcmp(strategy->answer,"Fast")==0)
+    	strgy=1;
+    else if(strcmp(strategy->answer,"Medium")==0)
+    	strgy=2;
+    else if(strcmp(strategy->answer,"Best")==0)
+    	strgy=3;
+    else if(strcmp(strategy->answer,"All")==0)
+    	strgy=4;
+    else if(strcmp(strategy->answer,"Low")==0)
+    	strgy=5;
+    else if(strcmp(strategy->answer,"Upp")==0)
+    	strgy=6;
+    else
+    	strgy=7;
+
+    G_message("choose:%d,%s",strgy,strategy->answer);
+
+
+    /* process the input maps:*/
+    /* ATTRIBUTES grid */
+    attributes = G_malloc((nattribute+1) * sizeof(struct input)); /*attributes is input struct defined in localproto.h*/
+
+	for (i = 0; i < nattribute; i++)
+	{
+		struct input *p = &attributes[i];
+		p->name = attribute->answers[i];
+		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);
+		if (p->fd < 0)
+			G_fatal_error(_("Unable to open input map <%s> in mapset <%s>"),p->name, p->mapset);
+		p->buf = G_allocate_d_raster_buf(); /* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL *  */
+	}
+
+   /* DECISION grid (at last column in Information System matrix) */
+		struct input *p = &attributes[nattribute];
+		p->name = decision->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_d_raster_buf(); /* Allocate an array of DCELL based on the number of columns in the current region. Return DCELL *  */
+
+
+	nrows = G_window_rows();
+	ncols = G_window_cols();
+
+	rough_sel_library_out(nrows, ncols, nattribute, attributes, output->answer);/*build RSL standard file*/
+	RulsExtraction(output->answer,attributes,strgy); /* extract rules from RSL*/
+
+	exit(EXIT_SUCCESS);
+}
+
+
+void rough_sel_library_out(int nrows, int ncols, int nattribute, struct input *attributes, char *fileOutput)
+
+{
+	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(fileOutput, "w")))
+        	G_fatal_error("Not able to open file [%s]",fileOutput);
+
+       	fprintf(fp,"NAME: %s\nATTRIBUTES: %d\nOBJECTS: %s\n",fileOutput,nattribute+1,"      ");
+
+	/************** process the data *************/
+
+	nobject=0;
+
+	fprintf (stderr, _("Percent complete ... "));
+
+	for (row = 0; row < nrows; row++)
+		{
+			G_percent(row, nrows, 2);
+			for(i=0;i<=nattribute;i++)
+				{
+					G_get_d_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)
+						{
+							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++;
+			      			}
+					}
+		}
+	/************** write code file*************/
+
+	for(i=0;i<=nattribute;i++)
+	{
+		fprintf(fp,"\n%s",attributes[i].name);
+	}
+
+	/************** write header file*************/
+
+	if(0<fseek(fp,0L,0)) /*move file pointer to header file*/
+		G_fatal_error("Not able to write file [%s]",fileOutput);
+	else
+		fprintf(fp,"NAME: %s\nATTRIBUTES: %d\nOBJECTS: %d\n",fileOutput,nattribute+1,nobject);
+
+	/************** close all and exit ***********/
+
+	for (i = 0; i<=nattribute; i++)
+		G_close_cell(attributes[i].fd);
+
+	fclose(fp);
+	G_percent(row, nrows, 2);
+
+}
+
+
+
+
+

Added: grass-addons/raster/mcda/r.roughset/r.roughset.tmp.html
===================================================================
--- grass-addons/raster/mcda/r.roughset/r.roughset.tmp.html	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/r.roughset.tmp.html	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,57 @@
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head><title>r.roughset</title></head>
+<body><h2 style="text-align: justify;">NAME</h2><div style="text-align: justify;">
+<em><b>r.roughset</b></em>  - Rough set based geographics knowledg 
+</div><h2 style="text-align: justify;">KEYWORDS</h2><div style="text-align: justify;">
+raster,&nbsp;geographics knowledg<span style="font-weight: bold;"> </span>discovery
+</div><h2 style="text-align: justify;">SYNOPSIS</h2><div style="text-align: justify;">
+<b>r.roughset</b><br>
+<b>r.roughset help</b><br>
+<b>r.roughset</b> <b>attributes</b>=<em>string</em>[,<i>string</i>,...] <b>decision</b>=<em>string</em> <b>strategy</b>=<em>string</em> <b>InfoSys</b>=<em>string</em>  [--<b>verbose</b>]  [--<b>quiet</b>] 
+
+
+</div><h3 style="text-align: justify;">Parameters:</h3><div style="text-align: justify;">
+</div><dl style="text-align: justify;"><dt><b>attributes</b>=<em>string[,<i>string</i>,...]</em></dt><dd>Input geographics attributes in information system</dd><dt><b>decision</b>=<em>string</em></dt><dd>Input geographics decision in information system</dd><dt><b>strategy</b>=<em>string</em></dt><dd>Choose strategy for generating rules</dd><dd>Options: <em>Very fast,Fast,Medium,Best,All,Low,Upp,Normal</em></dd><dt><b>InfoSys</b>=<em>string</em></dt><dd>Output information system file</dd><dd>Default: <em>InfoSys</em></dd></dl><br><br><h2 style="text-align: justify;">DESCRIPTION</h2><div style="text-align: justify;">
+
+<b>r.roughset&nbsp;</b>è un modulo che consente&nbsp;l'applicazione
+della rough set theory [] a database geografici in ambiente GRASS GIS.
+L'input è costituito da due gruppi di dati: <br>1. gli attributi
+geografici che costituiscono il sistema informativo della rough set
+analisys e che si ritiene siano sufficienti a descrivere&nbsp;un
+determinato fenomeno naturale, sociale od economico (<b>attributes</b>=<em>string[,<i>string</i>,...]</em>);<br>2.
+il tematismo decisionale nel quale sono identificate le aree per cui il
+fenomeno da studaire si è presentato con una certa modalità(<b>decision</b>=<em>string</em>);<br>Il
+sistema informativo così generato viene trattato con le funzioni della
+versione 2 delle rough set library (RSL, ver. 2.0)&nbsp; [1993,
+M.Gawrys, J.Sienkiewicz] secondo una delle strategie decisionali
+disponibili (<b>strategy</b>=<em>string</em>).<br><br>L'output è costituito da tre differenti files testuali, con prefisso definito dall'utente nel campo <b>InfoSys</b>=<em>string, </em>e in dettaglio:<br>a.
+file testo strutturato secondo lo standard suggerito dalla rough set
+library, contraddistinto dallo stesso nome indicato nel campo InfoSys
+senza ulteriori suffissi; non riveste particolare interesse per
+l'utente a meno che non si vogliano utilizare le RSL al di fuori
+dall'ambiente GIS;<br>b. file testo, contraddistinto dal suffisso .out,
+contenente le regole decisionali estratte dal sistema informativo
+geografico, oltre che il core e&nbsp;&nbsp;i ridotti; le regole
+decisionali sono nella forma: &nbsp;<span style="font-style: italic;">if ... then </span>e sono facilmente leggibile ed interpretabili dall'analista per finalità descritive del fenomeno oggetto di studio;<br>c.
+file shell bash, contraddistinto dal suffisso .out.sh, che serve ad
+elaborare i file utilizzati quali attributi nel sistema informativo
+e&nbsp; generare un nuovo file di classificazione e previsione del
+fenomeno oggetto di studio secondo le regole decisionali estratte; in
+altri termini serve e trasferire le regole decisionali al contesto
+geografico. Per fare ciò è sufficiente lanciare ilfile di shell
+all'interno di una sessione di GRASS e può essere opportunamente
+modificato per adattare gli output alle esigenze dell'utente.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#769;<br><br></div><h2 style="text-align: justify;">NOTES</h2><div style="text-align: justify;">Il
+modulo è in grado di trattare raster di qualsiasi tipo
+(CELL,FCELL,DCELL) ma le elaborazioni vengono eseguite tutte su
+variabili di tipo intero (int) perchè questo è imposto dalle rough set
+library. Le regole decisionali, conseguentemente, restituiscono
+informazioni esclusivamente di tipo intero.<br></div><h2 style="text-align: justify;">REFERENCE</h2><div style="text-align: justify;">Pawlak Z. Rough Sets, International Journal of Information&nbsp;and Computer Science Vol. 11, No. 5, 1982, pp. 344-356.<br>Pawlak&#8217;91 Pawlak Z. Rough Sets, Theoretical Aspects of Reasoning&nbsp;about Data, Kluwer Academic Publishers, 1991.<br>Gawrys M.,&nbsp;Sienkiewicz J. Rough Set Library - User's manual&nbsp;(ver. 2.0), September 1993<br><br><br>
+
+</div><h2 style="text-align: justify;">SEE ALSO</h2><div style="text-align: justify;">
+<em>r.mcda.fuzzy, r.mcda.electre, r.mcda.regime</em><br><em></em><em><a href="r.rescale.html"></a></em>
+
+</div><h2 style="text-align: justify;">AUTHORS</h2><div style="text-align: justify;">
+Gianluca Massei - Antonio Boggia - Dipartimento di Scienze Economico Estimative e degli Alimenti - Università di Perugia - Italy</div><p style="text-align: justify;"><br>
+
+</p><p><i><br></i></p></body></html>
\ No newline at end of file

Added: grass-addons/raster/mcda/r.roughset/raccess.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/raccess.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/raccess.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,159 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***            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] );
+ }

Added: grass-addons/raster/mcda/r.roughset/raccess.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/raccess.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/raccess.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,50 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***             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 */

Added: grass-addons/raster/mcda/r.roughset/rbasic.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rbasic.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rbasic.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,472 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***               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;
+ }

Added: grass-addons/raster/mcda/r.roughset/rbasic.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rbasic.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rbasic.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,67 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***                   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" */

Added: grass-addons/raster/mcda/r.roughset/rclass.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rclass.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rclass.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,202 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***               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;
+}

Added: grass-addons/raster/mcda/r.roughset/rclass.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rclass.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rclass.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,51 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***               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 */

Added: grass-addons/raster/mcda/r.roughset/rcore.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rcore.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rcore.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,253 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***               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;
+  }

Added: grass-addons/raster/mcda/r.roughset/rcore.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rcore.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rcore.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,50 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***              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 */
+

Added: grass-addons/raster/mcda/r.roughset/reduct1.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/reduct1.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/reduct1.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,1022 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***               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);
+}
+

Added: grass-addons/raster/mcda/r.roughset/reduct1.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/reduct1.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/reduct1.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,48 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***               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 */
+

Added: grass-addons/raster/mcda/r.roughset/reduct2.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/reduct2.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/reduct2.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,173 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***               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;
+ }
+
+

Added: grass-addons/raster/mcda/r.roughset/reduct2.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/reduct2.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/reduct2.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,45 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***              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 */
+
+

Added: grass-addons/raster/mcda/r.roughset/rerror.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rerror.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rerror.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,24 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***         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;}
+

Added: grass-addons/raster/mcda/r.roughset/rough.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rough.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rough.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,50 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***       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"

Added: grass-addons/raster/mcda/r.roughset/rset.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rset.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rset.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,373 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***       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");
+ }
+
+

Added: grass-addons/raster/mcda/r.roughset/rset.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rset.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rset.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,119 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***       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 */

Added: grass-addons/raster/mcda/r.roughset/rsystem.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rsystem.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rsystem.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,452 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***                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; }

Added: grass-addons/raster/mcda/r.roughset/rsystem.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rsystem.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rsystem.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,123 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***                 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 */

Added: grass-addons/raster/mcda/r.roughset/rule1.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rule1.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rule1.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,35 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***               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;	 
+ }
+

Added: grass-addons/raster/mcda/r.roughset/rule1.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rule1.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rule1.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,22 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***               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 */

Added: grass-addons/raster/mcda/r.roughset/rule2.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rule2.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rule2.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,550 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***               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;
+ }
+
+
+   

Added: grass-addons/raster/mcda/r.roughset/rule2.h
===================================================================
--- grass-addons/raster/mcda/r.roughset/rule2.h	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rule2.h	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,79 @@
+/*******************************************************************/
+/*******************************************************************/
+/***                                                             ***/
+/***               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 */

Added: grass-addons/raster/mcda/r.roughset/rules_extr.c
===================================================================
--- grass-addons/raster/mcda/r.roughset/rules_extr.c	                        (rev 0)
+++ grass-addons/raster/mcda/r.roughset/rules_extr.c	2008-10-10 10:38:38 UTC (rev 33802)
@@ -0,0 +1,344 @@
+/************************************************************************
+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 RulsExtraction(char *name, struct input *attributes, int strgy);
+void fPrintSetA( FILE *f, setA set );
+void fPrintSetO( FILE *f, setO set );
+void fPrintRules( FILE *file, value_type* rules, int N, int *opr, setA P, setA Q, struct input *attributes);
+void fPrintToScript( 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 RulsExtraction(char *name,struct input *attributes, int strgy)  /*old MAIN*/
+{
+  SYSTEM *sys1, *sys2, *trainsys, *testsys; /* Information system descriptor structures. It contains information about the 							system parameters (number of objects, number of attributes, system name. */
+  value_type *buf,*rules; /* stores a single value of attribute (used for attribute-value table and rule implementation)*/
+  char c;
+  int ob,at,at2,n,j,i,work=1,good,r;
+  int *opr;
+  setA beg,P,Q,full,core; /*set of attributes*/
+  setO train;		  /*set of object*/
+  FILE *file, *file2, *file3;
+  int (*genrules)( value_type**, setA, setA, int );
+  int p30, sample;
+  clock_t time1, time2;
+  int inf;
+  char *nameFILE; /*storage root file names*/
+   
+
+  sys1=InitEmptySys();  /* Allocates memory for a system descriptor and returns a pointer.*/
+
+
+  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 (!(file2=fopen(name,"a"))) 					/*output text file*/
+  	{G_fatal_error("  Can't open output file \n");
+  		return(1);}
+  		
+  strcat(name,".sh");  	
+  	
+  if (!(file3=fopen(name,"w"))) 					/*output mapcalc 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.*/
+  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();
+  
+
+  
+  /* define attribute */
+  for(i=0;i<(AttributesNum(sys1)-1);i++)  
+    { 
+    	AddSetA(P,i); /* Adds a single element to a set */
+    }
+    
+    
+   /* define decision */
+   AddSetA(Q,(AttributesNum(sys1)-1));
+   
+   
+  /*printf("number of objects: %i \n",ObjectsNum(sys1)); 		Returns number of objects in a system*/
+  /*printf("number of attributes: %i \n",AttributesNum(sys1));  Returns a number of attributes in a system.*/
+  
+    
+  fprintf(file2,"Condition attributes are\n");   
+        fPrintSetA(file2,P);
+        PrintSetA(P);  /* Writes a formatted condition set to the standard output.Prints elements in brackets. */
+  fprintf(file2,"\nDecision attributes are\n");   
+        fPrintSetA(file2,Q);
+        PrintSetA(Q);  /* Writes a formatted decision set to the standard output.Prints elements in brackets. */
+  fprintf(file2,"\nDependCoef = %f\n",DependCoef(P,Q,MATD)); /* Returns degree of dependency Q from P in the active information system.*/
+
+  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. */	
+  fprintf(file2,"CORE = ");   
+  fPrintSetA(file2,core);  
+  RedOptim( core, MATX ); /* Provides the optimized heuristic search for a single reduct */
+  fprintf(file2,"\nRedOptim = ");
+  fPrintSetA(file2,core);
+  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. */
+
+  fprintf( file2,"\nFew reducts ( %i ):\n", n );
+  for (i=0;i<n;i++)
+  { 
+     fPrintSetA( file2, beg+i*sys1->setAsize );
+     fprintf(file2,"\n");
+  }
+  if ( n>0 ) free( beg );
+
+
+
+
+
+  fprintf(file2, "%d strategy of generating rules\n", strgy);
+    
+  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;
+     }
+
+/*****************************************************************************/
+  time1 = clock();
+  r = genrules ( &rules, P, Q, MATD );
+  time2 = clock();
+  if (r>0)
+  {  fprintf(file2,"Time of generating rules = %ds\n", time2, (time2-time1)/CLOCKS_PER_SEC );
+     opr = StrengthOfRules( rules, r ); /* Creates a table of rules strengths*/
+     fprintf(file2,"Rules ( %i )\n", r );
+     fPrintRules( file2, rules, r, opr, P, Q, attributes ); /*print to file generated rules*/
+     fPrintToScript( file3, rules, r, opr, P, Q, attributes );/*build mapcalc file*/
+     fprintf(file2,"Mean number of attributes in rule = %.1f\n",MeanAttrInRule( rules, r, P ));
+     free( rules );
+     free( opr );
+  }
+/******************************************************************************/
+  
+  
+  CloseSetA(P);
+  CloseSetA(Q);
+  CloseSetA(full);
+  CloseSys(sys1);
+  fclose(file2);
+  fclose(file3);
+  G_message("O.K. output placed to files");
+  return (0);
+}
+
+
+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;
+}
+
+
+void fPrintToScript( FILE *file, value_type* rules, int N, int *opr, setA P, setA Q, struct input *attributes )
+{  
+	int n,j,i;
+   fprintf(file,"#!/bin/bash\nRASTERrule=${1}\nif [ $# -ne 1 ]; then\n\techo 'Output file named roughmap, "
+				"Consider renaming'\n\tRASTERrule=roughmap\nfi\n");
+   	for (n=0;n<N;n++) 
+   	{  
+   	  	i=0;
+   	  	for (j=0;j<_mainsys->attributes_num;j++)
+   	  		{
+	 		if ( ContSetA( P,j ) ) /*Tests if a set contains an element*/
+	   			if (rules[n*_mainsys->attributes_num+j]!=MINUS) /*Missing values are coded by MINUS*/
+	   				{
+	   				if(i==0) /*if the role is only one or the firsth ...*/
+	   					fprintf(file,"r.mapcalc 'maprule%d=if(%s==%d",n,attributes[j].name,rules[n*_mainsys->attributes_num+j]);
+	   				else /*... otherwise ...*/
+	   					fprintf(file," && %s==%d",attributes[j].name,rules[n*_mainsys->attributes_num+j]);
+	   				i++;
+	   				}   		
+	   		}	   			
+      	for (j=0;j<_mainsys->attributes_num;j++)
+	 		if ( ContSetA( Q,j ) ) /*Tests if a set contains an element*/
+	   			if ((rules+n*_mainsys->attributes_num)[j]!=MINUS) /*Missing values are coded by MINUS*/
+	     			fprintf(file,",%d,null())'\n",(rules+n*_mainsys->attributes_num)[j]);
+   	}
+
+	
+   	fprintf(file,"\nr.patch --overwrite input=");
+   	for (n=0;n<N;n++) 
+   		{
+   			fprintf(file,"maprule%d",n);
+   			if(n<N-1)	{fprintf(file,",");}
+   		}
+   	fprintf(file," output=$RASTERrule");
+   		
+   	fprintf(file,"\ng.remove rast=");
+   	for (n=0;n<N;n++) 
+   		{
+   			fprintf(file,"maprule%d",n);
+   			if(n<N-1)	{fprintf(file,",");}
+   		}	
+		
+	fprintf(file,"\nr.colors map=$RASTERrule color=ryg ");
+
+   	return;
+}
+
+/*
+void fPrintToScript( FILE *file, value_type* rules,
+		 int N, int *opr, setA P, setA Q, struct input *attributes )
+{  int n,j,i;
+   
+   fprintf(file,"roughmap=");
+   for (n=0;n<N;n++) 
+   {  
+   	  i=0;
+   	  for (j=0;j<_mainsys->attributes_num;j++)
+   	  	{
+	 	if ( ContSetA( P,j ) ) 
+	   		if (rules[n*_mainsys->attributes_num+j]!=MINUS) 
+	   			{
+	   			if(i==0) 
+	   				fprintf(file,"if(%s==%d",attributes[j].name,rules[n*_mainsys->attributes_num+j]);
+	   			else 
+	   				fprintf(file," && %s==%d",attributes[j].name,rules[n*_mainsys->attributes_num+j]);
+	   			i++;
+	   			}
+	   		
+	   	}
+	   			
+      for (j=0;j<_mainsys->attributes_num;j++)
+	 	if ( ContSetA( Q,j ) ) 
+	   		if ((rules+n*_mainsys->attributes_num)[j]!=MINUS) 
+	     		fprintf(file,",%d)",(rules+n*_mainsys->attributes_num)[j]);
+      if(n<N-1)
+	 fprintf(file,"\\ \n + ");
+   }
+	   			
+   fprintf(file,"\nend\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 );
+}
+
+
+   
+
+



More information about the grass-commit mailing list