tags:

views:

84

answers:

2

Say I want to rewrite A <= MAX (B, 100) using only AND statements and substractions. <= means smaller or equal. A and B are variables. Is it possible?

I can't seem to use OR's using the Microsoft Solver foundation in this contrived example, which is a simplification of a problem I have at work :

Decision x = new Decision(Domain.Real, "x"); model.AddDecisions(x);

        Decision y = new Decision(Domain.Real, "y");
        model.AddDecisions(y);

        // Add a constraint
        // x <= MAX(y,200);
        model.AddConstraints("zero", x + Math.Sin(44) == 33.2);
        model.AddConstraints("one", y + x == 5);
        model.AddConstraints("three", x <= -y);
        model.AddConstraints("four", x <= 200);
        // Solve the problem
        context.Solve();

        // Display the results 
        Console.WriteLine("x: {0}", x);
        Console.WriteLine("y: {0}", y);
A: 

Um, whats wrong with "NOT (A > MAX (B, 100))"?


Since MAX is not allowed, then try "NOT (x > a) And NOT (x > 100)".

RBarryYoung
Solver won't accept MAX as a function.
Andrei Tanasescu
Perhaps you should tell us what it DOES accept, since that seems to be a very short list.
RBarryYoung
AND, plus, minus, multiplication, division, equality, inequality, greater than, smaller than.
Andrei Tanasescu
Umm, I don't see "NOT" on that list. Please tell me that it's on the list ...
RBarryYoung
Actually, it's not. It only operates on variables of type boolean, and expressions such as x > a aren't (can't) be converted to boolean.
Andrei Tanasescu
Right. This is ridiculous. You'd be better off writing your own Rules Engine than spending your time trying to trick something this dysfunctional into working. And as I have written rules engines myself, I am quite serious about that.
RBarryYoung
A: 

Would this work:

  • A) Assume that B <= 100, solve for A and B. If A > 100 or B > 100, then this answer is crap.
  • B) Assume that B >= 100, solve for A and B. If B < 100, then the answer is crap.
  • C) Assert that you A) and B) do not both give the answer.
  • D) Write dozens of unit tests (or feed it an XML, etc). If an assert is ever raised, then pause and examine what is going on.

?

Hamish Grubijan