Originally posted by: **FizzaCees**

Hello.

I am trying to maximize a function that involves a negatively impacting term, Q:

Max (A - B - C .. - Q);

Where, A, B, C .. Q are different terms in the objective function that are dependent on decision variables. **x1, x2, ... xn** (non-negative)I also have the initial positions for the decision variables represented by **p1,p2, ... pn** and constant values **c1,c2, ... cn.**

As per my understanding, whether **c** is positive or negative I have split the decision variables **vector x** into two groups **(Positive set** and **Negative set)** and calculated the following:

P = sum(j in Postive set)

mypwl(pj -xj) *cj

N = sum(j in Negative set)

mypwl(pj -xj) *cj

Q is defined as:

Q = P+N + Switch;

Where, **mypwl** is a piece-wise function defined as follows:

pwlFunction mypwl=piecewise{0->0; 0->0; 1};

Intuitively, I would like to penalize the positive values under all circumstances, and give preference to negative values or **"switch them off"** under specific circumstances (e.g. sum of P and N is less than zero)

Here, **Switch** is a decision variable which can either be zero OR equal to **- N**, bounded through constraints as follows:

constraint_1 :(P+N >= 0) => (Switch == 0);

constraint_2 :!(P+N >= 0) => (Switch == -N); //(negation constraint)

I am trying to continue to penalize positive values but stop the preference for negative values when **N>P** (this is achieved through **constraint_2**).

However, this seems to be an incorrect implementation of the problem I am trying to model. To explain this, let's go over an example :

If N= -400 and P =200

then

Q = 200 +(-400) + 400 = 200

Increasing the value of **P** will increase the value of **Q** until **P>N** at which point the switch will revert to a value of 0 and **Q** = 401 -400 =1.

This would incentivize the optimization to target a **Q** value of 0 rather than letting the expressions **A,B, C** .. take control of the optimization.

I believe the implementation can be improved by fixing the value of **N** when **P==N,** rather than using switch however I am unsure as to how one can achieve this. Please advise on how to achieve this, any alternate solution to achieve the same outcome would also be greatly appreciated.

Thanks in advance!

#DecisionOptimization#MathematicalProgramming-General