Linear Constraints python implementation for a receding horizon problem
回答済みI am trying to write the following constraints on the python platform as an optimization problem:
\begin{equation}
\forall k \in[1 \ldots N], \forall j \in[1 \ldots J]:
\end{equation}
\begin{equation}\left\{\begin{aligned}
x_{T}-\alpha_{c}\left(\cos k \theta_{s}\right.&-1) v_{y T}-\alpha_{c}\left(\sin k \theta_{s}\right) v_{x T} \\
& \leq x_{\min , j}+M b_{k j 1}+M d \\
-x_{T}+\alpha_{c}\left(\cos k \theta_{s}\right.&-1) v_{y T}+\alpha_{c}\left(\sin k \theta_{s}\right) v_{x T} \\
& \leq-x_{\max , j}+M b_{k j 2}+M d \\
y_{T}-\alpha_{c}\left(\sin k \theta_{s}\right) & v_{y T}+\alpha_{c}\left(\cos k \theta_{s}-1\right) v_{x T} \\
& \leq y_{\min , j}+M b_{k j 3}+M d \\
-y_{T}+\alpha_{c}\left(\sin k \theta_{s}\right) & v_{y T}-\alpha_{c}\left(\cos k \theta_{s}-1\right) v_{x T} \\
& \leq-y_{\max , j}+M b_{k j 4}+M d
\end{aligned}\right.\end{equation}
\begin{equation}
\text { AND }
\end{equation}
\begin{equation}
\left\{\begin{array}{r}
x_{T}+\alpha_{c}\left(\cos k \theta_{s}-1\right) v_{y T}+\alpha_{c}\left(\sin k \theta_{s}\right) v_{x T} \\
\leq x_{\min , j}+M b_{k j 1}+M(1-d) \\
-x_{T}-\alpha_{c}\left(\cos k \theta_{s}-1\right) v_{y T}-\alpha_{c}\left(\sin k \theta_{s}\right) v_{x T} \\
\leq-x_{\max , j}+M b_{k j 2}+M(1-d) \\
y_{T}+\alpha_{c}\left(\sin k \theta_{s}\right) v_{y T}-\alpha_{c}\left(\cos k \theta_{s}-1\right) v_{x T} \\
\leq y_{\min , j}+M b_{k j 3}+M(1-d) \\
-y_{T}-\alpha_{c}\left(\sin k \theta_{s}\right) v_{y T}+\alpha_{c}\left(\cos k \theta_{s}-1\right) v_{x T} \\
\leq-y_{\max , j}+M b_{k j 4}+M(1-d)
\end{array}\right.
\end{equation}
\begin{equation}
\left\{\begin{aligned}
\sum_{l=1}^{4} b_{k j l} & \leq 3 \\
\end{aligned}\right.
\end{equation}
I have so far written the code as:
N = 10 # angle distribution
J = 2 # total obstacles
# obstacles definition
xmin = [10.0, 13.0]
xmax = [15.0, 19.0]
ymin = [0.0, 24.0]
ymax = [15.0, 29.0]
ac = 10 # acceleration constant
T = 20 # time instant
M = 100 # weighted aux constant
d = m.addVar(vtype=GRB.BINARY) # selection binary variable
b1 = m.addVars(N, J, vtype=GRB.BINARY) # conversion binary variables
b2 = m.addVars(N, J, vtype=GRB.BINARY) # conversion binary variables
b3 = m.addVars(N, J, vtype=GRB.BINARY) # conversion binary variables
b4 = m.addVars(N, J, vtype=GRB.BINARY) # conversion binary variables
for j in J:
m.addConstrs((x[T] - ac*(math.cos(j*(2*pi/N))-1)*vy[T] - ac*(math.sin(j*(2*pi/N)))*vx[T] <= xmin[j] + M*b1[k, j] + M*d for k in range(1,N)))
m.addConstrs((-x[T] + ac*(math.cos(j*(2*pi/N))-1)*vy[T] + ac*(math.sin(j*(2*pi/N)))*vx[T] <= -xmax[j] + M*b2[k, j] + M*d for k in range(1,N)))
m.addConstrs((y[T] - ac*(math.sin(j*(2*pi/N)))*vy[T] + ac*(math.cos(j*(2*pi/N))-1)*vx[T] <= ymin[j] + M*b3[k, j] + M*d for k in range(1,N)))
m.addConstrs((-y[T] + ac*(math.sin(j*(2*pi/N)))*vy[T] - ac*(math.cos(j*(2*pi/N))-1)*vx[T] <= -ymax[j] + M*b4[k, j] + M*d for k in range(1,N)))
#AND ? # How can I incorporate AND function or AND condition in this program?
m.addConstrs((x[T] + ac*(math.cos(j*(2*pi/N))-1)*vy[T] + ac*(math.sin(j*(2*pi/N)))*vx[T] <= xmin[j] + M*b1[k, j] + M*(1-d) for k in range(1,N)))
m.addConstrs((-x[T] - ac*(math.cos(j*(2*pi/N))-1)*vy[T] - ac*(math.sin(j*(2*pi/N)))*vx[T] <= -xmax[j] + M*b2[k, j] + M*(1-d) for k in range(1,N)))
m.addConstrs((y[T] + ac*(math.sin(j*(2*pi/N)))*vy[T] - ac*(math.cos(j*(2*pi/N))-1)*vx[T] <= ymin[j] + M*b3[k, j] + M*(1-d) for k in range(1,N)))
m.addConstrs((-y[T] - ac*(math.sin(j*(2*pi/N)))*vy[T] + ac*(math.cos(j*(2*pi/N))-1)*vx[T] <= -ymax[j] + M*b4[k, j] + M*(1-d) for k in range(1,N)))
m.addConstrs((b1[k, j] + b2[k, j]+ b3[k, j] + b4[k, j] <= 3 for k in range(1,N)))
I just need to understand how can I incorporate the AND condition inside the program?
Kind regards,
Muhammad Haris
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Muhammad,
Could you please explain what the AND condition in your program means?
Do you mean that all constraints have to be fulfilled at the same time? If yes, then you don't need to add anything because any feasible solution has to fulfill all given constraints at the same time.
Best regards,
Jaromił0 -
Hi Jaromil,
Thank you very much for your support.
Kind regards,
Muhammad Haris
0
投稿コメントは受け付けていません。
コメント
3件のコメント