[Coin-discuss] arithmetic exception when using Cbc

Kish Shen kish.shen at crosscoreop.com
Thu Nov 2 12:58:52 EST 2006


On Thursday 02 November 2006 17:27, Matthew Saltzman wrote:
> On Thu, 2 Nov 2006, Kish Shen wrote:
> 
> > Hi,
> >
> > I am getting an arithmetic exception when using Cbc/Clp through OsiClp. 
> > The crash happens in CbcModel.cpp, in gcd (line 84 in the copy I am 
> > using):
> >
> >  while (remainder) {
> >    remainder = b % a;
> >    b = a;
> >    a = remainder;
> >  }
> >  return b;
> >
> > The crash happens  in doing the % operation, I assume because a = -1.
> 
> Seems like an arithmetic exception should be easy to find.  Do you know 
> what the args are that cause the crash?  What arch is this on?
> 
The problem was run on 32 bit x86 Linux. 

By args do you mean the values of b, a etc.? Here are the values:
 (gdb) p b
$1 = -2147483648
(gdb) p a
$2 = -1
(gdb) p remainder
$3 = -1

I guess b looks like it might be wrong. The gcd is called from line 346 of CbcModel.cpp:

      for (iColumn = 0 ; iColumn < numberColumns ; iColumn++)
      { if (upper[iColumn] > lower[iColumn]+1.0e-8)
	{ if (isInteger(iColumn)&&objective[iColumn])
	  { double value = fabs(objective[iColumn])*multiplier ;
	    int nearest = (int) floor(value+0.5) ;
	    if (fabs(value-floor(value+0.5)) > 1.0e-8)
	    { increment = 0 ;
	      break ; }
	    else if (!increment)
	    { increment = nearest ; }
	    else
	    { increment = gcd(increment,nearest) ; } } } } <---

(gdb) p objective[27]
$8 = 12512501.125
(gdb) p multiplier
$9 = 2520

and the objective coeff for objective[27] does look correct -- this is the range of values 
that is assigned to the objective coefficients.
 
By the way, this is with the latest development branch of Cbc. I have managed to fix the problem
I mentioned in my last post, and got the same problem now with this latest Cbc.


> One thing about / and % in C (resp. C++) is that they are ambiguous.  The 
> standard requires that (a/b) * b + a % b = a, but it does not require that 
> a % b >= 0, Some architectures return negative remainders if the dividend 
> or divisor is negative.
> 
> On SPARC, for example, -4 % -6 == -4, -4 % 6 == -4, 4 % -6 == 4.
> 
> Not sure what the context for calls to gcd() is here, but it's worth 
> paying attention to for a general-purpose gcd().
> 
> BTW, any reason not to move gcd() from Cbc to CoinUtils?  It seems like a 
> generally useful thing to not have to recode.
>

I will try the problem on Sparc as well to see what happens...

Cheers,

Kish
 
> >
> > This is within a call to a call to CbcModel's branchAndBound().
> >
> > I am using Cbc/Clp as an MP solver for the Constraint Logic Programming 
> > Language ECLiPSe, for which I am providing an interface. The original 
> > problem occurs in a program of one of our users, and it happens after 
> > repeated solving and modification of the problem.
> >
> > I have extracted the C/C++ calls to Osi/Cbc that reproduce this problem 
> > without ECLiPSe. The file is quite big, nearly 300K in size, so I am not 
> > including it with this message.
> >
> > I get this error with a copy of the development branch of Cbc I 
> > donwloaded on 2006-08-17. I have just tried to run the same code with 
> > the latest development branch which I downloaded today (2006-11-02), but 
> > the program aborts much earlier. I haven't been able to look at why this 
> > happens yet.
> >
> > Does this problem look like it might be something that I am doing wrong, 
> > or something that might have been fixed since August?
> >
> > I guess John Forrest might be interested in looking at the code that 
> > give this problem. Do please let me know, and I can send the code to 
> > you.
> >
> > Thanks in advance for any information and help!
> >
> > Kish Shen
> >
> >
> > _______________________________________________
> > Coin-discuss mailing list
> > Coin-discuss at list.coin-or.org
> > http://list.coin-or.org/mailman/listinfo/coin-discuss
> >
> 



More information about the Coin-discuss mailing list