Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

Solving linear system of equations with Prolog library Simplex

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...