2
$\begingroup$

I am trying to work out an if else statement for the following problem, which should be mathematically linear programmed:

when both item 1 and item 2 are picked, both their costs are reduced with 20%. I have more items than only item 1 and 2, and there costs never change. if only one of item 1 or 2 are picked, there regular costs will be implemented.

I thought of the following, however I don't know how to rewrite it in a way it is mathematical and thus not contains any ifs and whens:

$C_i$: reduced cost of item $i$ for $i \in \{1,2\}$

$K_i$: regular cost of item $i$ for $i \in \{1,2,3,4\}$

$X_i$: whether or not item $i$ is picked for $i \in \{1,2,3,4\}$

the sum of $X_i C_i$ should be smaller than or equal to $1300$

$C_1 = 0.8K_1$ if $X_1+X_2=2$

$C_2= 0.8K_2$ if $X_1+X_2=2$

$C_i=K_i$ for $i\in \{3,4\}$

Is there anyone who can help me with this?

$\endgroup$
1
  • 1
    $\begingroup$ For some basic information about writing mathematics at this site see, e.g., here, here, here and here. $\endgroup$ Commented Jun 14, 2022 at 9:43

3 Answers 3

3
$\begingroup$

Normally in these cases we use an auxiliar variable that takes values $\{0,1\}$. Thus we add the variable $\delta \in \{0,1\}$ that is $1$ if both items are bought and $0$ otherwise. Add the corresponding price to the objective function times $\delta$ and you should be done.

$\endgroup$
1
$\begingroup$

I agree with @Gowexx that you should use a binary variable $Y_{1,2}$. To enforce this, try using these constraints:

$$Y_{1,2} \ge (X_1 + X_2)-(Y_1 + Y_2)$$ $$Y_{1,2} \ge X_1 - Y_1$$ $$Y_{1,2} \ge X_2 - Y_2$$ $$|Y_1-X_2| =0$$ $$|Y_2-X_1| =0$$ $$Y_1,Y_2,X_1,X_2 \in \{0,1\}$$ $$Y_{1,2} \in \{0,2\}$$

$Y_1$ and $Y_2$ are used to account for one of the $X$'s being $0$ and the other being $1$. If one of the $X$'s is not turned on, the corresponding $Y$ will turn on and turn the RHS of Constraint 1 to 0. If both are turned on, RHS should be 2.

$\endgroup$
1
$\begingroup$

\begin{align} \sum_{i=1}^4 K_i X_i - 0.2(K_1+K_2)Y &\le 1300 \\ Y &\le X_1 \\ Y &\le X_2 \end{align}

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.