Originally posted by: SystemAdmin
[marcello said:]
I had the same problem today,
it seems that I succeded using a presolveCallback
1) I created a presolve callback
[color=blue]class myCallbackI : public IloCplex::PresolveCallbackI
{
public:
IloNum NRemCols, NRemRows, NAggrs, NModCoeffs;
IloCplex::CallbackI* duplicateCallback() const{
return (new (getEnv()) myCallbackI(*this));
}
myCallbackI(IloEnv env) : IloCplex::PresolveCallbackI(env), NAggrs(0), NModCoeffs(0), NRemCols(0), NRemRows(0) {}
void main();
};
IloCplex::Callback preCallback(IloEnv env)
{
return (IloCplex::Callback(new (env) myCallbackI(env)));
}[/color]
2) then I created the main function. Since the presolveCallback is continuously called during the presolve phase, I built the main function to update the number of aggregations, modified coefficients, removed columns and rows every time it is called.
[color=blue]void myCallbackI::main()
{
this->NAggrs = (this->getNaggregations()>this->NAggrs) ? this->getNaggregations(): this->NAggrs;
this->NModCoeffs = (this->getNmodifiedCoeffs()>this->NModCoeffs) ? this->getNmodifiedCoeffs(): this->NModCoeffs;
this->NRemCols = (this->getNremovedCols()>this->NRemCols) ? this->getNremovedCols(): this->NRemCols;
this->NRemRows = (this->getNremovedRows()>this->NRemRows) ? this->getNremovedRows(): this->NRemRows;
}[/color]
3) In the code, I add the callback to the cplex instance and created a pointer to the presolveCallback
[color=blue]IloCplex::Callback cb = cplex.use(preCallback(env));
myCallbackI* mcb = (myCallbackI*) cb.getImpl();[/color]
4) After the model has been solved, through the pointer I can access the last value of the presolve variables in the callback:
[color=blue]cout << "NAggrs=" << mcb->NAggrs << endl;<br />cout << "NModCoeffs=" << mcb->NModCoeffs << endl;<br />cout << "NRemCols=" << mcb->NRemCols << endl;<br />cout << "NRemRows=" << mcb->NRemRows << endl;[/color]<br />
Maybe it is not so elegant but it works.
Please feel free to add any comment to improve it, in particular I don't like the explicit casting too much.
Marcello
#CPLEXOptimizers#DecisionOptimization