fork download
  1. // Paste into an online Java IDE as Main.java and run.
  2. // Verifies infeasibility of the LP:
  3. // min z = -3 x1 + x2
  4. // s.t. x1 - 2 x2 >= 2
  5. // -x1 + x2 >= 3
  6. // x1, x2 >= 0
  7. public class Main {
  8. static boolean feasible(double x1, double x2) {
  9. return x1 >= 0 && x2 >= 0
  10. && (x1 - 2*x2 >= 2 - 1e-12)
  11. && (-x1 + x2 >= 3 - 1e-12);
  12. }
  13.  
  14. public static void main(String[] args) {
  15. System.out.println("LP to check:");
  16. System.out.println(" minimize z = -3 x1 + x2");
  17. System.out.println(" subject to x1 - 2 x2 >= 2");
  18. System.out.println(" -x1 + x2 >= 3");
  19. System.out.println(" x1, x2 >= 0");
  20. System.out.println();
  21.  
  22. // 1) Algebraic proof (one-line contradiction)
  23. System.out.println("Algebraic check:");
  24. System.out.println(" Add the two >= constraints:");
  25. System.out.println(" (x1 - 2x2) + (-x1 + x2) >= 2 + 3 => -x2 >= 5 => x2 <= -5");
  26. System.out.println(" But bounds require x2 >= 0. Contradiction.");
  27. System.out.println(" ==> The LP is INFEASIBLE.");
  28. System.out.println();
  29.  
  30. // 2) Small brute-force sanity check over a grid (non-proof, just confirmation)
  31. boolean anyFeasible = false;
  32. double bestZ = Double.POSITIVE_INFINITY, bestX1 = Double.NaN, bestX2 = Double.NaN;
  33.  
  34. // scan a modest grid to illustrate there are no feasible points
  35. for (int i1 = 0; i1 <= 50; i1++) {
  36. for (int i2 = 0; i2 <= 50; i2++) {
  37. double x1 = i1 * 0.5; // step 0.5
  38. double x2 = i2 * 0.5;
  39. if (feasible(x1, x2)) {
  40. anyFeasible = true;
  41. double z = -3*x1 + x2;
  42. if (z < bestZ) {
  43. bestZ = z; bestX1 = x1; bestX2 = x2;
  44. }
  45. }
  46. }
  47. }
  48.  
  49. if (!anyFeasible) {
  50. System.out.println("Brute-force grid confirmation: no feasible points found on a 0.5 grid in [0,25]^2.");
  51. System.out.println("Conclusion: INFEASIBLE.");
  52. } else {
  53. System.out.printf("Found feasible point (unexpected): x1=%.4f, x2=%.4f, z=%.4f%n", bestX1, bestX2, bestZ);
  54. }
  55. }
  56. }
  57.  
  58.  
Success #stdin #stdout 0.09s 52644KB
stdin
Standard input is empty
stdout
LP to check:
  minimize  z = -3 x1 + x2
  subject to x1 - 2 x2 >= 2
             -x1 + x2 >= 3
             x1, x2 >= 0

Algebraic check:
  Add the two >= constraints:
    (x1 - 2x2) + (-x1 + x2) >= 2 + 3  =>  -x2 >= 5  =>  x2 <= -5
  But bounds require x2 >= 0. Contradiction.
  ==> The LP is INFEASIBLE.

Brute-force grid confirmation: no feasible points found on a 0.5 grid in [0,25]^2.
Conclusion: INFEASIBLE.