I'm working with a statistical linear model where I have a variable, ( N ), representing the percentage of charging of a battery. Based on ( N ), I derive another variable, Charging_level, with the following conditions:

- If \( N = 0 \), `Charging_level = 0`.
- If \( 0 < N \leq 20 \), `Charging_level = 1`.
- If \( 20 < N \leq 40 \), `Charging_level = 2`.
- If \( 40 < N \leq 80 \), `Charging_level = 3`.
- If \( 80 < N \leq 100 \), `Charging_level = 4`.

I have 4 distinct levels of charging: 1, 2, 3, and 4. The statiscal model use indicator variables (coefficients per level), where one level is set to 1 and the others are set to 0, and hence can provide prediction.

I should note that I am optimizing over N (tradeoff between charging to full and other budget constraints), I'm seeking an efficient way to represent the Charging_level variable. I've come across the Big-M method, which I know is used for basic if-else conditions, but I'm unsure how to apply it to my scenario with multiple levels.

Is there a straightforward method for representing this multi-level categorical variable using the Big-M method? Or are there alternative approaches that might be more suitable?


1 Answer 1


Introduce a small constant tolerance $\epsilon>0$ and five binary decision variables $z_0,\dots,z_4$, and impose linear constraints \begin{align} \sum_{i=0}^4 z_i &=1 \\ 0z_0+\epsilon z_1+(20+\epsilon)z_2+(40+\epsilon)z_3+ (80+\epsilon)z_4 \le N &\le 0z_0+20z_1+40z_2+80z_3+ 100z_4 \\ \sum_{i=0}^4 i z_i &=\text{Charging_level} \end{align}

  • $\begingroup$ This models both implications, right ? (e.g., $N=0 \iff \mbox{charging_level}=0$) $\endgroup$
    – Kuifje
    Aug 8 at 7:42
  • $\begingroup$ @Kuifje Yes, and that is how I interpreted the desired rule. $\endgroup$
    – RobPratt
    Aug 8 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.