双约束优化 [英] optimalization with double constraint

查看:92
本文介绍了双约束优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我是使用VB和MSF的新手。有人能帮助我吗?我非常绝望......

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

我需要在约束中使用sqrt函数。

I need to use sqrt function in constraint.

在Excel中使用Excel解算器解决同样的问题(使用Excel解算器)罚款。

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

Excel文件:

http://wikisend.com/download/380264/excel solver.xlsx

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()

但是有错误:  "Microsoft.SolverFoundation.Services.Term"类型的值无法转换为"Double"。

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

推荐答案

Hi Michal,

Hi Michal,

您应该将Math.Sqrt更改为Model.Sqrt。 Math.Sqrt是内置的.Net函数,Model.Sqrt是构建模型时应该使用的Solver Foundation函数。

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


这篇关于双约束优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆