Minor fixes

Request to comments on pull request for simplex method. In particular
*) while(1) is replaced with for(;;)
*) if(true){...} constructions in tests are replaced with #if 1 ...
 #endif
This commit is contained in:
Alex Leontiev 2013-07-30 04:14:36 +03:00
parent 52b250f466
commit 3013ad6624
2 changed files with 15 additions and 15 deletions

View File

@ -208,7 +208,7 @@ static int initialize_simplex(Mat_<double>& c, Mat_<double>& b,double& v,vector<
static int inner_simplex(Mat_<double>& c, Mat_<double>& b,double& v,vector<int>& N,vector<int>& B,vector<unsigned int>& indexToRow){ static int inner_simplex(Mat_<double>& c, Mat_<double>& b,double& v,vector<int>& N,vector<int>& B,vector<unsigned int>& indexToRow){
int count=0; int count=0;
while(1){ for(;;){
dprintf(("iteration #%d\n",count)); dprintf(("iteration #%d\n",count));
count++; count++;

View File

@ -4,7 +4,7 @@
TEST(Optim_LpSolver, regression_basic){ TEST(Optim_LpSolver, regression_basic){
cv::Mat A,B,z,etalon_z; cv::Mat A,B,z,etalon_z;
if(true){ #if 1
//cormen's example #1 //cormen's example #1
A=(cv::Mat_<double>(3,1)<<3,1,2); A=(cv::Mat_<double>(3,1)<<3,1,2);
B=(cv::Mat_<double>(3,4)<<1,1,3,30,2,2,5,24,4,1,2,36); B=(cv::Mat_<double>(3,4)<<1,1,3,30,2,2,5,24,4,1,2,36);
@ -13,9 +13,9 @@ TEST(Optim_LpSolver, regression_basic){
std::cout<<"here z goes\n"<<z<<"\n"; std::cout<<"here z goes\n"<<z<<"\n";
etalon_z=(cv::Mat_<double>(3,1)<<8,4,0); etalon_z=(cv::Mat_<double>(3,1)<<8,4,0);
ASSERT_EQ(cv::countNonZero(z!=etalon_z),0); ASSERT_EQ(cv::countNonZero(z!=etalon_z),0);
} #endif
if(true){ #if 1
//cormen's example #2 //cormen's example #2
A=(cv::Mat_<double>(1,2)<<18,12.5); A=(cv::Mat_<double>(1,2)<<18,12.5);
B=(cv::Mat_<double>(3,3)<<1,1,20,1,0,20,0,1,16); B=(cv::Mat_<double>(3,3)<<1,1,20,1,0,20,0,1,16);
@ -24,9 +24,9 @@ TEST(Optim_LpSolver, regression_basic){
std::cout<<"here z goes\n"<<z<<"\n"; std::cout<<"here z goes\n"<<z<<"\n";
etalon_z=(cv::Mat_<double>(2,1)<<20,0); etalon_z=(cv::Mat_<double>(2,1)<<20,0);
ASSERT_EQ(cv::countNonZero(z!=etalon_z),0); ASSERT_EQ(cv::countNonZero(z!=etalon_z),0);
} #endif
if(true){ #if 1
//cormen's example #3 //cormen's example #3
A=(cv::Mat_<double>(1,2)<<5,-3); A=(cv::Mat_<double>(1,2)<<5,-3);
B=(cv::Mat_<double>(2,3)<<1,-1,1,2,1,2); B=(cv::Mat_<double>(2,3)<<1,-1,1,2,1,2);
@ -35,13 +35,13 @@ TEST(Optim_LpSolver, regression_basic){
std::cout<<"here z goes\n"<<z<<"\n"; std::cout<<"here z goes\n"<<z<<"\n";
etalon_z=(cv::Mat_<double>(2,1)<<1,0); etalon_z=(cv::Mat_<double>(2,1)<<1,0);
ASSERT_EQ(cv::countNonZero(z!=etalon_z),0); ASSERT_EQ(cv::countNonZero(z!=etalon_z),0);
} #endif
} }
TEST(Optim_LpSolver, regression_init_unfeasible){ TEST(Optim_LpSolver, regression_init_unfeasible){
cv::Mat A,B,z,etalon_z; cv::Mat A,B,z,etalon_z;
if(true){ #if 1
//cormen's example #4 - unfeasible //cormen's example #4 - unfeasible
A=(cv::Mat_<double>(1,3)<<-1,-1,-1); A=(cv::Mat_<double>(1,3)<<-1,-1,-1);
B=(cv::Mat_<double>(2,4)<<-2,-7.5,-3,-10000,-20,-5,-10,-30000); B=(cv::Mat_<double>(2,4)<<-2,-7.5,-3,-10000,-20,-5,-10,-30000);
@ -50,26 +50,26 @@ TEST(Optim_LpSolver, regression_init_unfeasible){
std::cout<<"here z goes\n"<<z<<"\n"; std::cout<<"here z goes\n"<<z<<"\n";
etalon_z=(cv::Mat_<double>(3,1)<<1250,1000,0); etalon_z=(cv::Mat_<double>(3,1)<<1250,1000,0);
ASSERT_EQ(cv::countNonZero(z!=etalon_z),0); ASSERT_EQ(cv::countNonZero(z!=etalon_z),0);
} #endif
} }
TEST(Optim_LpSolver, regression_absolutely_unfeasible){ TEST(Optim_LpSolver, regression_absolutely_unfeasible){
cv::Mat A,B,z,etalon_z; cv::Mat A,B,z,etalon_z;
if(true){ #if 1
//trivial absolutely unfeasible example //trivial absolutely unfeasible example
A=(cv::Mat_<double>(1,1)<<1); A=(cv::Mat_<double>(1,1)<<1);
B=(cv::Mat_<double>(2,2)<<1,-1); B=(cv::Mat_<double>(2,2)<<1,-1);
std::cout<<"here A goes\n"<<A<<"\n"; std::cout<<"here A goes\n"<<A<<"\n";
int res=cv::optim::solveLP(A,B,z); int res=cv::optim::solveLP(A,B,z);
ASSERT_EQ(res,-1); ASSERT_EQ(res,-1);
} #endif
} }
TEST(Optim_LpSolver, regression_multiple_solutions){ TEST(Optim_LpSolver, regression_multiple_solutions){
cv::Mat A,B,z,etalon_z; cv::Mat A,B,z,etalon_z;
if(true){ #if 1
//trivial example with multiple solutions //trivial example with multiple solutions
A=(cv::Mat_<double>(2,1)<<1,1); A=(cv::Mat_<double>(2,1)<<1,1);
B=(cv::Mat_<double>(1,3)<<1,1,1); B=(cv::Mat_<double>(1,3)<<1,1,1);
@ -80,13 +80,13 @@ TEST(Optim_LpSolver, regression_multiple_solutions){
std::cout<<"here z goes\n"<<z<<"\n"; std::cout<<"here z goes\n"<<z<<"\n";
ASSERT_EQ(res,1); ASSERT_EQ(res,1);
ASSERT_EQ(z.dot(A),1); ASSERT_EQ(z.dot(A),1);
} #endif
} }
TEST(Optim_LpSolver, regression_cycling){ TEST(Optim_LpSolver, regression_cycling){
cv::Mat A,B,z,etalon_z; cv::Mat A,B,z,etalon_z;
if(true){ #if 1
//example with cycling from http://people.orie.cornell.edu/miketodd/or630/SimplexCyclingExample.pdf //example with cycling from http://people.orie.cornell.edu/miketodd/or630/SimplexCyclingExample.pdf
A=(cv::Mat_<double>(4,1)<<10,-57,-9,-24); A=(cv::Mat_<double>(4,1)<<10,-57,-9,-24);
B=(cv::Mat_<double>(3,5)<<0.5,-5.5,-2.5,9,0,0.5,-1.5,-0.5,1,0,1,0,0,0,1); B=(cv::Mat_<double>(3,5)<<0.5,-5.5,-2.5,9,0,0.5,-1.5,-0.5,1,0,1,0,0,0,1);
@ -97,5 +97,5 @@ TEST(Optim_LpSolver, regression_cycling){
std::cout<<"here z goes\n"<<z<<"\n"; std::cout<<"here z goes\n"<<z<<"\n";
ASSERT_EQ(z.dot(A),1); ASSERT_EQ(z.dot(A),1);
//ASSERT_EQ(res,1); //ASSERT_EQ(res,1);
} #endif
} }