0
$\begingroup$

I have a short question,

Would it be correct to define the following constraints: $$ \begin{align*} - L_0 - A_0 + L_1 &= 0, \\ - L_1 - A_1 + L_2 &= 0, \\ - L_2 - A_2 + L_3 &= 0, \\ &\vdots \\ - L_{119} - A_{119} + L_{120} &= 0 \end{align*} $$

Into a constraints matrix that looks like this:

import numpy as np
H = np.zeros((120, 240))
for i, p in zip(range(120), range(120)):
    for j in range(i, i+3):
        if j - i < 2:
            H[p][j] = -1
        else:
            H[p][j] = 1  
$\endgroup$
2
  • $\begingroup$ It definitely gets you a $120\times 240$ matrix with $-1$, $-1$, and then $1$ in the $(i,i)$, $(i,i+1)$, and $(i,i+2)$ entries for $i = 0,\ldots,119$, but beyond that it's tough to say if what you're doing is correct. Are the $A_{i}$ known constants, or are they variables (slack, etc.) that you also want to solve for? $\endgroup$
    – kandb
    Feb 6, 2023 at 7:55
  • $\begingroup$ They are known constant, $-1 \leq A_i \leq 1$. So this should be the only thing to solve for. $\endgroup$ Feb 6, 2023 at 8:15

1 Answer 1

1
$\begingroup$

If the $A_{i}$ are unknown, I think the constraint system should be

\begin{equation*} \underbrace{\left(\begin{array}{cccccccccccccc} -1 & 1 & 0 & 0 & 0 & 0 & \cdots & 0 & 0 & -1 & 0 & 0 & \cdots & 0\\ 0 & -1 & 1 & 0 & 0 & 0 & \cdots & 0 & 0 & 0 &-1 & 0 & \cdots & 0\\ 0 & 0 & -1 & 1 & 0 & 0 & \cdots & 0 & 0 & 0 & 0 & -1 & \cdots & 0\\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots\\ 0 & 0 & 0 & 0 & 0 & 0 & \cdots & -1 & 1 & 0 & 0 & 0 & \cdots & -1 \end{array}\right)}_{120\times 241}\underbrace{\left(\begin{array}{c} L_{0}\\ L_{1}\\ L_{2}\\ \vdots \\ L_{120}\\ A_{0}\\ A_{1}\\ A_{2}\\ \vdots\\ A_{119} \end{array}\right)}_{241\times 1} = \underbrace{\left(\begin{array}{c} 0\\ 0\\ \vdots\\ 0 \end{array}\right)}_{120\times 1} \end{equation*}

Otherwise, I think it should be

\begin{equation*} \underbrace{\left(\begin{array}{cccccc} -1 & 1 & 0 & \cdots & 0 & 0\\ 0 & -1 & 1 & \cdots & 0 & 0\\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots\\ 0 & 0 & 0 & \cdots & -1 & 1\\ \end{array}\right)}_{120 \times 121}\underbrace{\left(\begin{array}{c} L_{0}\\ L_{1}\\ \vdots\\ L_{119}\\ L_{120} \end{array}\right)}_{121\times 1} = \underbrace{\left(\begin{array}{c} A_{0}\\ A_{1}\\ \vdots\\ A_{119} \end{array}\right)}_{120\times 1} \end{equation*}

The way you're constructing your matrix, it seems like you're sort of mixing up the positions of the $A_{i}$ and the $L_{i}$.

$\endgroup$
5
  • $\begingroup$ Thank you. How come there are $121$ and $241$ columns respectively. Is it to account for the separate constraint on $L_0$ $\endgroup$ Feb 6, 2023 at 8:57
  • $\begingroup$ If I understand you correctly, the unknowns are either the $L_{0},\ldots,L_{120}$ (there are $121$ of them) in which case you $121$ variables subject to $120$ equality constraints; or $L_{0},\ldots,L_{120},A_{0},\ldots,A_{119}$, (there are $121+120 = 241$ of them) in which case you have $241$ variables still subject to $120$ equality constraints $\endgroup$
    – kandb
    Feb 6, 2023 at 8:59
  • $\begingroup$ Yes. That is my understanding too. This means my cost vector 'c' needs to be of size 241 too. Since the objective function is $max. \sum{cx}$ and $c$ is known, I now have my $120 p_i's$ and $120$ zeros in this vector. Would I have to add another $0$ here? $\endgroup$ Feb 6, 2023 at 9:08
  • $\begingroup$ Right--so if the unknowns are $L_{0},\ldots,L_{120},A_{0},\ldots,A_{119}$, then I guess cost vector would be of the form $(c_{1},c_{2},\ldots,c_{120},c_{121},\ldots,c_{241})$ where the $c_{121},\ldots,c_{241}$ are all zero if the $A_{i}$ don't figure in the cost. I guess my question is this: is your problem to maximize $\mathbf{c}^{T}\mathbf{L}$ subject to $L_{i} - L_{i+1} - A_{i} = 0$ for $i = 0,\ldots,119$ where $\mathbf{L} = (L_{0},\ldots,L_{120},A_{0},\ldots,A_{119})^{T}$? $\endgroup$
    – kandb
    Feb 6, 2023 at 9:22
  • $\begingroup$ My $\it{original}$ problem is: maximize $\textbf{c}^T\textbf{L}$ s.t. $L_t = L_{t-1} - A_{t-1}; t>1$ for $i=0,...,119$ where $\textbf{c}$ is a vector of $120$ prices, and $\textbf{L} = (A_0,...,A_{119})$ $\endgroup$ Feb 6, 2023 at 9:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .