1
#include <RcppArmadillo.h>
2

3
using namespace Rcpp;
4
using namespace arma;
5

6
// [[Rcpp::depends(RcppArmadillo)]]
7
// [[Rcpp::export]]
8

9 2
arma::imat matdom(NumericMatrix A, bool map, bool benefit) {
10 2
  arma::mat B=as<arma::mat>(A);
11 2
  int n=B.n_rows;
12
  // int m=B.n_cols;
13
  bool status;
14 2
  arma::mat Asort(n,n,fill::zeros);
15 2
  arma::imat dom(n,n,fill::zeros);
16 2
  arma::rowvec tmpi(n);
17 2
  arma::rowvec tmpj(n);
18 2
  arma::rowvec check(n); 
19 2
  if(map){
20 2
    Asort=arma::sort(B,"descend",1);
21
  }
22 2
  int c=1;
23 2
  if(!benefit){
24 2
     c=-1;
25
  }
26 2
  for(int i = 0; i < n; ++i) {
27 2
    for(int j = 0; j < n; ++j) {
28 2
      if(i!=j){
29 2
        if(!map){
30 2
          tmpi=c*B.row(i);
31 2
          tmpj=c*B.row(j);
32 2
          tmpi[i]=c;
33 2
          tmpi[j]=c;
34 2
          tmpj[i]=c;
35 2
          tmpj[j]=c;
36 2
          check=tmpi-tmpj;
37 2
          status = arma::all(check<=0);
38 2
          if(status){
39 2
            dom(i,j)=1;
40
          }
41
        } else{
42 2
          tmpi=c*Asort.row(i);
43 2
          tmpj=c*Asort.row(j);
44 2
          check=tmpi-tmpj;
45 2
          status = arma::all(check<=0);
46 2
          if(status){
47 2
            dom(i,j)=1;
48
          }
49
        }
50

51
      }
52
    }
53
  }
54 2
  return dom;
55
}

Read our documentation on viewing source code .

Loading