# Assigning conditional penalties to CVX solution

I would like to assign conditional penalties using CVX (I am operating in the R environment so using CVXR).
I am working on maximizing product x’A with x being integers (constraints: x >=0, sum(x) <=n) and A a vector of real value.
I would also like to impose a penalty p conditional on the values of a x’B product.
I will try to provide a simple example but my problem is more complex as it involves several conditional penalties (x’B, x’C, x’D etc…).
Ex: A is a vector (90,95,97.5,100) B is a vector (0.5,0.25,0.75,1)
I would like to assign penalties involving x such as if x’B >=3 then penalty p=5 else penalty p=0.
My objective would then be to Maximize(x’A-p).
Any direction would be greatly appreciated if a solution is available using CVX.

CVXR is a CVX-inspired package running under R, which is a different tool than CVX, which runs under MATLAB, and is the subject of this forum. It is kind of confusing that CVX’s website is at the domain cvxr.com (which predates the CVXR package).

Per the CVXR FAQ at https://cvxr.rbind.io/cvxr_faq/#gen-help 2

``````    Where can I go for help?

Please post questions to the cvx tag on StackOverflow 3.
``````

It’s interesting that there is just a “generic” cvx tag at Stack Overflow, rather than one specific to CVXR, but that’s what the CVXR FAQ says, so follow those instructions.

Thank you Mark.
I will try the Stack Overflow but that forum is relatively low on answering questions.
Out of the 100+ questions asked there are > 60% unanswered ones.
I was wondering if there are ways to specify conditional penalties to begin with even if with MATLAB.
If this is feasible then I can continue searching for a way but if this is not even possible then I might go to the alternate approach I came up with which is using a heuristic search algorithm (but relatively slow and I believe I am hitting local maxima rather than global maxima).

Search for `logic constraints` on Operations Research Stack Exchange. That should allow you to produce a formulation in any MIDCP tool, such as CVXR, CVX, CVXPY.

https://docs.mosek.com/modeling-cookbook/mio.html#implication-of-positivity and/or other sections in this chapter but essentially with binary variables you can model a discontinuous step function.

Thank you both @Mark_L_Stone and @Michal_Adamaszek for the suggestions.
I will consult both resources.