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:
http://wikisend.com/download/380264/excel solver.xlsx
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.AddDecisions(A, B, C) model.AddConstraints("A_con", A >= 0) model.AddConstraints("B_con", B >= 0) model.AddConstraints("C_con", C >= 0) model.AddConstraints("ABC_con", A + B + C = 1) model.AddConstraints("max_con", (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) model.AddGoals("cil", GoalKind.Maximize, 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
- Edited by Michal Janata Friday, April 06, 2012 12:44 PM
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 Nate Brixius Sunday, April 08, 2012 2:05 AM

