开发者

Rewrite max using two and statements

Say I want t开发者_如何学Goo 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);


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.

?


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


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


Is B non-negative? Then MAX is the infinity-norm, since you're allowed multiplication you can approximate this:

A*A*A*A*A*A <= B*B*B*B*B*B + 100*100*100*100*100*100

If the six-norm isn't a good enough approximation for the infinity-norm, add more terms.

Also, the linked solution can be adapted, and MIP is not even necessary:

A <= B + M1
A <= 100 + M2
M1*M2 <= 0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜