forked from BYU-PRISM/GEKKO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fishing_optimization_test.py
45 lines (32 loc) · 4.39 KB
/
fishing_optimization_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
from gekko import GEKKO
import numpy as np
import test_runner
def fishing():
m = GEKKO()
n=101
m.time = np.linspace(0,10,n)
E = 1
c = 17.5
r = 0.71
k = 80.5
U_max = 20
u = m.MV(lb=0,ub=1,value=1)
u.STATUS = 1
x = m.Var(value=70)
m.Equation(x.dt() == r*x*(1-x/k)-u*U_max)
J = m.Var(value=0)
Jf = m.FV()
Jf.STATUS = 1
m.Connection(Jf,J,pos2='end')
m.Equation(J.dt() == (E-c/x)*u*U_max)
m.Obj(-Jf)
m.options.IMODE = 6
m.options.NODES = 3
m.options.SOLVER = 3
m.solve(disp=False)
assert J.value == [0.0, 1.495191, 2.980856, 4.45711, 5.924057, 7.381791, 8.830394, 10.26994, 11.70049, 13.1221, 14.5348, 15.93865, 17.33365, 18.71983, 20.0972, 21.46575, 22.82547, 24.17635, 25.51835, 26.85144,28.17557, 29.49069, 30.79672, 32.09258, 33.19262, 34.14704, 35.03382, 35.90079, 36.7674, 37.63793, 38.51146, 39.38639, 40.26171, 41.13703, 42.01228, 42.88747, 43.76263, 44.63778, 45.51293, 46.38808, 47.26324, 48.13839, 49.01354, 49.88869, 50.76384, 51.63899, 52.51415, 53.3893, 54.26445, 55.1396, 56.01475, 56.88991, 57.76506, 58.64021, 59.51536, 60.39051, 61.26566, 62.14082, 63.01597, 63.89114, 64.76636, 65.64164, 66.51694, 67.39212, 68.2665, 69.13882, 70.00774, 70.87441, 71.74908, 72.66269, 73.67438, 74.84509, 76.11564, 77.37664, 78.62796, 79.86948, 81.10102, 82.32241, 83.53349, 84.73404, 85.92385, 87.10269, 88.2703, 89.4264, 90.57071, 91.70289, 92.82261, 93.92949, 95.02312, 96.10307, 97.16886, 98.21996, 99.25584, 100.2759, 101.2794, 102.2657, 103.2339, 104.1833, 105.1128, 106.0215, 106.9081]
assert Jf.value == [106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081, 106.9081]
assert x.value == [70.0, 68.68286, 67.43015, 66.23608, 65.0955, 64.00383, 62.95696, 61.95118, 60.98318, 60.04994, 59.14873, 58.27707, 57.43269, 56.61351, 55.81765, 55.04334, 54.28897, 53.55306, 52.83422, 52.13115, 51.44267, 50.76765, 50.10503, 49.45505, 49.10604, 48.98275, 48.96466, 48.97739, 48.99067, 48.99787, 49.00039, 49.00074, 49.00047, 49.00021, 49.00006, 49.0, 48.99999, 48.99999, 48.99999, 48.99999, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.0, 49.00001, 49.00001, 49.00001, 49.00001, 49.0, 48.99997, 48.99987, 48.99967, 48.99944, 48.9994, 49.0006, 49.005, 49.0147, 49.02789, 49.02863, 48.96884, 48.75625, 48.29394, 47.6701, 47.05438, 46.44599, 45.84423, 45.24837, 44.65774, 44.07168, 43.48957, 42.91077, 42.33468, 41.7607, 41.18826, 40.61676, 40.04563, 39.47429, 38.90217, 38.32869, 37.75326, 37.17529, 36.59418, 36.00931, 35.42005, 34.82575, 34.22573, 33.6193, 33.00574, 32.38429, 31.75415, 31.1145]
assert u.value == [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.853423, 0.7421807, 0.6899773, 0.6745367, 0.674141, 0.6771105, 0.6794158, 0.6804968, 0.6808019, 0.6808022, 0.6807487, 0.6807017, 0.6806795, 0.6806744, 0.6806733, 0.680673, 0.680673, 0.6806731, 0.6806734, 0.6806735, 0.6806737, 0.6806738, 0.6806739, 0.6806739, 0.6806738, 0.6806737, 0.6806736, 0.6806735,0.6806733, 0.6806732, 0.6806732, 0.6806732, 0.6806735, 0.6806743, 0.6806769, 0.6806896, 0.6807248, 0.6807767, 0.6807916, 0.6806986, 0.6800795, 0.6784639, 0.6757571, 0.6738888, 0.6799703, 0.710282, 0.7875389, 0.9150895, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
test_runner.test('fishing', fishing)