optimalization with double constraint

# optimalization with double constraint

• Friday, April 06, 2012 12:41 PM

Hello,

i am new in using VB and MSF. Could someone help me? im really desperate...

I need to use sqrt function in constraint.

Solution of the same problem in Excel (using Excel Solver) works fine.

Excel file:

I tried this:

```        Dim max As Double = 0.3
Dim sm_od As Double = 0.072
Dim vyn_A As Double = 0.077
Dim vyn_B As Double = 0.054
Dim vyn_C As Double = 0.084
Dim b_A As Double = 1.151
Dim b_B As Double = 1.003
Dim b_C As Double = 1.352
Dim chyba_A As Double = 0.068
Dim chyba_B As Double = 0.085
Dim chyba_C As Double = 0.091

' MSF

Dim context As SolverContext = SolverContext.GetContext()
Dim model As Model = context.CreateModel()

Dim A As Decision = New Decision(Domain.Real, "A")
Dim B As Decision = New Decision(Domain.Real, "B")
Dim C As Decision = New Decision(Domain.Real, "C")

model.AddConstraints("ABC_con", A + B + C = 1)
(Math.Sqrt(
(b_A * A + b_B * B + b_C + C) *
(b_A * A + b_B * B + b_C + C) *
sm_od + A * chyba_A * chyba_A +
B * chyba_B * chyba_B +
C * chyba_C * chyba_C
)) <= max)

vyn_A * A + vyn_B * B + vyn_C * C)

Dim sol As Solution = context.Solve()
Dim report As Report = sol.GetReport()```

But there is error: Value of type 'Microsoft.SolverFoundation.Services.Term' cannot be converted to 'Double'.

Thanks for your replies. I appreciate any help.

Michal

### All Replies

• Sunday, April 08, 2012 2:04 AM

Hi Michal,

You should change Math.Sqrt to Model.Sqrt. Math.Sqrt is the built-in .Net function, and Model.Sqrt is the Solver Foundation function that you should use when building models.

Nate

• Proposed As Answer by Sunday, April 08, 2012 2:05 AM
•