Skip to main content
Became Hot Network Question
added 299 characters in body
Source Link

LinearOptimization - how to write downsolve with vector constraints?

I have the following linear program that I am able to solve in MATLAB. However, I want to move to Mathematica.

For some fixed constants $n$, $\delta$ and $\varepsilon$ and fixed $(n+1)$-dimensional vector $p$, we have the following optimization variables: $(n+1)$-dimensional vectors $y$ and $r$ and a constant $s$. The components of the vectors are labelled by index $k$ which runs from $0$ to $n$. The linear program is

$$ \begin{aligned} \inf \quad & s \\ \text { s.t. } \quad & y_{k}-r_{k}+p_{k} \geq 0, \forall k \\ \quad & y_{k} \geq 0, \forall k \\ \quad& 0 \leq r_{k} \leq s, \forall k \\ & \Sigma_{k=0}^{n}\left(\begin{array}{l} n \\ k \end{array}\right) r_{k}=1, \\ & \Sigma_{k=0}^{n}\left(\begin{array}{l} n \\ k \end{array}\right)y_{k} \leq \varepsilon . \end{aligned} $$

In MATLAB, this can be solved as follows

%Declaring input variables n = 10; eps = 0.01; delta = 0.2; for i = 1:n+1 p(i, 1) = delta^(i-1)*(1-delta)^(n-i+1); nck(1,i) = nchoosek(n, i-1); end %Start optimization cvx_begin variable y(n+1) variable r(n+1) variable s minimize(s) subject to y >= 0; r >= 0; r <= s*ones(n+1, 1) y - r + p >= 0; nck*r ==1; nck*y <= eps; cvx_end 

How does one do vector constraints in Mathematica? I want to efficiently write down the vector constraints I have instead of writing down the scalar constraints for each $k$. Here is my to-be-filled code, whereattempt but I don't knowam not sure how to input the constraintsproceed from here

n = 10; delta = 1/5; eps = 1/100;50; ppvec = Range[nArray[p, n + 1]; ncknckvec = Range[nArray[nck, n + 1]; yvec = Array[y, n + 1]; rvec = Array[r, n + 1]; For[i = 1, i <= n+1n + 1, i++, p[[i]]pvec[[i]] = delta^(i - 1)*(1 - delta)^(n - i + 1)] For[i = 1, i <= n+1n + 1, i++, nck[[i]]nckvec[[i]] = Binomial[n, i]] LinearOptimization[sc1 = Thread[rvec . nckvec == 1]; c2 = Thread[yvec . nckvec <= eps]; c3 = Thread[yvec - rvec + pvec >= 0]; c4 = Thread[0 <= rvec]; c5 = Thread[0 <= yvec]; c6 = Thread[rvec <= s*ConstantArray[1, {}]n (*+ To1]]; constraints be= filledJoin[c1, *)c2, c3, c4, c5, c6]; 

I get an error when I try to join the constraints and I am also not sure how the final linear program solving using, say, LinearOptimization should be done.

LinearOptimization - how to write down vector constraints?

I have the following linear program that I am able to solve in MATLAB. However, I want to move to Mathematica.

For some fixed constants $n$, $\delta$ and $\varepsilon$ and fixed $(n+1)$-dimensional vector $p$, we have the following optimization variables: $(n+1)$-dimensional vectors $y$ and $r$ and a constant $s$. The components of the vectors are labelled by index $k$ which runs from $0$ to $n$. The linear program is

$$ \begin{aligned} \inf \quad & s \\ \text { s.t. } \quad & y_{k}-r_{k}+p_{k} \geq 0, \forall k \\ \quad & y_{k} \geq 0, \forall k \\ \quad& 0 \leq r_{k} \leq s, \forall k \\ & \Sigma_{k=0}^{n}\left(\begin{array}{l} n \\ k \end{array}\right) r_{k}=1, \\ & \Sigma_{k=0}^{n}\left(\begin{array}{l} n \\ k \end{array}\right)y_{k} \leq \varepsilon . \end{aligned} $$

In MATLAB, this can be solved as follows

%Declaring input variables n = 10; eps = 0.01; delta = 0.2; for i = 1:n+1 p(i, 1) = delta^(i-1)*(1-delta)^(n-i+1); nck(1,i) = nchoosek(n, i-1); end %Start optimization cvx_begin variable y(n+1) variable r(n+1) variable s minimize(s) subject to y >= 0; r >= 0; r <= s*ones(n+1, 1) y - r + p >= 0; nck*r ==1; nck*y <= eps; cvx_end 

How does one do vector constraints in Mathematica? I want to efficiently write down the vector constraints I have instead of writing down the scalar constraints for each $k$. Here is my to-be-filled code, where I don't know how to input the constraints

n = 10; delta = 1/5; eps = 1/100; p = Range[n + 1]; nck = Range[n + 1]; For[i = 1, i <= n+1, i++, p[[i]] = delta^(i - 1)*(1 - delta)^(n - i + 1)] For[i = 1, i <= n+1, i++, nck[[i]] = Binomial[n, i]] LinearOptimization[s, {}] (* To be filled *) 

LinearOptimization - how to solve with vector constraints?

I have the following linear program that I am able to solve in MATLAB. However, I want to move to Mathematica.

For some fixed constants $n$, $\delta$ and $\varepsilon$ and fixed $(n+1)$-dimensional vector $p$, we have the following optimization variables: $(n+1)$-dimensional vectors $y$ and $r$ and a constant $s$. The components of the vectors are labelled by index $k$ which runs from $0$ to $n$. The linear program is

$$ \begin{aligned} \inf \quad & s \\ \text { s.t. } \quad & y_{k}-r_{k}+p_{k} \geq 0, \forall k \\ \quad & y_{k} \geq 0, \forall k \\ \quad& 0 \leq r_{k} \leq s, \forall k \\ & \Sigma_{k=0}^{n}\left(\begin{array}{l} n \\ k \end{array}\right) r_{k}=1, \\ & \Sigma_{k=0}^{n}\left(\begin{array}{l} n \\ k \end{array}\right)y_{k} \leq \varepsilon . \end{aligned} $$

In MATLAB, this can be solved as follows

%Declaring input variables n = 10; eps = 0.01; delta = 0.2; for i = 1:n+1 p(i, 1) = delta^(i-1)*(1-delta)^(n-i+1); nck(1,i) = nchoosek(n, i-1); end %Start optimization cvx_begin variable y(n+1) variable r(n+1) variable s minimize(s) subject to y >= 0; r >= 0; r <= s*ones(n+1, 1) y - r + p >= 0; nck*r ==1; nck*y <= eps; cvx_end 

How does one do vector constraints in Mathematica? Here is my attempt but I am not sure how to proceed from here

n = 10; delta = 1/5; eps = 1/50; pvec = Array[p, n + 1]; nckvec = Array[nck, n + 1]; yvec = Array[y, n + 1]; rvec = Array[r, n + 1]; For[i = 1, i <= n + 1, i++, pvec[[i]] = delta^(i - 1)*(1 - delta)^(n - i + 1)] For[i = 1, i <= n + 1, i++, nckvec[[i]] = Binomial[n, i]] c1 = Thread[rvec . nckvec == 1]; c2 = Thread[yvec . nckvec <= eps]; c3 = Thread[yvec - rvec + pvec >= 0]; c4 = Thread[0 <= rvec]; c5 = Thread[0 <= yvec]; c6 = Thread[rvec <= s*ConstantArray[1, n + 1]]; constraints = Join[c1, c2, c3, c4, c5, c6]; 

I get an error when I try to join the constraints and I am also not sure how the final linear program solving using, say, LinearOptimization should be done.

Source Link

LinearOptimization - how to write down vector constraints?

I have the following linear program that I am able to solve in MATLAB. However, I want to move to Mathematica.

For some fixed constants $n$, $\delta$ and $\varepsilon$ and fixed $(n+1)$-dimensional vector $p$, we have the following optimization variables: $(n+1)$-dimensional vectors $y$ and $r$ and a constant $s$. The components of the vectors are labelled by index $k$ which runs from $0$ to $n$. The linear program is

$$ \begin{aligned} \inf \quad & s \\ \text { s.t. } \quad & y_{k}-r_{k}+p_{k} \geq 0, \forall k \\ \quad & y_{k} \geq 0, \forall k \\ \quad& 0 \leq r_{k} \leq s, \forall k \\ & \Sigma_{k=0}^{n}\left(\begin{array}{l} n \\ k \end{array}\right) r_{k}=1, \\ & \Sigma_{k=0}^{n}\left(\begin{array}{l} n \\ k \end{array}\right)y_{k} \leq \varepsilon . \end{aligned} $$

In MATLAB, this can be solved as follows

%Declaring input variables n = 10; eps = 0.01; delta = 0.2; for i = 1:n+1 p(i, 1) = delta^(i-1)*(1-delta)^(n-i+1); nck(1,i) = nchoosek(n, i-1); end %Start optimization cvx_begin variable y(n+1) variable r(n+1) variable s minimize(s) subject to y >= 0; r >= 0; r <= s*ones(n+1, 1) y - r + p >= 0; nck*r ==1; nck*y <= eps; cvx_end 

How does one do vector constraints in Mathematica? I want to efficiently write down the vector constraints I have instead of writing down the scalar constraints for each $k$. Here is my to-be-filled code, where I don't know how to input the constraints

n = 10; delta = 1/5; eps = 1/100; p = Range[n + 1]; nck = Range[n + 1]; For[i = 1, i <= n+1, i++, p[[i]] = delta^(i - 1)*(1 - delta)^(n - i + 1)] For[i = 1, i <= n+1, i++, nck[[i]] = Binomial[n, i]] LinearOptimization[s, {}] (* To be filled *)