Forum Discussion
FICO
1 year agoCommunity Manager
Mapping methods between XPRBctr and new class Inequality
I'm porting a Java application to c++ (I'm using latest Xpress Version). From guide I understood that XPRBctr old BCL class has been mapped to Inequality, but I cannot find some methods (i.e. addTerm...
FICO
1 year agoCommunity Manager
Sorry, for the late reply. It is probably best to look at the examples that ship in the examples/solver/optimizer/cxx/objects directory and at the introduction here.
The way to build a linear constraint in the C++ API involves these steps:
- Create expressions for the left-hand side and right-hand side.
- Use relational operators to turn this into an inequality definition.
- Use XpressProblem::addConstraint() to add this as a constraint. This function returns a handle to the newly added constraint, an instance of xpress::objects::Inequality.
- You can then later change coefficients in this constraint (directly in the matrix) use the chgCoef(), chgCoefs() and setRhs() functions of class Inequality.
Here is a short example:
#include <xpress.hpp>
#include <xpress_objects.hpp>
using namespace xpress::objects;
int
main(void)
{
XpressProblem prob;
auto x = prob.addVariables(3).toArray();
Expression lhs = x[0] + 2*x[1]; // Create expression for left-hand side.
Expression rhs = x[2] + 4; // Create expression for right-hand side.
auto def = lhs <= rhs; // Create constraint _definition_.
Inequality i = prob.addConstraint(def); // Create an actual constraint from the definition.
prob.writeProb("p1.lp"); // LP file has: R1: C1 + 2 C2 - C3 <= 4
i.chgCoef(x[1], 3); // Modify the constraint.
prob.writeProb("p2.lp"); // LP file has: R1: C1 + 3 C2 - C3 <= 4
return 0;
}Related Content
Related Content
Variable object mapping issue in Python Callbacks with Presolve enabled
Hi, I am implementing a Branch-and-Cut algorithm using the Xpress Python interface. I have structured my code as a class where I create variables (using xp.var) and store them in a dictionary attrib...8 months agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum6 unread comments6 unread1View0likes6CommentsA specific separation procedure, $(l,S)$ Inequalities, to solve the lot-sizing problem
Dear support team, I have tried to use a specific separation procedure, $(l, S)$ Inequalities, to solve the lot-sizing problem proposed in the references, like Algorithm and formulations for lot siz...8 months agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum4 unread comments4 unread5Views0likes4CommentsQuestion about GetBasis method?
Hi, I have a question about the GetBasis method.problem.getbasis (fico.com) I made a console application with c#(as below) to test it. sol = 10, rowStatus = 2 and colStatus = 1. Why rowStatus is ...4 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum4 unread comments4 unread0Views0likes4Comments