[GRASS-SVN] r66121 - grass-addons/grass7/raster/r.mcda.promethee

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Sep 6 02:29:29 PDT 2015


Author: gianluca
Date: 2015-09-06 02:29:29 -0700 (Sun, 06 Sep 2015)
New Revision: 66121

Modified:
   grass-addons/grass7/raster/r.mcda.promethee/local_proto.h
   grass-addons/grass7/raster/r.mcda.promethee/main.c
   grass-addons/grass7/raster/r.mcda.promethee/promethee.c
Log:
first almost usable version 0.1

Modified: grass-addons/grass7/raster/r.mcda.promethee/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.mcda.promethee/local_proto.h	2015-09-06 02:44:34 UTC (rev 66120)
+++ grass-addons/grass7/raster/r.mcda.promethee/local_proto.h	2015-09-06 09:29:29 UTC (rev 66121)
@@ -20,5 +20,5 @@
 
 void build_flow_matrix(int nrows, int ncols, int ncriteria,
                             double *weight_vect, double ***decision_vol,
-                            double ***positive_flow_vol, double ***negative_flow_vol);
+                            double **positive_flow_vol, double **negative_flow_vol);
 

Modified: grass-addons/grass7/raster/r.mcda.promethee/main.c
===================================================================
--- grass-addons/grass7/raster/r.mcda.promethee/main.c	2015-09-06 02:44:34 UTC (rev 66120)
+++ grass-addons/grass7/raster/r.mcda.promethee/main.c	2015-09-06 09:29:29 UTC (rev 66121)
@@ -3,9 +3,8 @@
  * MODULE:   r.mcda.promethee
  * AUTHORS:  Gianluca Massei (g_massa at libero.it) - Antonio Boggia (boggia at unipg.it)
  *
- * PURPOSE:      Make a multicriteria decision analysis based on PROMETHEE algorithm,
- *               with concordance and discordance indexes maps
- *
+ * PURPOSE:      Make a multicriteria decision analysis based on PROMETHEE algorithm.
+ *               
  * COPYRIGHT:    (C) GRASS Development Team (2015)
  *
  *              This program is free software under the GNU General Public
@@ -38,7 +37,7 @@
     int row1, col1;
     int outfd_positive_flow, outfd_negative_flow, outfd_netflow;      /* output file descriptor */
     /*RASTER_MAP_TYPE data_type;     type of the map (CELL/DCELL/...) */
-    double *weight_vect, ***decision_vol, ***positive_flow_vol, ***negative_flow_vol;/* vector and matrix */
+    double *weight_vect, ***decision_vol, **positive_flow_vol, **negative_flow_vol;/* vector and matrix */
 
 
     struct History history; /* holds meta-data (title, comments,..) */
@@ -164,19 +163,20 @@
 
     /*memory allocation for-three dimensional matrix*/
     decision_vol=G_malloc(nrows * sizeof(double*));
-    positive_flow_vol=G_malloc(nrows * sizeof(double*));
-    negative_flow_vol=G_malloc(nrows * sizeof(double*));
+    positive_flow_vol=G_calloc(nrows, sizeof(double*)); /*Allocates aligned block of memory and initializes the allocated memory to zero.*/
+    negative_flow_vol=G_calloc(nrows, sizeof(double*));
+ 
     
     for (i=0; i<nrows; ++i)
     {
         decision_vol[i]=G_malloc(ncols * sizeof(double*));
-        positive_flow_vol[i]=G_malloc(nrows * sizeof(double*));
-        negative_flow_vol[i]=G_malloc(nrows * sizeof(double*));
+        positive_flow_vol[i]=G_calloc(ncols, sizeof(double*));/*Allocates aligned block of memory and initializes the allocated memory to zero.*/
+        negative_flow_vol[i]=G_calloc(ncols, sizeof(double*));
         for (j=0; j<ncols; ++j)
         {
             decision_vol[i][j]=G_malloc((ncriteria+2) * sizeof(double)); /****NOTE: it's storage ****/
-            positive_flow_vol[i][j]=G_malloc((ncriteria+2) * sizeof(double));
-            negative_flow_vol[i][j]=G_malloc((ncriteria+2) * sizeof(double));
+            //positive_flow_vol[i][j]=G_malloc((ncriteria) * sizeof(double));
+            //negative_flow_vol[i][j]=G_malloc((ncriteria) * sizeof(double));
         }
     }
 
@@ -186,16 +186,18 @@
     outrast_netflow = Rast_allocate_buf(DCELL_TYPE);
     
     /* controlling, if we can write the raster */
-    outrast_positive_flow = Rast_open_new(result_positive_flow, DCELL_TYPE);
-    outrast_negative_flow = Rast_open_new(result_negative_flow, DCELL_TYPE);
-    outrast_netflow = Rast_open_new(result_netflow, DCELL_TYPE);
+    outfd_positive_flow = Rast_open_new(result_positive_flow, DCELL_TYPE);
+    outfd_negative_flow = Rast_open_new(result_negative_flow, DCELL_TYPE);
+    outfd_netflow = Rast_open_new(result_netflow, DCELL_TYPE);
 
 
     /*build a three dimensional matrix for storage all critera maps*/
+    G_message("Load data");
     for (i=0;i<ncriteria;i++)
     {
         for (row1 = 0; row1 < nrows;row1++)
         {
+            G_percent(row1, nrows, 2);
             Rast_get_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++)
@@ -206,17 +208,18 @@
             }
         }
     }
-
-    G_message("step started");
+    
+    G_message("run algorithm");
     build_flow_matrix(nrows,ncols,ncriteria,weight_vect,decision_vol,positive_flow_vol, negative_flow_vol); /*scan all DCELL, make a pairwise comparatione, buil positive flow matrix*/
-    G_message("step ended");
 
+    G_message("buil mcda maps");
     for (row1 = 0; row1 < nrows; row1++)
     {
+        G_percent(row1, nrows, 2);
         for (col1 = 0; col1 < ncols; col1++)
         {
-            ((DCELL *) outrast_positive_flow)[col1] = (DCELL)positive_flow_vol[row1][col1][ncriteria];/*write positive flow map*/
-            ((DCELL *) outrast_negative_flow)[col1] = (DCELL)negative_flow_vol[row1][col1][ncriteria];/*write negative flow map*/
+            ((DCELL *) outrast_positive_flow)[col1] = (DCELL)positive_flow_vol[row1][col1];/*write positive flow map*/
+            ((DCELL *) outrast_negative_flow)[col1] = (DCELL)negative_flow_vol[row1][col1];/*write negative flow map*/
         }
         Rast_put_row(outfd_positive_flow, outrast_positive_flow,  DCELL_TYPE);
         Rast_put_row(outfd_negative_flow, outrast_negative_flow,  DCELL_TYPE);

Modified: grass-addons/grass7/raster/r.mcda.promethee/promethee.c
===================================================================
--- grass-addons/grass7/raster/r.mcda.promethee/promethee.c	2015-09-06 02:44:34 UTC (rev 66120)
+++ grass-addons/grass7/raster/r.mcda.promethee/promethee.c	2015-09-06 09:29:29 UTC (rev 66121)
@@ -9,7 +9,7 @@
 
 void build_flow_matrix(int nrows, int ncols, int ncriteria,
                             double *weight_vect, double ***decision_vol,
-                            double ***positive_flow_vol, double ***negative_flow_vol);
+                            double **positive_flow_vol, double **negative_flow_vol);
 
 
 /*
@@ -50,7 +50,7 @@
 
 void build_flow_matrix(int nrows, int ncols, int ncriteria,
                             double *weight_vect, double ***decision_vol,
-                            double ***positive_flow_vol, double ***negative_flow_vol)
+                            double **positive_flow_vol, double **negative_flow_vol)
 {
     int row1, col1, row2, col2;
     int i;
@@ -66,37 +66,45 @@
 			{
 				for (row2 = 0; row2 < nrows; row2++)
 				{
+					//G_percent(row2, (nrows), 2);
 					for (col2 = 0; col2 < ncols; col2++)
 					{
 						threshold = (decision_vol[row1][col1][i] - decision_vol[row2][col2][i]);
+						//G_message("thersold:%f;r1:%d;c1:%d // r2:%d;c2:%d ",threshold,row1,col1,row2,col2);
 						if (threshold>0)
 							{
-							positive_flow_vol[row1][col1][i]=threshold*weight_vect[i];
-							negative_flow_vol[row1][col1][i]=0;
+							//positive_flow_vol[row1][col1][i]=threshold*weight_vect[i];
+							//negative_flow_vol[row1][col1][i]=0;
+							positive_flow_vol[row1][col1]=positive_flow_vol[row1][col1]+(threshold*weight_vect[i]);
+							negative_flow_vol[row1][col1]=negative_flow_vol[row1][col1];
+
 							}
 						else
 							{
-							positive_flow_vol[row1][col1][i]=0;
-							negative_flow_vol[row1][col1][i]=threshold*weight_vect[i];
+							negative_flow_vol[row1][col1]=negative_flow_vol[row1][col1]+(threshold*weight_vect[i]);
+							positive_flow_vol[row1][col1]=positive_flow_vol[row1][col1];
+							//positive_flow_vol[row1][col1][i]=0;
+							//negative_flow_vol[row1][col1][i]=threshold*weight_vect[i];
 							}
 					}
 				}
 			}
 		}
 	}
-
+	G_message("check");
+	
     /*storage preference value in decision_vol */
-    for (row1 = 0; row1 < nrows; row1++)
+/*    for (row1 = 0; row1 < nrows; row1++)
     {
         G_percent(row1, nrows, 2);
         for (col1 = 0; col1 < ncols; col1++)
         {
 			for ( i=0; i<ncriteria;i++)
 			{
-            /*fill matrix with performance  for each DCELL */
+            //fill matrix with performance  for each DCELL 
             positive_flow_vol[row1][col1][ncriteria] = positive_flow_vol[row1][col1][ncriteria]+positive_flow_vol[row1][col1][i];
             negative_flow_vol[row1][col1][ncriteria] = negative_flow_vol[row1][col1][ncriteria]+negative_flow_vol[row1][col1][i];
 			}
         }
-    }
+    }*/
 }



More information about the grass-commit mailing list