Thanks a lot for your reply, your code is inspiring to me, and I've figured it out.
But now I have another problem. When I try to
read the constant term in the objective function of a MIQP problem, I.e. miqpex1.lp, the getConstant() function fails to read the value. In order to prove the correctness of the code, I use it to read the constant term of a SOCP model, that is ilosocpex1.lp, the program outputs the correct value 0. I checked a lot of official documents, but still can't figure out why.
See the program in obj_test.cpp
Please refer to miqpex1.lp for the MIQP model
See ilosocpex1.lp for the SOCP model
A Example of the function call:
obj_test miqpex1.lp
Looking forward to your reply
------------------------------
Musheng Li
------------------------------
Original Message:
Sent: Mon January 10, 2022 05:20 AM
From: Vincent Beraudier
Subject: How to get access to the coefficient matrix in a QCQP model that already been built in the C++ API?
Hello, I think it would be something like
void iterate(IloExpr::QuadIterator it){ while (it.ok()) { IloNum c = it.getCoef(); IloNumVar v1 = it.getVar1(); IloNumVar v2 = it.getVar2(); std::cout << c << "*" << v1 << "*" << v2 << "\n"; ++it; }}void iterate(IloModel model){ for (IloModel::Iterator it(model); it.ok(); ++it) { IloExtractable ext = *it; if (ext.isObjective()) { IloObjective o = ext.asObjective(); IloExpr::QuadIterator it = o.getQuadIterator(); std::cout << " ===== start obj ====\n"; iterate(it); std::cout << " ===== end obj ====\n"; } else if (ext.isConstraint()) { IloConstraint c = ext.asConstraint(); if (c.getImpl()->isType(IloRangeI::GetTypeInfo())){ IloRange r = (IloRangeI*)c.getImpl(); IloExpr::QuadIterator it = r.getQuadIterator(); std::cout << " ===== start range ====\n"; iterate(it); std::cout << " ===== end range ====\n"; } } }}
------------------------------
Vincent Beraudier
Original Message:
Sent: Wed January 05, 2022 02:55 AM
From: Musheng Li
Subject: How to get access to the coefficient matrix in a QCQP model that already been built in the C++ API?
Hi Everyone,
I am solving a Quadratic Programming Problem with Quadratic Constraints (QCQP) with CPLEX using C++ API. Currently, I am struggling with getting access to the coefficient matrix in a model that has already been built. The objective function of the model is quadratic, and the constraints include Second-order cone programming (SOCP) constraints, Quadratic constraints, and linear constraints.
And I have the following ideas:
1) Use IloModel::Iterator to traverse the variables, constraints, and objectives in the model.
2) Use IloExtractable to judge their types.
I wonder if this idea is correct, and Can anyone provide a piece of C + + code for reference?
Thanks in advance!
------------------------------
Musheng Li
------------------------------
#DecisionOptimization