Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
675 views
in Technique[技术] by (71.8m points)

linear programming - I'd like to use attributes of r function at Rcpp

This is my cpp code.. using lp function (with lpSolve package)

I'd like to assign the 'solution' attribute of lp results.

which is the part of "lp(~~~)$solution[2]" in bellow code.

Is there any way to pass that results in cpp??

Thank u in advance.

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
NumericVector po_adj(NumericVector prpsd_po, NumericVector pred_ord, NumericVector dmlt_po, NumericVector pred_stock, NumericVector last_avgord, NumericVector pred_ords, NumericVector len, NumericVector ld_time, NumericVector obj_1, NumericVector obj_2, NumericVector obj_3) {
  
  Environment base("package:lpSolve");
  Function lp = base["lp"];
  
  Environment base2("package:base");
  Function comb = base2["c"];
  Function matrix = base2["matrix"];
  
  int n = min(len)+1;
  NumericVector adj_PO(n);
  adj_PO[0]=prpsd_po[0];
  
  for(int i=0; i < n; i++) {
    int k = ld_time[i];
    int a;
    int b;
    int c;
    int rhs;
 
    ...
    
    prpsd_po[i+1] = lp(_["direction"] = "min"
                      ,_["objective.in"] = comb(a-c,b)
                      ,_["const.mat"] = matrix(comb(0,1)
                                              ,_["nrow"]=1)
                      ,_["const.dir"] = ">="
                      ,_["const.rhs"] = comb(0,rhs))$solution[2];  <--- this makes error maybe..
  }
  return adj_PO;
}
question from:https://stackoverflow.com/questions/65952624/id-like-to-use-attributes-of-r-function-at-rcpp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...