2

I am trying to use SWI-Prolog simplex library to solve a linear system of equations with the set of real numbers as domain. Would anyone please have a clue why the following query does not succeed?

maximize(
[],
state(
 0,
 [],
 [ 
   c(0,
    [- 0.95*x(3),0.05*x(0),0.05*x(1),0.05*x(2)],
    =,
    1479754163278877r9007199254740992),
   c(0,
    [0.95*x(2),- 0.05*x(0),- 0.05*x(1),- 0.05*x(3)],
    =,
    185786871969449310676024028079063r3975352282315727403093661252059136
   ),
   c(0,
    [0.95*x(1),- 0.05*x(0),- 0.05*x(2),- 0.05*x(3)],
    =,
    756128230024134313216574233897861r15901409129262909612374645008236544
   ),
   c(0,
    [0.95*x(0),- 0.05*x(1),- 0.05*x(2),- 0.05*x(3)],
    =,
    294112628726237r72057594037927936
   )
 ],
 []
),
S).

The system I intend to solve is the following:

0.05*x(0)+0.05*x(1)+0.05*x(2)-0.95*x(3)
= 
1479754163278877/9007199254740992

- 0.05*x(0)- 0.05*x(1)+0.95*x(2)- 0.05*x(3) 
=
185786871969449310676024028079063/3975352282315727403093661252059136

- 0.05*x(0)+0.95*x(1)- 0.05*x(2)- 0.05*x(3)
=
756128230024134313216574233897861/15901409129262909612374645008236544

0.95*x(0)- 0.05*x(1)- 0.05*x(2)- 0.05*x(3)
=
294112628726237/72057594037927936

Alternatively, would you please know a better way to solve this in Prolog?

David Tonhofer
  • 14,559
  • 5
  • 55
  • 51
catbow
  • 85
  • 9
  • Likely the simplex solver assumes all variables are non-negative. Could that be tripping you up? – Erwin Kalvelagen Jan 05 '21 at 18:47
  • thanks for the suggestion! it seems only the right hand side of constraints must be non-negative https://www.swi-prolog.org/pldoc/man?predicate=constraint/3 – catbow Jan 05 '21 at 19:26
  • I see: " In the current implementation, all variables are implicitly constrained to be non-negative. This may change in future versions, and non-negativity constraints should therefore be stated explicitly." – Erwin Kalvelagen Jan 05 '21 at 19:33
  • Thanks a lot, well spotted! would you please know a more appropriate way to solve this kind of linear systems of equations with Prolog? – catbow Jan 05 '21 at 22:28
  • I don't know much about SWI-Prolog and this package (so no clue about other linear system solvers), but the LP formulation may be salvageable by "variable splitting". Too long to explain in a comment, but this will allow you to reformulate the original problem in terms of just non-negative variables. – Erwin Kalvelagen Jan 06 '21 at 15:39

1 Answers1

2

It looks like the solver assumes all variables are non-negative. So the question becomes: can we reformulate Ax=b, where x are free variables, into something that uses non-negative variables? The answer is: yes. Using a technique called variable splitting we can replace each x(j) by xplus(j)-xmin(j) where xplus(j),xmin(j)>=0. So the system of equations becomes:

  sum(j, a(i,j)*(xplus(j)-xmin(j))) = b(i)   for all i
  xplus(j),xmin(j)>=0
       

We may need to make sure that only one of the pair (xplus(j),xmin(j)) can become nonzero. This may hold automatically as the basis matrix B will become singular if both are in the basis. But we also can set an objective that handles this:

  min sum(j, xplus(j)+xmin(j))

As long as the system of equations has a feasible solution, the objective will make sure that only one of (xplus(j),xmin(j)) is nonzero.

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39