[GRASS-SVN] r66192 - grass-addons/grass7/raster/r.mcda.promethee
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Sep 13 13:42:44 PDT 2015
Author: gianluca
Date: 2015-09-13 13:42:44 -0700 (Sun, 13 Sep 2015)
New Revision: 66192
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:
all output performed
Modified: grass-addons/grass7/raster/r.mcda.promethee/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.mcda.promethee/local_proto.h 2015-09-13 13:28:35 UTC (rev 66191)
+++ grass-addons/grass7/raster/r.mcda.promethee/local_proto.h 2015-09-13 20:42:44 UTC (rev 66192)
@@ -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,
+ double **net_flow_vol);
Modified: grass-addons/grass7/raster/r.mcda.promethee/main.c
===================================================================
--- grass-addons/grass7/raster/r.mcda.promethee/main.c 2015-09-13 13:28:35 UTC (rev 66191)
+++ grass-addons/grass7/raster/r.mcda.promethee/main.c 2015-09-13 20:42:44 UTC (rev 66192)
@@ -30,15 +30,15 @@
int main(int argc, char *argv[])
{
struct Cell_head cellhd; /* it stores region information, and header information of rasters */
- char *result_positive_flow, *result_negative_flow, *result_netflow; /* outputs raster name */
+ char *result_positive_flow, *result_negative_flow, *result_net_flow; /* outputs raster name */
/*char *mapset; mapset name */
- unsigned char *outrast_positive_flow, *outrast_negative_flow, *outrast_netflow; /* output buffer */
+ unsigned char *outrast_positive_flow, *outrast_negative_flow, *outrast_net_flow; /* output buffer */
int i,j, ncriteria=0; /* index and files number*/
int nrows, ncols;
int row1, col1;
- int outfd_positive_flow, outfd_negative_flow, outfd_netflow; /* output file descriptor */
+ int outfd_positive_flow, outfd_negative_flow, outfd_net_flow; /* 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, **net_flow_vol;/* vector and matrix */
struct History history; /* holds meta-data (title, comments,..) */
@@ -145,7 +145,7 @@
result_positive_flow=positiveflow->answer; /* store output name in variables*/
result_negative_flow=negativeflow->answer;
- result_netflow=netflow->answer;
+ result_net_flow=netflow->answer;
if (G_legal_filename(result_positive_flow) < 0) /* check for legal database file names */
@@ -154,8 +154,8 @@
if (G_legal_filename(result_negative_flow) < 0) /* check for legal database file names */
G_fatal_error(_("<%s> is an illegal file name"), result_negative_flow);
- if (G_legal_filename(result_netflow) < 0) /* check for legal database file names */
- G_fatal_error(_("<%s> is an illegal file name"), result_netflow);
+ if (G_legal_filename(result_net_flow) < 0) /* check for legal database file names */
+ G_fatal_error(_("<%s> is an illegal file name"), result_net_flow);
/*values = G_malloc(ncriteria * sizeof(DCELL));*/
@@ -166,6 +166,8 @@
decision_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*));
+ net_flow_vol=G_calloc(nrows, sizeof(double*));
+ //negative_flow_vol=G_calloc(nrows, sizeof(double*));
for (i=0; i<nrows; ++i)
@@ -173,25 +175,24 @@
decision_vol[i]=G_malloc(ncols * 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*));
+ 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) * sizeof(double));
- //negative_flow_vol[i][j]=G_malloc((ncriteria) * sizeof(double));
}
}
/* Allocate output buffer, use DCELL_TYPE */
outrast_positive_flow = Rast_allocate_buf(DCELL_TYPE); /* Allocate memory for a raster map of type DCELL_TYPE. */
outrast_negative_flow = Rast_allocate_buf(DCELL_TYPE);
- outrast_netflow = Rast_allocate_buf(DCELL_TYPE);
+ outrast_net_flow = Rast_allocate_buf(DCELL_TYPE);
+ //outrast_net_flow = Rast_allocate_buf(DCELL_TYPE);
/* controlling, if we can write the raster */
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);
+ outfd_net_flow = Rast_open_new(result_net_flow, DCELL_TYPE);
-
/*build a three dimensional matrix for storage all critera maps*/
G_message("Load data");
for (i=0;i<ncriteria;i++)
@@ -211,7 +212,7 @@
}
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*/
+ build_flow_matrix(nrows,ncols,ncriteria,weight_vect,decision_vol,positive_flow_vol,negative_flow_vol,net_flow_vol); /*scan all DCELL, make a pairwise comparatione, buil positive flow matrix*/
G_message("buil mcda maps");
for (row1 = 0; row1 < nrows; row1++)
@@ -221,9 +222,11 @@
{
((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*/
+ ((DCELL *) outrast_net_flow)[col1] = (DCELL)net_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);
+ Rast_put_row(outfd_net_flow, outrast_net_flow, DCELL_TYPE);
}
@@ -235,28 +238,34 @@
G_free(outrast_positive_flow);
G_free(outrast_negative_flow);
+ G_free(outrast_net_flow);
G_free(decision_vol);
G_free(positive_flow_vol);
G_free(negative_flow_vol);
+ G_free(net_flow_vol);
-
-
/* closing raster maps */
for (i = 0; i<ncriteria; i++)
Rast_close(attributes[i].infd);
Rast_close(outfd_positive_flow);
Rast_close(outfd_negative_flow);
+ Rast_close(outfd_net_flow);
- /* add command line incantation to history concordance file */
+ /* add command line incantation to history positive file */
Rast_short_history(result_positive_flow, "raster", &history);
Rast_command_history(&history);
Rast_write_history(result_positive_flow, &history);
- /* add command line incantation to history discordance file */
+ /* add command line incantation to history negative file */
Rast_short_history(result_negative_flow, "raster", &history);
Rast_command_history(&history);
Rast_write_history(result_negative_flow, &history);
+
+ /* add command line incantation to history net file */
+ Rast_short_history(result_net_flow, "raster", &history);
+ Rast_command_history(&history);
+ Rast_write_history(result_net_flow, &history);
exit(EXIT_SUCCESS);
}
Modified: grass-addons/grass7/raster/r.mcda.promethee/promethee.c
===================================================================
--- grass-addons/grass7/raster/r.mcda.promethee/promethee.c 2015-09-13 13:28:35 UTC (rev 66191)
+++ grass-addons/grass7/raster/r.mcda.promethee/promethee.c 2015-09-13 20:42:44 UTC (rev 66192)
@@ -9,7 +9,8 @@
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,
+ double **net_flow_vol);
/*
@@ -50,7 +51,8 @@
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,
+ double **net_flow_vol)
{
int row1, col1, row2, col2;
int i;
@@ -59,14 +61,14 @@
/* make pairwise comparation and build positive flow matrix */
for (i = 0; i < ncriteria; i++)
{
- G_percent(i, (nrows*ncriteria), 2);
for (row1 = 0; row1 < nrows; row1++)
{
for (col1 = 0; col1 < ncols; col1++)
{
+ //G_percent(i, (nrows*ncriteria), 2);
for (row2 = 0; row2 < nrows; row2++)
{
- //G_percent(row2, (nrows), 2);
+ G_percent(row2, (nrows), 2);
for (col2 = 0; col2 < ncols; col2++)
{
threshold = (decision_vol[row1][col1][i] - decision_vol[row2][col2][i]);
@@ -86,20 +88,14 @@
}
}
}
- G_message("check");
- /*storage preference value in decision_vol */
-/* 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
- 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];
- }
- }
- }*/
+ for(row1 = 0; row1 < nrows; row1++)
+ {
+ for (col1 = 0; col1 < ncols; col1++)
+ {
+ positive_flow_vol[row1][col1]=positive_flow_vol[row1][col1]/ncriteria;
+ negative_flow_vol[row1][col1]=negative_flow_vol[row1][col1]/ncriteria;
+ net_flow_vol[row1][col1]=positive_flow_vol[row1][col1]-negative_flow_vol[row1][col1];
+ }
+ }
}
More information about the grass-commit
mailing list