문제

A solver project I am working on (C#) requires to test if there is a solution, regardless of quality, or not to a problem where some of the inputs fall within some pre-defined range of real numbers.

I put together the following example that contains one constraint representing a simple equality test between a value (a Parameter type) and an equation comprised of two variables (Decision types).

        const double DESIRED_OUTPUT_VALUE = -2.5;

        SolverContext solver = SolverContext.GetContext();
        Model model = solver.CreateModel();

        //Defined a value to be tested against
        Parameter output = new Parameter(Domain.Real, "output");
        output.SetBinding(DESIRED_OUTPUT_VALUE);

        //Defined a range between 1 & 10 for the input variables.
        Domain inputDomain = Domain.RealRange(1, 10);
        Decision inputA = new Decision(inputDomain, "inputA");
        Decision inputB = new Decision(inputDomain, "inputB");

        model.AddDecision(inputA);
        model.AddDecision(inputB);
        model.AddParameter(output);

        //The constraint, which given the value of output currently is not solvable.
        Constraint constraint = model.AddConstraint("result", output == inputA / inputB);

        /*Expected that the solver would report back quickly that this is no feasable solution.
         *However instead it just sits there with a blank screen... 
         */
        Solution solution = solver.Solve();
        Report report = solution.GetReport();
        Console.WriteLine(report);
        Console.ReadLine();

What I have observed is that if the constraint is changed so that that there is no solution, and the equation represented therein is a division or multiplication, the solver seems to stall, not giving any feedback as to whether it is still solving or not.

I suspect this stalling-like behaviour is to do with the fact the solver is dealing with real numbers and is in the midst of some exhaustive search, however if the constraint is altered so that there is a known solution it works very quickly.

Having scoured various forums I am still not sure what could be causing this behaviour or, given this is my first experience using Microsoft Solver Foundation, if my implementation approach is the correct one to take.

Has anyone else experienced this issue or indeed has a solution?

d.

도움이 되었습니까?

해결책

The solver that is chosen by Solver Foundation depends on a number of factors. A big factor is how you use the Decisions in your goals and constraints. In this case, you are dividing two decisions, which means that a very general solver needs to be used.

You'll have much better success if you can write your model so that the goals and constraints are linear in the Decision objects. I realize this is not always possible, but in this specific case, it can: change output == inputA / inputB to inputB * output == inputA.

I think this should help. Nate

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top