|
Hi, how can we modify the coefficients of a constraint (extractable) in a model ( Code to give details: Step 1) Adding a constraint: IloRangeArray c1(env);
c1.add(IloRange(env, -IloInfinity, -1.0));
for(int I=0;I < NumVar; I++)
c1[0].setLinearCoef(Var[I],-1);
model.add(c1);
c1.end();
Now how to modify the coefficients of the constraint, just added, by using the object " [Edit: X-Post @ IBM ILOG Optimization Forums: How to modify the coefficients of constraints already added in Ilomodel]
showing 5 of 6
show all
|
|
I don't know why you're using an IloRangeArray for a single range, but that really does not matter. IloModel::add returns the handle of the added object; store it somewhere, after casting it back to IloRange or IloRangeArray as appropriate (I think the return value is IloExtractable). Do not invoke end() on the stored value. (I'm not sure it's safe to end() c1, either. It is safe to reinitialize c1 later.) If you know what modifications you want to do, just use IloRange::setLinearCoefficient on each constraint to be modified. Iterating is only necessary if you do not know which variables appear in the constraint, and need to scan the constraint to find them. Sir, Thanks for the answer and editing the post. This method also works i.e. do not invoke end() and use IloRange::setLinearCoefficient to modify a constraint. Note: we should not end() c1 if any modification has to be done.
(Feb 14 at 20:20)
MBansal
|

Hi, @MBansal, I'm not actually sure whether we have a (strict anti-)cross-posting policy here on OR-X; let's assume for a second: we don't have such thing. So I'd recommend to repost your question here, too. [It's good style to paste a link to that repost in your question here, though.]
Obviously I don't make the rules here, but I am reasonable sure we recommend using software specific forums for such related questions, though you will possibly get a qualified answer here too.
I pasted the question literally into a google search, and the first hit looks good to me, but see @Florian's comment below.
@Marco: If I'm getting this right, the question here is: Can you extract an
IloRangeobject from anIloModelinstance [to callIloRange::setLinearCoef]? @Paul Rubin has authored two blog posts (here and here) that address this problem (accessing model components using an iterator), but [these] require you to have access to theIloCplexinstance - Warning: Java!@MBansal: This said, & IANAE - in anything,
IloModel::Iteratorgrants access toIloExtractableobjects; if those represent constraints,IloExtractable::asConstraintreturns the correspondingIloConstraintobject, let's call it "cons". From here,IloRangeI* impl = dynamic_cast<IloRangeI *>(cons.getImpl()); IloRange rng(impl);should take you where you want to get. [You want to read this and this for further details.]Thank you to all of you for your time and the replies. @fbahr, using dynamic_cast I can now extract an IloRange object from an IloModel instance. Also, the links, you shared, were very helpful. Thanks a lot!