Click here to Skip to main content
15,920,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I managed to convert almost an entire Excel workbook to C#, especially the solvers which gave me trouble, but I solved everything except one problem on my last tab.

What I have tried:

I used "Term" to represent every formula that use in the Solvers (C#). No problem with Excel formulas with: EXP/POW/RACINE/LOG,
Math.Exp is replaced by Model.Exp.
Math.Pow by Model.Power,
Math.Sqrt by Model.Sqrt,
and Math.Log by Model.Log. (not yet tested this one, present only in my last Tab, but the compiler seems to take it well).


But I'm stuck on a formula that compares a result of another formula that contains one of my variables to find, so a Term, it compares it with a double, and the compiler doesn't like that.

It tells me: Cannot implicitly convert type 'Microsoft.SolverFoundation.Services.Term' to 'bool'

Do you have an idea ?

Thanks.

C#
    private Term Solv_P18()
    {
            Term res = null;
            if (!Var.Calc.C15)
            {
            
                if (Var.Calc.C100 < 2 * Cell_D12())
                {

                    if (Solv_M18() > Var.Calc.T100)
                    {
                        res = 2 * Cell_D12() / Solv_M18();
                    }
                    else
                    {
                        res = 2 * Cell_D12() / Var.Calc.T100;
                    }
                }
                else
                {
                    if (Solv_M18() > Var.Calc.T100)
                    {
                        res = Var.Calc.C100 / Solv_M18();
                    }
                    else
                    {
                        res = Var.Calc.C100 * Var.Calc.T100;
                    }

                }
            }
            return res;
        }

        private Term Solv_M18()
        {
            Term res = null;
            if (Cell_E18() == double.NaN)
            {
                res = Var.Calc.Tr100;
            }
            else
            {
                res = Var.Calc.Tr100 * Model.Exp(-Solv_N13() * Solv_N12() * Solver_L18);
            }
            return res;
        }
<pre>

I have 2 variables to find, Solver_L18 is one of them.

Methods Solv_N13 and Solv_N12, contain my second variable to find. So they are also "Term".
Posted
Updated 12-Jul-22 20:14pm
Comments
CHill60 11-Jul-22 11:27am    
It would have helped to share the definition of term but my first thoughts are - provide a Term.ToDouble function or a Term.CompareToDouble
Richard MacCutchan 11-Jul-22 11:42am    
Which line generates the error message?
[no name] 11-Jul-22 13:24pm    
"Term" is an abstract class; you need to determine what "derived" class you are / should be working with; if at all.

1 solution

I think I found. I said "I think", because I haven't really been able to try it yet, because I'm stuck on something else, I'm going to write a post on it. here is what i did. With Model.If


C#
if (Var.Calc.C100 < 2 * Cell_D12())
                {

                    res = Model.If(Solv_M18() > Var.Calc.T100,2 * Cell_D12() / Solv_M18(), 2 * Cell_D12() / Var.Calc.T100)
                    
                }
                else
                {
                    res = Model.If (Solv_M18() > Var.Calc.T100,Var.Calc.C100 / Solv_M18() , Var.Calc.C100 * Var.Calc.T100)

                }
 
Share this answer
 
Comments
Graeme_Grant 13-Jul-22 3:04am    
I am glad that this means something to you...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900