jump-dev / Pajarito.jl

A solver for mixed-integer convex optimization
Mozilla Public License 2.0
131 stars 22 forks source link

failure case for exponential cone #368

Closed mlubin closed 6 years ago

mlubin commented 7 years ago
using Pajarito, MathProgBase, CPLEX, ECOS

# min -t
# s.t. (t,s,r)     ∈ Exp
#      1/2 - t - s ≥ 0
# s Binary

c = [-1.0,0.0,0.0]
A = [1.0 1.0 0.0]
b = [0.5]
constr_cones = [(:NonNeg,1:1)]
var_cones = [(:ExpPrimal,1:3)]

function solve(solver)

    m = MathProgBase.ConicModel(solver)
    MathProgBase.loadproblem!(m, c, A, b, constr_cones, var_cones)
    MathProgBase.setvartype!(m, [:Cont,:Bin,:Cont])
    MathProgBase.optimize!(m)
    stat = MathProgBase.status(m)
    x_sol = MathProgBase.getsolution(m)
    objval = MathProgBase.getobjval(m)

    @show stat
    @show x_sol
    @show objval
end

solve(PajaritoSolver(mip_solver=CplexSolver(CPX_PARAM_SCRIND=0),prim_cuts_only=true,solve_relax=false,solve_subp=false))
solve(PajaritoSolver(mip_solver=CplexSolver(CPX_PARAM_SCRIND=0),cont_solver=ECOSSolver(verbose=0),prim_cuts_assist=false))

Primal only happy returns an infeasible solution

Iter. | Best feasible  | Best bound     | Rel. gap    | Time (s)   
    1 |  -5.000000e-01 |  -5.000000e-01 |   0.000e+00 |   4.680e+00

Iterative algorithm summary:
 - Status               =        Optimal
 - Best feasible        =  -5.000000e-01
 - Best bound           =  -5.000000e-01
 - Relative opt. gap    =      0.000e+00
 - Total time (s)       =       4.72e+00

stat = :Optimal
x_sol = [0.5,0.0,4.0]
objval = -0.5

Subp only returns an infeasibile solution but reports issues:

Iter. | Best feasible  | Best bound     | Rel. gap    | Time (s)   
    1 |  -5.000000e-01 |  -4.827854e-01 |  -3.443e-02 |   2.096e+00
WARNING: Solution value (-0.5) is smaller than best bound (-0.4827854111813981): check solution feasibility (tightening primal feasibility tolerance of conic solver may help)

Iterative algorithm summary:
 - Status               =        Optimal
 - Best feasible        =  -5.000000e-01
 - Best bound           =  -4.827854e-01
 - Relative opt. gap    =*    -3.443e-02*
 - Total time (s)       =       2.10e+00

Timers (s):
 - Setup                =   3.19e-01
 -- Transform data      =   4.42e-05
 -- Create conic data   =   3.19e-01
 -- Create MIP data     =   6.41e-05
 - Algorithm            =   1.78e+00
 -- Solve relaxation    =   1.09e+00
 -- Get relaxation cuts =   6.02e-01
 -- Solve MIP models    =   8.09e-04
 -- Solve subproblems   =   3.18e-04
 -- Get subproblem cuts =   5.04e-02
 -- Get primal cuts     =   7.83e-06

Counters:
 - Iterations           =     1
 -- Integer repeats     =     0
 -- Conic subproblems   =     1
 --- Infeasible         =     0
 --- Optimal            =     1
 --- Suboptimal         =     0
 --- UserLimit          =     0
 --- ConicFailure       =     0
 --- Other status       =     0
 -- Feasible solutions  =     2
 --- From subproblems   =     1
 --- From MIP solve     =     1

Solution returned by MIP solver

Outer-approximation cuts added:
Cone             | Relax.    | Violated  | Nonviol. 
   Primal expon. |         0 |         1 |         0

0 numerically unstable cone duals encountered

Distance to feasibility (negative indicates strict feasibility):
Cone             | Variable  | Constraint
          Linear |        NA | -0.00e+00

Distance to integrality of integer/binary variables:
          binary |  0.00e+00

stat = :Optimal
x_sol = [0.5,0.0,4.0]
objval = -0.5

First thing is to fix the feasibility detection, second is to add the new separation cuts.

mlubin commented 7 years ago

When s < tol_zero then I would take the feasibility to be the violation of t <= 0.

chriscoey commented 7 years ago

OK I will try that. If I can get it to return a correct answer, should I add it to the tests?

mlubin commented 7 years ago

Yes, this problem should be in the unit tests.

chriscoey commented 7 years ago

should i just hard-code in a constant the zero tolerance we use for the s in the exp cone?

mlubin commented 7 years ago

Hard-coding 1e-10 should be fine until we have some reason to make it a parameter.

mlubin commented 7 years ago

Well, it should be closer to the solver's integrality tolerance, maybe 1e-6.

chriscoey commented 7 years ago

ok, so 1e-6 for now

chriscoey commented 7 years ago

Now the output for subp cuts alg is:

Starting iterative algorithm
(r_dual,s_dual,t_dual) = (-19975.384522011205,437327.4118080733,2.2806266823598686e-6)

Iter. | Best feasible  | Best bound     | Rel. gap    | Time (s)   
    1 |  -1.232274e-08 |  -4.827854e-01 |       >1000 |   8.269e-03
WARNING: Repeated integer solution without converging

Iter. | Best feasible  | Best bound     | Rel. gap    | Time (s)   
    2 |  -1.232274e-08 |  -4.827854e-01 |       >1000 |   1.003e-02
WARNING: Pajarito failed to converge to the desired relative gap; try turning off the MIP solver's presolve functionality

Iterative algorithm summary:
 - Status               =     Suboptimal
 - Best feasible        =  -1.232274e-08
 - Best bound           =  -4.827854e-01
 - Relative opt. gap    =      4.822e+04
 - Total time (s)       =       1.04e-02

Timers (s):
 - Setup                =   4.19e-04
 -- Transform data      =   1.10e-04
 -- Create conic data   =   2.29e-04
 -- Create MIP data     =   8.07e-05
 - Algorithm            =   9.95e-03
 -- Solve relaxation    =   1.31e-03
 -- Get relaxation cuts =   6.48e-06
 -- Solve MIP models    =   2.10e-03
 -- Solve subproblems   =   4.69e-04
 -- Get subproblem cuts =   1.61e-04
 -- Get primal cuts     =   7.53e-06

Counters:
 - Iterations           =     2
 -- Integer repeats     =     1
 -- Conic subproblems   =     1
 --- Infeasible         =     0
 --- Optimal            =     1
 --- Suboptimal         =     0
 --- UserLimit          =     0
 --- ConicFailure       =     0
 --- Other status       =     0
 -- Feasible solutions  =     1
 --- From subproblems   =     1
 --- From MIP solve     =     0

Solution returned by conic solver

Outer-approximation cuts added:
Cone             | Relax.    | Violated  | Nonviol. 
   Primal expon. |         0 |         1 |         0

0 numerically unstable cone duals encountered

Distance to feasibility (negative indicates strict feasibility):
Cone             | Variable  | Constraint
          Linear |        NA | -5.00e-01
   Primal expon. |  1.23e-08 |        NA

Distance to integrality of integer/binary variables:
          binary |  0.00e+00

stat = :Suboptimal
x_sol = [1.23227e-8,0.0,18.1137]
objval = -1.2322744242737645e-8
-1.2322744242737645e-8
chriscoey commented 7 years ago

when scaling is turned off:

Starting iterative algorithm
(r_dual,s_dual,t_dual) = (-0.9999999838736358,21.893315959633913,1.1417185201459285e-10)

Iter. | Best feasible  | Best bound     | Rel. gap    | Time (s)   
    1 |  -1.232274e-08 |  -4.827854e-01 |       >1000 |   6.862e-02
WARNING: Repeated integer solution without converging

Iter. | Best feasible  | Best bound     | Rel. gap    | Time (s)   
    2 |  -1.232274e-08 |  -4.827854e-01 |       >1000 |   7.001e-02
WARNING: Pajarito failed to converge to the desired relative gap; try turning off the MIP solver's presolve functionality

Iterative algorithm summary:
 - Status               =     Suboptimal
 - Best feasible        =  -1.232274e-08
 - Best bound           =  -4.827854e-01
 - Relative opt. gap    =      4.822e+04
 - Total time (s)       =       7.03e-02

Timers (s):
 - Setup                =   7.78e-04
 -- Transform data      =   5.35e-05
 -- Create conic data   =   5.74e-04
 -- Create MIP data     =   1.50e-04
 - Algorithm            =   6.95e-02
 -- Solve relaxation    =   1.78e-03
 -- Get relaxation cuts =   1.23e-05
 -- Solve MIP models    =   1.53e-03
 -- Solve subproblems   =   3.71e-04
 -- Get subproblem cuts =   1.52e-04
 -- Get primal cuts     =   6.78e-06

Counters:
 - Iterations           =     2
 -- Integer repeats     =     1
 -- Conic subproblems   =     1
 --- Infeasible         =     0
 --- Optimal            =     1
 --- Suboptimal         =     0
 --- UserLimit          =     0
 --- ConicFailure       =     0
 --- Other status       =     0
 -- Feasible solutions  =     1
 --- From subproblems   =     1
 --- From MIP solve     =     0

Solution returned by conic solver

Outer-approximation cuts added:
Cone             | Relax.    | Violated  | Nonviol. 
   Primal expon. |         0 |         1 |         0

0 numerically unstable cone duals encountered

Distance to feasibility (negative indicates strict feasibility):
Cone             | Variable  | Constraint
          Linear |        NA | -5.00e-01
   Primal expon. |  1.23e-08 |        NA

Distance to integrality of integer/binary variables:
          binary |  0.00e+00
chriscoey commented 7 years ago

using cut_zero_tol=1e-8 and rounding to 0 rather than discarding the cut:

solve(PajaritoSolver(mip_solver=CplexSolver(CPX_PARAM_SCRIND=0),cont_solver=ECOSSolver(verbose=0),prim_cuts_assist=false,cut_zero_tol=1e-8,log_level=3))
...
Starting iterative algorithm

Iter. | Best feasible  | Best bound     | Rel. gap    | Time (s)   
    1 |  -1.232274e-08 |  +0.000000e+00 |  -1.231e-03 |   2.467e+00
WARNING: Solution value (-1.2322744242737645e-8) is smaller than best bound (0.0): check solution feasibility (tightening primal feasibility tolerance of conic solver may help)
Pajarito will print diagnostic information

Iterative algorithm summary:
 - Status               =        Optimal
 - Best feasible        =  -1.232274e-08
 - Best bound           =  +0.000000e+00
 - Relative opt. gap    =*    -1.231e-03*
 - Total time (s)       =       2.50e+00

Timers (s):
 - Setup                =   3.47e-01
 -- Transform data      =   1.16e-04
 -- Create conic data   =   3.47e-01
 -- Create MIP data     =   7.68e-05
 - Algorithm            =   2.16e+00
 -- Solve relaxation    =   1.28e+00
 -- Get relaxation cuts =   7.06e-01
 -- Solve MIP models    =   1.56e-03
 -- Solve subproblems   =   5.61e-04
 -- Get subproblem cuts =   2.31e-02
 -- Get primal cuts     =   1.71e-05

Counters:
 - Iterations           =     1
 -- Integer repeats     =     0
 -- Conic subproblems   =     1
 --- Infeasible         =     0
 --- Optimal            =     1
 --- Suboptimal         =     0
 --- UserLimit          =     0
 --- ConicFailure       =     0
 --- Other status       =     0
 -- Feasible solutions  =     2
 --- From subproblems   =     1
 --- From MIP solve     =     1

Solution returned by conic solver

Outer-approximation cuts added:
Cone             | Relax.    | Violated  | Nonviol. 
   Primal expon. |         1 |         0 |         1

0 numerically unstable cone duals encountered

Distance to feasibility (negative indicates strict feasibility):
Cone             | Variable  | Constraint
          Linear |        NA | -5.00e-01
   Primal expon. |  1.23e-08 |        NA

Distance to integrality of integer/binary variables:
          binary |  0.00e+00

stat = :Optimal
x_sol = [1.23227e-8,0.0,18.1137]
objval = -1.2322744242737645e-8
-1.2322744242737645e-8
mlubin commented 7 years ago

Ok, that's correct.

mlubin commented 7 years ago

We can set cut_zero_tol=1e-8 when testing this example.

chriscoey commented 7 years ago

OK will add as a test. then for sep cuts only i still need to add the code for the special sep cut. and then this example should work with sep cuts only as well, so I will add that as a test also.