I am trying to solve an mixed integer problem with CVXR in R. Following code is used to solve it:
n <- 6
beta <- Variable(n, n, integer = TRUE)
epsilon <- 0.1*10^-5
objective <- Minimize(1)
constraints <- list(beta >= 1,
beta <= 9,
abs(diff(beta)) >= epsilon,
abs(diff(t(beta))) >= epsilon)
prob <- Problem(objective, constraints)
CVXR_result <- solve(prob)
This gives the following error:
Error in construct_intermediate_chain(object, candidate_solvers, gp = gp) :
Problem does not follow DCP rules.
When I change the code into following code:
n <- 6
beta <- Variable(n, n, integer = TRUE)
epsilon <- 0.1*10^-5
objective <- Minimize(1)
constraints <- list(beta >= 1,
beta <= 9,
abs(diff(beta)) <= epsilon,
abs(diff(t(beta))) <= epsilon)
prob <- Problem(objective, constraints)
CVXR_result <- solve(prob)
CVXR_result$status
CVXR_result$value
cvxrBeta <- CVXR_result$getValue(beta)
cvxrBeta
It works, but these are not the constraints that I want.
Does anyone know how to solve this?
We can convexivy the problem by introducing a boolean matrix
ysuch thaty[i,j]is 1 if the i,jth inequality ondiff(beta)is greater-than and 0 otherwise. Similarlyyy[i,j]is 1 if the i,jth inequality ondiff(t(beta))is greater-than and 0 otherwise. Thus we have added 2*(n-1)*n boolean variables. Also setMto 9 and to avoid numerical difficulties setepsilonto 0.1. For more information see: https://math.stackexchange.com/questions/37075/how-can-not-equals-be-expressed-as-an-inequality-for-a-linear-programming-model/1517850