-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do variables need to be greater than zero? #3
Comments
I have a LP problem in matlab code is:
I have sole this by matlab function
setup A, b and c to sdlp_example and then run : ➜ build git:(main) ✗ make
[ 50%] Building CXX object CMakeFiles/sdlp_example.dir/example/sdlp_example.cpp.o
[100%] Linking CXX executable sdlp_example
[100%] Built target sdlp_example
➜ build git:(main) ✗ ./sdlp_example
optimal sol: 0.155327 0.426713 0.6981 0.6981 1.20496
u: -0.193773 0.0776133 0.349 0.349
optimal obj: -1.20496 get the solution:
the optimal obj is the same, but B*u_SDLP != v, u != u_SDLP. why? @ZhepeiWang the sdlp_example code is #include <iostream>
#include "sdlp/sdlp.hpp"
using namespace std;
using namespace Eigen;
int main(int argc, char **argv)
{
// int m = 2 * 7;
int m = 10;
Eigen::Matrix<double, 5, 1> x; // decision variables
Eigen::Matrix<double, 5, 1> c; // objective coefficients
Eigen::Matrix<double, -1, 5> A(m, 5); // constraint matrix
Eigen::VectorXd b(m); // constraint bound
A << -0.4440, 0, 0.4440, 0, -0.2000,
0, -0.4440, 0, 0.4440, -0.1000,
0.2070, 0.2070, 0.2070, 0.2070, -0.1000,
0.4440, 0, -0.4440, 0, 0.2000,
0, 0.4440, 0, -0.4440, 0.1000,
-0.2070, -0.2070, -0.2070, -0.2070, 0.1000,
1.0000, 0, 0, 0, 0,
0, 1.0000, 0, 0, 0,
0, 0, 1.0000, 0, 0,
0, 0, 0, 1.0000, 0;
b <<0, 0, 0.2890, 0, 0, -0.2890, 0.6981, 0.6981, 0.6981, 0.6981;
c << 0.0, 0.0, 0.0, 0.0, -1.0;
double minobj = sdlp::linprog<5>(c, A, b, x);
Eigen::Matrix<double, 4, 1> u_={x(0)-0.3491, x(1)-0.3491, x(2)-0.3491, x(3)-0.3491};
Eigen::Matrix<double, 4, 1> u=u_;
if(minobj>=1)
{
for(int i=0;i<4;i++)
{
u(i)=u_(i)/minobj;
}
}
std::cout << "optimal sol: " << x.transpose() << std::endl;
std::cout << "u: " << u.transpose() << std::endl;
std::cout << "optimal obj: " << minobj << std::endl;
return 0;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usually, the standard form of linear programming requires variables to be greater than zero. Does this constraint need to be integrated into the A matrix?
The text was updated successfully, but these errors were encountered: