0

Related question: Tell Wolfram Alpha that a variable is a natural number


I want to do the following in Wolfram Alpha:

Minimise

$$z = (y_1-x_1)+(x_2-y_2)+(1/2)(x_3)$$

s.t.

$$0 \le x_1 \le y_1$$

$$y_2 \le x_2 \le 2y_2$$

$$2y_3 \le x_3 \le 3y_3$$

$$y_1+y_2+y_3=1$$

$$y_1, y_2, y_3 \in \{0,1\}$$

$$x_1,x_2,x_3 \ge 0$$

It seems pretty long so I kind of converted

$$0 \le x_1 \le y_1$$

$$y_2 \le x_2 \le 2y_2$$

$$2y_3 \le x_3 \le 3y_3$$

$$y_1, y_2, y_3 \in \{0,1\}$$

$$x_1,x_2,x_3 \ge 0$$

into

$$0 \le x_1 \le y_1 \le 1$$

$$\color{red}{0 \le} y_2 \le x_2 \le 2y_2 \color{red}{\le 2}$$

$$\color{red}{0 \le} 2y_3 \le x_3 \le 3y_3 \color{red}{\le 3}$$

$$\color{red}{y_1, y_2, y_3 \ \text{is an integer}}$$

Anyway, I typed

minimize (y1-x1)+(x2-y2)+(1/2)*(x3), 0 <= x1 <= y1 <= 1, 0 <= y2 <= x2 <= 2*y2 <=2, 0 <= 2*y3 <= x3 <= 3*y3 <= 3, y1+y2+y3=1

That works but this

minimize (y1-x1)+(x2-y2)+(1/2)*(x3), 0 <= x1 <= y1 <= 1, 0 <= y2 <= x2 <= 2*y2 <=2, 0 <= 2*y3 <= x3 <= 3*y3 <= 3, y1+y2+y3=1, $\color{red}{\text{y1 is an integer}}$

doesn't work.

Help please.

BCLC
  • 14,197

2 Answers2

1

The given constraints on $y_1, y_2, y_3$ are such that there are only three cases: $$(y_1, y_2, y_3) \in \{(1,0,0), (0,1,0), (0,0,1)\}.$$ In each case, two of the three variables $$x_1, x_2, x_3$$ are constrained to $0$ and the resulting function $z$ becomes univariate on the remaining nontrivial variable.

Note that WolframAlpha does not accept/parse the full range of Mathematica input syntax. You could do the requested command with

Minimize[{(y1 - x1) + (x2 - y2) + x3/2, 0 <= x1 <= y1 && 
  y2 <= x2 <= 2 y2 && 2 y3 <= x3 <= 3 y3 && y1 + y2 + y3 == 1 &&
  (y1 == 0 || y1 == 1) && (y2 == 0 || y2 == 1) &&
  (y3 == 0 || y3 == 1)}, {x1, x2, x3, y1, y2, y3}]

which produces

{0, {x1 -> 0, x2 -> 1, x3 -> 0, y1 -> 0, y2 -> 1, y3 -> 0}}

but there is another minimum for

{0, {x1 -> 1, x2 -> 0, x3 -> 0, y1 -> 1, y2 -> 0, y3 -> 0}}
heropup
  • 143,828
0

You specified in your query that y1,y2,y3 are all positive definite. y1+y2+y3=1 and y3 is and integer.

Or y1,y2 =0 and y3 =1, this forces x1,x2 = 0, 2 <= x3 <= 3

z reaches its minimum under this condition at x3 =2, z=1

WA is confused because of the length of the query. Appending any additional argument to the end of

minimize (y1-x1)+(x2-y2)+(1/2)*(x3), 0 <= x1 <= y1 <= 1, 0 <= y2 <= x2 <= 2*y2 <=2, 0 <= 2*y3 <= x3 <= 3*y3 <= 3, y1+y2+y3=1

will confuse WA, such as

minimize (y1-x1)+(x2-y2)+(1/2)*(x3), 0 <= x1 <= y1 <= 1, 0 <= y2 <= x2 <= 2*y2 <=2, 0 <= 2*y3 <= x3 <= 3*y3 <= 3, y1+y2+y3=1,y3=1

minimize (y1-x1)+(x2-y2)+(1/2)*(x3), 0 <= x1 <= y1 <= 1, 0 <= y2 <= x2 <= 2*y2 <=2, 0 <= 2*y3 <= x3 <= 3*y3 <= 3, y1+y2+y3=1,y2=0

minimize (y1-x1)+(x2-y2)+(1/2)*(x3), 0 <= x1 <= y1 <= 1, 0 <= y2 <= x2 <= 2*y2 <=2, 0 <= 2*y3 <= x3 <= 3*y3 <= 3, y1+y2+y3=1,y1=0

all will confuse WA