[GRASS-SVN] r35163 - grass-addons/raster/mcda/r.mcda.regime
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jan 2 09:58:02 EST 2009
Author: gianluca
Date: 2009-01-02 09:58:02 -0500 (Fri, 02 Jan 2009)
New Revision: 35163
Modified:
grass-addons/raster/mcda/r.mcda.regime/main.c
grass-addons/raster/mcda/r.mcda.regime/regime.c
Log:
r.mcda.regime: more efficient code
Modified: grass-addons/raster/mcda/r.mcda.regime/main.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/main.c 2009-01-02 10:26:44 UTC (rev 35162)
+++ grass-addons/raster/mcda/r.mcda.regime/main.c 2009-01-02 14:58:02 UTC (rev 35163)
@@ -1,13 +1,13 @@
/****************************************************************************
*
- * MODULE: r.mcda.electre
- * AUTHORS Gianluca Massei (g_massa at libero.it) - Antonio Boggia (boggia at unipg.it)
+ * 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)
+ * COPYRIGHT: (C) G.Massei - A.Boggia (2008)
*
- * This program is free software under the GNU General Public
+ * This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
* for details.
*
@@ -31,7 +31,7 @@
int nrows, ncols;
int row1, row2, col1, col2;
int outfd_preference; /* output file descriptor */
- double *weight_vect, **regime_mat, ***decision_vol;
+ double *weight_vect, ***decision_vol;
struct History history; /* holds meta-data (title, comments,..) */
@@ -114,7 +114,7 @@
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 */
+ 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*/
@@ -128,8 +128,6 @@
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)
@@ -167,7 +165,7 @@
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 */
+ build_regime_matrix(nrows,ncols,ncriteria,weight_vect,decision_vol); /*scan all DCELL, make a pairwise comparatione, buil regime index matrix */
for(row1 = 0; row1 < nrows; row1++)
@@ -187,7 +185,6 @@
G_free(attributes[i].inrast);
G_free(outrast_preference);
- G_free_matrix(regime_mat);
G_free(decision_vol);
/* closing raster maps */
Modified: grass-addons/raster/mcda/r.mcda.regime/regime.c
===================================================================
--- grass-addons/raster/mcda/r.mcda.regime/regime.c 2009-01-02 10:26:44 UTC (rev 35162)
+++ grass-addons/raster/mcda/r.mcda.regime/regime.c 2009-01-02 14:58:02 UTC (rev 35163)
@@ -6,7 +6,7 @@
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);
+void build_regime_matrix(int nrows, int ncols, int ncriteria, double *weight_vect, double ***decision_vol);
/*
@@ -43,56 +43,50 @@
}
-void build_regime_matrix(int nrows, int ncols, int ncriteria, double *weight_vect, double **regime_mat, double ***decision_vol)
+void build_regime_matrix(int nrows, int ncols, int ncriteria, double *weight_vect, double ***decision_vol)
{
int row1,col1,row2,col2;
int i,j,k,cont;
- double row_sum_regime;
+ double *row_sum_regime = G_alloc_vector(nrows * ncols);
- k=0; /* make pairwise comparation and built regime matrix*/
+ j=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++)
{
+ double reg = 0;
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]);
+ double d=decision_vol[row1][col1][i]-decision_vol[row2][col2][i];
+ if(d>0)
+ reg += (1*weight_vect[i]);
+ else if(d<0)
+ reg += (-1*weight_vect[i]);
else
- regime_mat[k][j]=regime_mat[k][j];
+ reg += 0;
}
- j++;/* increase rows index up to nrows*ncols*/
+ row_sum_regime[j] += reg;
}
}
- k++; /* increase columns index up to nrows*ncols*/
+ j++;/* increase rows index up to nrows*ncols*/
}
+ G_percent(row1, nrows, 1);
}
/*calculate concordance and discordance index and storage in decision_vol*/
cont=0;
for(row1=0;row1<nrows;row1++)
{
- 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];
- }
+ decision_vol[row1][col1][ncriteria]=row_sum_regime[cont]/(nrows*ncols-1);/*fill matrix with regime index for each DCELL*/
cont++;
- decision_vol[row1][col1][ncriteria]=row_sum_regime/(nrows*ncols-1);/*fill matrix with regime index for each DCELL*/
}
+ G_percent(row1, nrows, 2);
}
}
More information about the grass-commit
mailing list