mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
core: update solveLP() interface
This commit is contained in:
@@ -90,18 +90,20 @@ static void swap_columns(Mat_<double>& A,int col1,int col2);
|
||||
#define SWAP(type,a,b) {type tmp=(a);(a)=(b);(b)=tmp;}
|
||||
|
||||
//return codes:-2 (no_sol - unbdd),-1(no_sol - unfsbl), 0(single_sol), 1(multiple_sol=>least_l2_norm)
|
||||
int solveLP(const Mat& Func, const Mat& Constr, Mat& z){
|
||||
int solveLP(InputArray Func_, InputArray Constr_, OutputArray z_)
|
||||
{
|
||||
dprintf(("call to solveLP\n"));
|
||||
|
||||
//sanity check (size, type, no. of channels)
|
||||
CV_Assert(Func.type()==CV_64FC1 || Func.type()==CV_32FC1);
|
||||
CV_Assert(Constr.type()==CV_64FC1 || Constr.type()==CV_32FC1);
|
||||
CV_Assert((Func.rows==1 && (Constr.cols-Func.cols==1))||
|
||||
(Func.cols==1 && (Constr.cols-Func.rows==1)));
|
||||
if (!z.empty())
|
||||
CV_CheckTypeEQ(z.type(), CV_64FC1, "");
|
||||
else
|
||||
CV_CheckType(z.type(), z.type() == CV_64FC1 || z.type() == CV_8UC1/*empty cv::Mat*/, "");
|
||||
CV_Assert(Func_.type()==CV_64FC1 || Func_.type()==CV_32FC1);
|
||||
CV_Assert(Constr_.type()==CV_64FC1 || Constr_.type()==CV_32FC1);
|
||||
CV_Assert((Func_.rows()==1 && (Constr_.cols()-Func_.cols()==1))||
|
||||
(Func_.cols()==1 && (Constr_.cols()-Func_.rows()==1)));
|
||||
if (z_.fixedType())
|
||||
CV_CheckType(z_.type(), z_.type() == CV_64FC1 || z_.type() == CV_32FC1 || z_.type() == CV_32SC1, "");
|
||||
|
||||
Mat Func = Func_.getMat();
|
||||
Mat Constr = Constr_.getMat();
|
||||
|
||||
//copy arguments for we will shall modify them
|
||||
Mat_<double> bigC=Mat_<double>(1,(Func.rows==1?Func.cols:Func.rows)+1),
|
||||
@@ -129,7 +131,7 @@ int solveLP(const Mat& Func, const Mat& Constr, Mat& z){
|
||||
}
|
||||
|
||||
//return the optimal solution
|
||||
z.create(c.cols,1,CV_64FC1);
|
||||
Mat z(c.cols,1,CV_64FC1);
|
||||
MatIterator_<double> it=z.begin<double>();
|
||||
unsigned int nsize = (unsigned int)N.size();
|
||||
for(int i=1;i<=c.cols;i++,it++){
|
||||
@@ -140,6 +142,7 @@ int solveLP(const Mat& Func, const Mat& Constr, Mat& z){
|
||||
}
|
||||
}
|
||||
|
||||
z.copyTo(z_);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user