<br><font size=2 face="sans-serif">Kish,</font>
<br>
<br><font size=2 face="sans-serif">a) postprocessing deletes the solver
it is given which is why you get error in getNumCols() as that just asks
current solver how many columns it has.</font>
<br><font size=2 face="sans-serif">b) On first inspection of your code
it looks as if the solution should be back in lpd->lp->solver. One
way to check would be to put garbage in the solution before postprocess
(setColSolution) and see if it changes. If so it should be correct.</font>
<br><font size=2 face="sans-serif">c) It is more likely that - shock, horror
- there is a bug in preprocessing. I am fairly sure at least one
bug has been fixed since June. If the user can give you the problem
that fails try with cbc-stable/2.0 and cbc-trunk.</font>
<br>
<br><font size=2 face="sans-serif">John</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Kish Shen <kisshen@cisco.com></b>
</font>
<p><font size=1 face="sans-serif">11/08/2007 12:58 PM</font>
<td width=59%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td><font size=1 face="sans-serif">John J Forrest/Watson/IBM@IBMUS</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td><font size=1 face="sans-serif">cbc@list.coin-or.org</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">Re: [Cbc] getting solution to original
problem from Cbc/Clp</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><tt><font size=2>Hi John,<br>
<br>
I have not had time to look into my problem again in detail until now,
<br>
so sorry for the delay in this follow-up...<br>
<br>
John J Forrest wrote:<br>
> <br>
> Kish,<br>
> <br>
> It sounds as if you are using presolve rather than CglPreProcess.
This <br>
> could give wrong results as you describe.<br>
> <br>
> Look at Cbc/examples/sample2.cpp and try with PREPROCESS defined to
1 or <br>
> 2 to see two ways of using CglPreProcess.<br>
> <br>
> As to your questions.<br>
> <br>
> 1) The solver can in some circumstances not have an integer
solution - <br>
> bestSolution is what is needed but it must go through post processing.<br>
<br>
<br>
I think it is best if I actually show what exactly I am doing in my <br>
code. Here is a brief outline of what I do:<br>
<br>
Types of variables used:<br>
<br>
OsiClpSolverInterface * lpd->lp->Solver <--- the original
problem<br>
<br>
OsiSolverInterface * mipsolver<br>
CbcModel * lpd->lp->mipmodel<br>
CbcModel * model<br>
CglPreProcess
process<br>
<br>
1. I first preprocess the original problem:<br>
<br>
mipsolver = process.preProcess(*lpd->lp->Solver, false, 5);<br>
<br>
2. I then put this preprocessed problem into a CbcModel (unless <br>
preprocess failed, in which case I abort):<br>
<br>
lpd->lp->mipmodel = new CbcModel(static_cast<OsiSolverInterface
<br>
&>(*mipsolver));<br>
CbcModel* model = lpd->lp->mipmodel;<br>
<br>
The lpd->lp->mipmodel is to allow me to access the model later in
the <br>
code, whereas model is used locally..<br>
<br>
3. this is followed by some more optimisations etc., based on the <br>
example2 code, and then branchAndBound is called:<br>
<br>
model->branchAndBound();<br>
<br>
In some cases, the branchAndBound may time-out early, because a timeout
<br>
is set.<br>
<br>
4. the problem is post-processed (this is always done, even if the <br>
problem was timed out, or is infeasible):<br>
<br>
process.postProcess(*model->solver());<br>
<br>
looking at the comment of example2, this will put the post-processed <br>
solution back into lpd->lp->Solver. I then subsequently access this
via <br>
lpd->lp->Solver->getColSolution().<br>
<br>
My user have reported that the solution returned may sometimes be wrong
<br>
because it seems to violate some the constraints in the original <br>
problem. This is why I thought I may be returning a relaxed solution <br>
from a node in the branch and bound (e.g. when the problem was timed <br>
out), rather than the best integer solution. This is why I want to use
<br>
bestSolution to return the solution.<br>
<br>
However, bestSolution is a method for CbcModel, and not OSI, I think, <br>
and the solution in the CbcModel (the one in model in my code) is still
<br>
the preprocessed problem, rather than the original problem, even after
<br>
the postProcess call in 4. I checked this by returning the column number
<br>
for model before and after the post-processing, and it is the same (and
<br>
less than the original problem's).<br>
<br>
Is there any way I can be certain I am getting the best integer solution<br>
found by the branchAndBound, in the original problem form, rather than
<br>
the preprocessed one?<br>
<br>
In checking the column numbers, I was somewhat surprised that I got an
<br>
error in the second call to getNumCols:<br>
<br>
std::cout<< "before:"<<mipsolver->getNumCols()<<std::endl;<br>
process.postProcess(*model->solver());<br>
>>>
std::cout<< "after:"<<mipsolver->getNumCols()<<std::endl;<br>
<br>
here is the output from running this:<br>
<br>
before:16<br>
pure virtual method called<br>
after:Signal 6<br>
<br>
I am not sure this is directly related to my problem, but is this <br>
expected behaviour?<br>
<br>
I think I am using a Cbc that I download in June this year.<br>
<br>
Thanks in advance for any information/help!<br>
<br>
Cheers,<br>
<br>
Kish<br>
<br>
<br>
<br>
<br>
> 2) The result should be correct for problem with all integer variables
<br>
> fixed to correct values.<br>
> <br>
> <br>
> John Forrest<br>
> <br>
> <br>
> *Kish Shen <kisshen@cisco.com>*<br>
> Sent by: cbc-bounces@list.coin-or.org<br>
> <br>
> 10/19/2007 12:03 PM<br>
> <br>
> <br>
> To<br>
> cbc@list.coin-or.org<br>
> cc<br>
> <br>
> Subject<br>
> [Cbc]
getting solution to original problem from Cbc/Clp<br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> Hi,<br>
> <br>
> I am using CBC with CLP as the linear solver. CLP is accessed via
OSI<br>
> i.e. OsiClpSolverInterface), but CBC is accessed directly, instead
of<br>
> via OSI.<br>
> <br>
> I have been obtaining the solution state for MIP problems via the
OSI<br>
> calls, e.g. getColSolution(), getRowPrice(), etc.. One of our users<br>
> reported that some of the solution is incorrect, e.g. variables that<br>
> should be integers are not, and some constraints are violated.<br>
> <br>
> I suspected that this is because the OSI calls are via<br>
> OsiClpSolverInterface, and so I am obtaining the state from the most<br>
> recent LP relaxation, rather than the most recent MIP solution. I<br>
> therefore changed the code to obtain the solution state via Cbc calls,<br>
> for example, bestSolution() of CbcModel instead of getColSolution().<br>
> <br>
> Unfortunately, in this case, the number of columnssiz in the problem<br>
> seems to be much smaller: in one example, the original problem had
945<br>
> columns, and the MIP solution of the problem has only 205 columns.
I<br>
> assume this is because presolve reduced the problem, and bestSolution()<br>
> returns the solution for the presolved matrix.<br>
> <br>
> Questions:<br>
> <br>
> 1) Am I correct that OSIClpSolverInterface's methods, such as<br>
> getColSolution(), is returning the state from the LP relaxation, rather<br>
> than the MIP solution? [If not, then there is something wrong with
the<br>
> MIP solution produced]<br>
> <br>
> 2) How can I obtain the MIP solution state (solution values, row price,<br>
> row activity, reduced cost [and basis status for the LP relaxation
that<br>
> produced the MIP solution, if this is available], for the original<br>
> problem (and not the presolved problem)?<br>
> <br>
> Thanks in advance for any help/information!<br>
> <br>
> Cheers,<br>
> <br>
> Kish Shen<br>
> _______________________________________________<br>
> Cbc mailing list<br>
> Cbc@list.coin-or.org<br>
> http://list.coin-or.org/mailman/listinfo/cbc<br>
> <br>
> <br>
> ------------------------------------------------------------------------<br>
> <br>
> _______________________________________________<br>
> Cbc mailing list<br>
> Cbc@list.coin-or.org<br>
> http://list.coin-or.org/mailman/listinfo/cbc<br>
</font></tt>
<br>