-1

I'm getting an exception

"Cannot implicitly convert type 'Microsoft.SolverFoundation.Services.Term' to 'bool'"

in the following code:

double T1;
Decision T4;

var XX3 = T1 > (T4 - 0.001) ? T4 - 0.001 : T1;

How it is possible to fix this problem?

  • 1
    I am using Microsoft SolverFoundation. Decision is a class. http://msdn.microsoft.com/en-us/library/microsoft.solverfoundation.services.decision(v=vs.93).aspx – user3362850 Jun 02 '14 at 07:07
  • You're hiding something. In your code I can't see where is `Microsoft.SolverFoundation.Services.Term` used? – Sriram Sakthivel Jun 02 '14 at 07:07
  • @SonerGönül: I don't think that's the problem, as it says it cannot convert to "bool" not to "double". The only bool thing here is the left hand side of the ? operator, which compares doubles here. – PMF Jun 02 '14 at 07:07
  • I have a method: public static Term SKPK(double T1, Decision T4) {var XX3 = T1 > (T4 - 0.001) ? T4 - 0.001 : T1; ......} – user3362850 Jun 02 '14 at 07:09
  • @SriramSakthivel [`Decision`](http://msdn.microsoft.com/en-us/library/microsoft.solverfoundation.services.decision.aspx) derives from `Term`. What he didn't show was the namespace `Microsoft.SolverFoundation.Services`, but it is in the error text. – Jeppe Stig Nielsen Jun 02 '14 at 07:54

1 Answers1

0

You use overloads of subtraction and greater than that have a return type Microsoft.SolverFoundation.Services.Term (see links). Then you use that expression x as the first part (of three) in the conditional operator x ? a : b. But a bool is required there.


I suggest you use Model.If instead, it appears to be Solver Foundation's "conditional operator". To be technical, the C# language does not allow overloading the ?: ternary operator the way many binary operators like - and > can be overloaded.

So change:

var XX3 = T1 > (T4 - 0.001) /* illegal! */ ? T4 - 0.001 : T1;

into:

var XX3 = Model.If(T1 > T4 - 0.001, T4 - 0.001, T1);

Disclaimer: I am not a Solver Foundation user.

Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181