Complementarity problem's solution is invalid

23 views
Skip to first unread message

s.dar...@gmail.com

unread,
Oct 4, 2017, 10:41:03 AM10/4/17
to AMPL Modeling Language
I'm using amplpy, and setting up the following model to solve a simple LCP:


        set Rn;


        param B {Rn,Rn} default 0;
        param q {Rn} default 0;

        var x {j in Rn};

        s.t. f {i in Rn}:
                0 <= x[i]
             complements
                sum {j in Rn} B[i,j]*x[j]
                 >= -q[i];



I'm solving it via pathampl, which confirms that 

 ** EXIT - solution found.
Major Iterations. . . . 0
Minor Iterations. . . . 0
Restarts. . . . . . . . 0
Crash Iterations. . . . 1
Gradient Steps. . . . . 0
Function Evaluations. . 2
Gradient Evaluations. . 2
Basis Time. . . . . . . 0.012745
Total Time. . . . . . . 0.022692
Residual. . . . . . . . 1.830372e-08
Path 4.7.04: Solution found.
1 iterations (1 for crash); 0 pivots.
2 function, 2 gradient evaluations.


Now, let's evaluate the solution.

x = ampl.getVariable('x').getValues().toPandas().values[:, 0]
BB = ampl.getParameter('B').getValues().toPandas().values
BB = BB.reshape((n, n))
qq = ampl.getParameter('q').getValues().toPandas().values[:, 0]

# second part of complementarity problem: Bx +q >= 0
ineq2 = BB.dot(x) + q 

# first part is trivially: x >= 0

# so, either x =0 or ineq2 =0  opr both, so it's necessary that the product is zero, which is not the case:

(ineq2 * x).min()
Out[18]: -4478.5662322322232
(ineq2 * x).max()
Out[19]: 4487.1317370994529


Have I set up my model incorrectly?

Robert Fourer

unread,
Oct 5, 2017, 2:36:34 PM10/5/17
to am...@googlegroups.com
As a first troubleshooting step, I would check the results that you get from the following command, executed immediately after solving with PATH:

ampl.eval('display {i in Rn} (x[i], sum {j in Rn} B[i,j]*x[j]+q[i]);')

In each row of the resulting AMPL display table, at least one of the two entries should be zero; if one entry is a tiny value like 1e-9 that is within typical solver tolerances for zero, that is also OK. If this test fails then it will be necessary to focus on what's happening with PATH and AMPL, while if this test succeeds then the focus should be on your Python API program.

Bob Fourer
am...@googlegroups.com

=======
Reply all
Reply to author
Forward
0 new messages