2

I'm new to the LPSolve and the toolkit. I'm trying to use the LPSolve IDE to stitch 4 image 1024x1024 tiles. To simplify the task, I use only the x coordinates of the tiles.

    -------------------------------
   | Tile1         |Tile2          |
   |               |               |
   |               |               |
   |               |               |
   --------------------------------
   | Tile3         | Tile4         |
   |               |               |
   |               |               |
   |               |               |
   --------------------------------

If I define the relationships in the following way

   min: +d1 +d3 +d4 +d6;

   -x1 +x2 -1024 +d1 <=0.1;
   -x1 +x2 -1024 +d1 >=-0.1;
   -x1 +x3 +1    +d2 <=0.1;
   -x1 +x3 +1    +d2 >=-0.1;
   -x2 +x4       +d3 <=0.1;
   -x2 +x4       +d3 >=-0.1;
   -x3 +x4 -1024 +d4 <=0.1;
   -x3 +x4 -1024 +d4 >=-0.1;
   x1=1024;
   x2=2048;
   x3=1023;
   x4=2047;

The LPSolve produces a correct result

   d1=0
   d2=0
   d3=0.900000000000091
   d4=0
   x1=1024
   x2=2048
   x3=1023
   x4=2047

If I change the model to the following, i.e. move the Tile4 by one pixel

   min: +d1 +d2 +d3 +d4;

   -x1 +x2 -1024 +d1 <=0.1;
   -x1 +x2 -1024 +d1 >=-0.1;
   -x1 +x3 +1    +d2 <=0.1;
   -x1 +x3 +1    +d2 >=-0.1;
   -x2 +x4       +d3 <=0.1;
   -x2 +x4       +d3 >=-0.1;
   -x3 +x4 -1024 +1 +d4 <=0.1;
   -x3 +x4 -1024 +1 +d4 >=-0.1;
   x1=1024;
   x2=2048;
   x3=1023;
   x4=2047;

the LPSolve responds with "model is INFEASIBLE", while, I think the respond should be

 d1=1
   d2=0
   d3=0.900000000000091
   d4=1

What am I doing wrong?

Ram Narasimhan
  • 22,341
  • 5
  • 49
  • 55

1 Answers1

0

You are running into scaling issues. lpsolve has lots of them.

You can see that for yourself, if you make a small change: I replaced the values for x3 and x4 in the last two constraints:

 min: +d1 +d3 +d4 +d2;

   -x1 +x2 - 1024 +d1 <=0.1;
   -x1 +x2 - 1024 +d1 >=-0.1;
   -x1 +x3 +1    +d2 <=0.1;
   -x1 +x3 +1    +d2 >=-0.1;
   -x2 +x4      +d3 <=0.1;
   -x2 +x4       +d3 >=-0.1;
   -1023 + 2047  -1024 + 1 + d4 <= 0.1;
   -1023 +  x4   -1024 + 1 + d4 >=-0.1;
   x1=1024;
   x2=2048;
   x3=1023;
   x4=2047;

You get this warning/error:

initialize_solution: Invalid rebounding; variable 10 at refact 0, iter 0
check_solution: Variable   d4 =                  0 is above its upper bound               -0.9

Seriously low accuracy found ||*|| = 0.9 (rel. error 0.473684)
lp_solve failed

Whereas, when I try substituting myself:

 min: +d1 +d3 +d4 +d2;

   -x1 +x2 - 1024 +d1 <=0.1;
   -x1 +x2 - 1024 +d1 >=-0.1;
   -x1 +x3 +1    +d2 <=0.1;
   -x1 +x3 +1    +d2 >=-0.1;
   -x2 +x4      +d3 <=0.1;
   -x2 +x4       +d3 >=-0.1;
//   -1023 + 2047  -1024 + 1 + d4 <= 0.1;
//   -1023 +  x4   -1024 + 1 + d4 >=-0.1;
  d4 <= 0.1;
  d4 >-0.1;
   x1=1024;
   x2=2048;
   x3=1023;
   x4=2047;

We get a solution and there is no infeasibility:

Actual values of the variables:
d1                              0
d3                            0.9
d4                           -0.1
d2                              0
x1                           1024
x2                           2048
x3                           1023
x4                           2047

This link tells you what's going on.

Quoting from the last line there:

Conclusion. You should always do some sort of scaling. It starts when you design the model. Extra scaling can be accomplished by one of the scaling options of lp_solve.

Hope that helps.

Ram Narasimhan
  • 22,341
  • 5
  • 49
  • 55