@@ -199,26 +199,26 @@ Thus, we have an optimization problem whose decision space is infinite with
199
199
respect to time `` t `` and position `` x `` . Now let's transcript it following the
200
200
above steps. First, we need to specify the infinite parameter supports and for
201
201
simplicity let's choose the following sparse sets:
202
- - `` t \in \{0, 10\} ``
202
+ - `` t \in \{0, 5, 10\} ``
203
203
- `` x \in \{[-1, -1]^T, [-1, 1]^T, [1, -1]^T, [1, 1]^T\} `` .
204
204
To handle the derivative `` \frac{\partial g(t, x)}{\partial t} `` , we'll use
205
- backward finite difference so no additional supports will need to be added.
205
+ backward finite difference, so no additional supports will need to be added.
206
206
207
207
Now we expand the two integrals (measures) via a finite approximation using only
208
208
the above supports and term coefficients of 1 (note this is not numerically
209
209
correct but is done for conciseness in example). Doing this, we obtain the
210
210
form:
211
211
``` math
212
212
\begin{aligned}
213
- &&\min_{y(t), g(t, x)} &&& y^2(0) + y^2(10) \\
213
+ &&\min_{y(t), g(t, x)} &&& y^2(0) + y^2(5) + y^2( 10) \\
214
214
&&\text{s.t.} &&& y(0) = 1 \\
215
215
&&&&& g(0, x) = 0 \\
216
216
&&&&& \frac{\partial g(t, [-1, -1])}{\partial t} + \frac{\partial g(t, [-1, 1])}{\partial t} + \frac{\partial g(t, [1, -1])}{\partial t} + \frac{\partial g(t, [1, 1])}{\partial t} = 42, && \forall t \in [0, 10] \\
217
217
&&&&& 3g(t, x) + 2y^2(t) \leq 2, && \forall t \in T, \ x \in [-1, 1]^2. \\
218
218
\end{aligned}
219
219
```
220
220
Notice that the infinite variable `` y(t) `` in the objective measure has been
221
- replaced with finite transcribed variables `` y(0) `` and `` y(10) `` . Also, the
221
+ replaced with finite transcribed variables `` y(0) `` , `` y(5) `` , `` y(10) `` . Also, the
222
222
infinite derivative `` \frac{\partial g(t, x)}{\partial t} `` was replaced with
223
223
partially transcribed variables in the second constraint in accordance with the
224
224
measure over the positional domain `` x `` .
@@ -230,13 +230,14 @@ and the third constraint needs to be transcribed for each unique combination
230
230
of the time and position supports. Applying this transcription yields:
231
231
``` math
232
232
\begin{aligned}
233
- &&\min_{y(t), g(t, x)} &&& y^2(0) + y^2(10) \\
233
+ &&\min_{y(t), g(t, x)} &&& y^2(0) + y^2(5) + y^2( 10) \\
234
234
&&\text{s.t.} &&& y(0) = 1 \\
235
235
&&&&& g(0, [-1, -1]) = 0 \\
236
236
&&&&& g(0, [-1, 1]) = 0 \\
237
237
&&&&& g(0, [1, -1]) = 0 \\
238
238
&&&&& g(0, [1, 1]) = 0 \\
239
239
&&&&& \frac{\partial g(0, [-1, -1])}{\partial t} + \frac{\partial g(0, [-1, 1])}{\partial t} + \frac{\partial g(0, [1, -1])}{\partial t} + \frac{\partial g(0, [1, 1])}{\partial t} = 42\\
240
+ &&&&& \frac{\partial g(5, [-1, -1])}{\partial t} + \frac{\partial g(5, [-1, 1])}{\partial t} + \frac{\partial g(5, [1, -1])}{\partial t} + \frac{\partial g(5, [1, 1])}{\partial t} = 42\\
240
241
&&&&& \frac{\partial g(10, [-1, -1])}{\partial t} + \frac{\partial g(10, [-1, 1])}{\partial t} + \frac{\partial g(10, [1, -1])}{\partial t} + \frac{\partial g(10, [1, 1])}{\partial t} = 42\\
241
242
&&&&& 3g(0, [-1, -1]) + 2y^2(0) \leq 2 \\
242
243
&&&&& 3g(0, [-1, 1]) + 2y^2(0) \leq 2 \\
@@ -252,10 +253,14 @@ infinite equation in this case this we only have 2 supports in the time domain
252
253
is then transcribed over the spatial domain to yield:
253
254
``` math
254
255
\begin{aligned}
255
- &&& g(10, [-1, -1]) = g(0, [-1, -1]) + 10\frac{\partial g(10, [-1, -1])}{\partial t} \\
256
- &&& g(10, [-1, 1]) = g(0, [-1, 1]) + 10\frac{\partial g(10, [-1, 1])}{\partial t} \\
257
- &&& g(10, [1, -1]) = g(0, [1, -1]) + 10\frac{\partial g(10, [1, -1])}{\partial t} \\
258
- &&& g(10, [1, 1]) = g(0, [1, 1]) + 10\frac{\partial g(10, [1, 1])}{\partial t}
256
+ &&& g(5, [-1, -1]) = g(0, [-1, -1]) + 5\frac{\partial g(5, [-1, -1])}{\partial t} \\
257
+ &&& g(5, [-1, 1]) = g(0, [-1, 1]) + 5\frac{\partial g(5, [-1, 1])}{\partial t} \\
258
+ &&& g(5, [1, -1]) = g(0, [1, -1]) + 5\frac{\partial g(5, [1, -1])}{\partial t} \\
259
+ &&& g(5, [1, 1]) = g(0, [1, 1]) + 5\frac{\partial g(5, [1, 1])}{\partial t} \\
260
+ &&& g(10, [-1, -1]) = g(5, [-1, -1]) + 5\frac{\partial g(10, [-1, -1])}{\partial t} \\
261
+ &&& g(10, [-1, 1]) = g(5, [-1, 1]) + 5\frac{\partial g(10, [-1, 1])}{\partial t} \\
262
+ &&& g(10, [1, -1]) = g(5, [1, -1]) + 5\frac{\partial g(10, [1, -1])}{\partial t} \\
263
+ &&& g(10, [1, 1]) = g(5, [1, 1]) + 5\frac{\partial g(10, [1, 1])}{\partial t}
259
264
\end{aligned}
260
265
```
261
266
@@ -275,7 +280,7 @@ using InfiniteOpt
275
280
inf_model = InfiniteModel()
276
281
277
282
# Define parameters and supports
278
- @infinite_parameter(inf_model, t in [0, 10], supports = [0, 10])
283
+ @infinite_parameter(inf_model, t in [0, 10], supports = [0, 5, 10])
279
284
@infinite_parameter(inf_model, x[1:2] in [-1, 1], supports = [-1, 1], independent = true)
280
285
281
286
# Define variables
@@ -313,56 +318,72 @@ julia> build_optimizer_model!(inf_model)
313
318
julia> trans_model = optimizer_model(inf_model);
314
319
315
320
julia> print(trans_model)
316
- Min y(support: 1)² + y(support: 2)²
321
+ Min y(support: 1)² + y(support: 2)² + y(support: 3)²
317
322
Subject to
318
323
y(support: 1) = 1
319
324
g(support: 1) = 0
320
- g(support: 3) = 0
321
- g(support: 5) = 0
325
+ g(support: 4) = 0
322
326
g(support: 7) = 0
323
- ∂/∂t[g(t, x)](support: 1) + ∂/∂t[g(t, x)](support: 3) + ∂/∂t[g(t, x)](support: 5) + ∂/∂t[g(t, x)](support: 7) = 42
324
- ∂/∂t[g(t, x)](support: 2) + ∂/∂t[g(t, x)](support: 4) + ∂/∂t[g(t, x)](support: 6) + ∂/∂t[g(t, x)](support: 8) = 42
325
- g(support: 1) - g(support: 2) + 10 ∂/∂t[g(t, x)](support: 2) = 0
326
- g(support: 3) - g(support: 4) + 10 ∂/∂t[g(t, x)](support: 4) = 0
327
- g(support: 5) - g(support: 6) + 10 ∂/∂t[g(t, x)](support: 6) = 0
328
- g(support: 7) - g(support: 8) + 10 ∂/∂t[g(t, x)](support: 8) = 0
327
+ g(support: 10) = 0
328
+ ∂/∂t[g(t, x)](support: 1) + ∂/∂t[g(t, x)](support: 4) + ∂/∂t[g(t, x)](support: 7) + ∂/∂t[g(t, x)](support: 10) = 42
329
+ ∂/∂t[g(t, x)](support: 2) + ∂/∂t[g(t, x)](support: 5) + ∂/∂t[g(t, x)](support: 8) + ∂/∂t[g(t, x)](support: 11) = 42
330
+ ∂/∂t[g(t, x)](support: 3) + ∂/∂t[g(t, x)](support: 6) + ∂/∂t[g(t, x)](support: 9) + ∂/∂t[g(t, x)](support: 12) = 42
331
+ g(support: 1) - g(support: 2) + 5 ∂/∂t[g(t, x)](support: 2) = 0
332
+ g(support: 2) - g(support: 3) + 5 ∂/∂t[g(t, x)](support: 3) = 0
333
+ g(support: 4) - g(support: 5) + 5 ∂/∂t[g(t, x)](support: 5) = 0
334
+ g(support: 5) - g(support: 6) + 5 ∂/∂t[g(t, x)](support: 6) = 0
335
+ g(support: 7) - g(support: 8) + 5 ∂/∂t[g(t, x)](support: 8) = 0
336
+ g(support: 8) - g(support: 9) + 5 ∂/∂t[g(t, x)](support: 9) = 0
337
+ g(support: 10) - g(support: 11) + 5 ∂/∂t[g(t, x)](support: 11) = 0
338
+ g(support: 11) - g(support: 12) + 5 ∂/∂t[g(t, x)](support: 12) = 0
329
339
y(support: 1)² + 3 g(support: 1) ≤ 2
330
340
y(support: 2)² + 3 g(support: 2) ≤ 2
331
- y(support: 1 )² + 3 g(support: 3) ≤ 2
332
- y(support: 2 )² + 3 g(support: 4) ≤ 2
333
- y(support: 1 )² + 3 g(support: 5) ≤ 2
334
- y(support: 2 )² + 3 g(support: 6) ≤ 2
341
+ y(support: 3 )² + 3 g(support: 3) ≤ 2
342
+ y(support: 1 )² + 3 g(support: 4) ≤ 2
343
+ y(support: 2 )² + 3 g(support: 5) ≤ 2
344
+ y(support: 3 )² + 3 g(support: 6) ≤ 2
335
345
y(support: 1)² + 3 g(support: 7) ≤ 2
336
346
y(support: 2)² + 3 g(support: 8) ≤ 2
347
+ y(support: 3)² + 3 g(support: 9) ≤ 2
348
+ y(support: 1)² + 3 g(support: 10) ≤ 2
349
+ y(support: 2)² + 3 g(support: 11) ≤ 2
350
+ y(support: 3)² + 3 g(support: 12) ≤ 2
337
351
```
338
352
This precisely matches what we found analytically. Note that the unique support
339
353
combinations are determined automatically and are represented visually as
340
354
` support: # ` . The precise support values can be looked up via ` supports ` :
341
355
``` jldoctest trans_example
342
356
julia> supports(y)
343
- 2 -element Vector{Tuple}:
357
+ 3 -element Vector{Tuple}:
344
358
(0.0,)
359
+ (5.0,)
345
360
(10.0,)
346
361
347
362
julia> supports(g)
348
- 8 -element Vector{Tuple}:
363
+ 12 -element Vector{Tuple}:
349
364
(0.0, [-1.0, -1.0])
365
+ (5.0, [-1.0, -1.0])
350
366
(10.0, [-1.0, -1.0])
351
367
(0.0, [1.0, -1.0])
368
+ (5.0, [1.0, -1.0])
352
369
(10.0, [1.0, -1.0])
353
370
(0.0, [-1.0, 1.0])
371
+ (5.0, [-1.0, 1.0])
354
372
(10.0, [-1.0, 1.0])
355
373
(0.0, [1.0, 1.0])
374
+ (5.0, [1.0, 1.0])
356
375
(10.0, [1.0, 1.0])
357
376
358
377
julia> supports(g, ndarray = true) # format it as an n-dimensional array (t by x[1] by x[2])
359
- 2 ×2×2 Array{Tuple, 3}:
378
+ 3 ×2×2 Array{Tuple, 3}:
360
379
[:, :, 1] =
361
380
(0.0, [-1.0, -1.0]) (0.0, [1.0, -1.0])
381
+ (5.0, [-1.0, -1.0]) (5.0, [1.0, -1.0])
362
382
(10.0, [-1.0, -1.0]) (10.0, [1.0, -1.0])
363
383
364
384
[:, :, 2] =
365
385
(0.0, [-1.0, 1.0]) (0.0, [1.0, 1.0])
386
+ (5.0, [-1.0, 1.0]) (5.0, [1.0, 1.0])
366
387
(10.0, [-1.0, 1.0]) (10.0, [1.0, 1.0])
367
388
```
368
389
0 commit comments