1

有谁知道任何可以解决线性约束数学模型的简单求解器?示例一个简单的模型:

a + b + c = 100;
a/b/c = 2/3/4;
a > d

我正在使用 MS Solver 基础,这是我的 C# 代码,但它抛出 UnsolvableModelException:

        SolverContext solverContext = SolverContext.GetContext();
        Model model = solverContext.CreateModel();
        Decision a = new Decision(Domain.Real, "a");
        Decision b = new Decision(Domain.Real, "b");
        model.AddDecisions(a, b);
        model.AddConstraint("fator", a / b ==  4);
        model.AddConstraint("sum", a + b == 5);
        Solution solution = solverContext.Solve(new ConstraintProgrammingDirective());
        Report report = solution.GetReport();
        Console.WriteLine("a = {0} ; b = {1}", a, b);

谢谢你的帮助

编辑:

因为 int CSP(constraint sstisfaction programming) 问题,解决它时不应该使用任何指令。代码应该是:

    SolverContext solverContext = SolverContext.GetContext();
    Model model = solverContext.CreateModel();
    Decision a = new Decision(Domain.Real, "a");
    Decision b = new Decision(Domain.Real, "b");
    model.AddDecisions(a, b);
    model.AddConstraint("fator", a / b ==  4);
    model.AddConstraint("sum", a + b == 5);
    Solution solution = solverContext.Solve();
    Report report = solution.GetReport();
    Console.WriteLine("a = {0} ; b = {1}", a, b);

但是,我不知道为什么我跑得很慢我只需要解决方案集中的第一个解决方案。

4

1 回答 1

1

根据您的需要,Wolfram Alpha 可能有用(至少用于验证)。我怀疑你能解决复杂的问题,因为输入是有限的。但是对于像你这样的简单问题,没关系。

http://www.wolframalpha.com/input/?i=solve+a+%2B+b+%2B+c+%3D%3D+100%3B+a%2Fb+%3D%3D+2%2F3%3B+b %2Fc%3D%3D3%2F4%3B+a+%3E+d

替代文字

于 2010-11-26T04:20:39.840 回答