Skip to content

Commit

Permalink
phase2 init vector testing 100% complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Deer-WarLord committed Jan 17, 2019
1 parent 949c642 commit 402649c
Show file tree
Hide file tree
Showing 2 changed files with 318 additions and 4 deletions.
38 changes: 34 additions & 4 deletions test4.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def init_equation_system(self):

for i in range(0, 3):
self.EQ["I_{i}_{N}".format(N=j, i=i)] = self.EQ["st_old_{i}_{N}".format(N=j, i=i)] * \
self.EQ["X_old_1_{N}".format(N=j, i=i)]
self.EQ["X_old_1_{pN}".format(pN=j-1, i=i)]

self.COND["invest_{N}".format(N=j)] = sum([self.EQ["su_old_{i}_{N}".format(N=j, i=i)] +
self.EQ["st_old_{i}_{N}".format(N=j, i=i)] for i in
Expand All @@ -94,13 +94,27 @@ def init_equation_system(self):
sum([self.EQ["X_old_{i}_{N}".format(N=j, i=i)] *
self.EQ["a_{i}".format(i=i)] for i in range(0, 3)])) / \
self.EQ["L_{N}".format(N=j, i=i)]
# self.results[0] = {
# self.EQ["su_old_0_1"]: 0.45,
# self.EQ["su_old_1_1"]: 0.23,
# self.EQ["su_old_2_1"]: 0.11,
# self.EQ["su_old_0_2"]: 0.47,
# self.EQ["su_old_1_2"]: 0.27,
# self.EQ["su_old_2_2"]: 0.06,
# self.EQ["su_old_0_3"]: 0.53,
# self.EQ["su_old_1_3"]: 0.15,
# self.EQ["su_old_2_3"]: 0.12,
# self.EQ["su_old_0_4"]: 0.52,
# self.EQ["su_old_1_4"]: 0.28,
# self.EQ["su_old_2_4"]: 0.0,
# }

for j in range(1, tau):
s = None
consumption = lambdify(self.EQ["su_old_2_{N}".format(N=j)], self.EQ["X_old_2_{N}".format(N=j)])
balance = lambdify([self.EQ["su_old_{i}_{N}".format(N=j, i=i)] for i in range(0, 3)],
self.COND["balance_{N}".format(N=j)])
for S_phase_1 in self.generate_s(self.ds, 0.8):
for S_phase_1 in self.generate_s(self.ds, 0.9):
if consumption(S_phase_1[2]) >= self.C and balance(*S_phase_1) <= 1:
s = S_phase_1
break
Expand All @@ -127,6 +141,7 @@ def init_equation_system(self):
self.EQ["X_new_1_{pN}".format(pN=tau - 1)] = 0.0

for j in range(tau, self.N):
print(strftime("%H:%M:%S", gmtime()), "st_new K_new", j)
for i in range(0, 3):
self.EQ["st_new_{i}_{N}".format(N=j, i=i)] = symbols("st_new_{i}_{N}".format(N=j, i=i), negative=False)

Expand All @@ -149,6 +164,8 @@ def init_equation_system(self):
self.EQ["L_new_{i}_{N}".format(N=j, i=i)] = Min(self.EQ["L_new_v1_{i}_{N}".format(N=j, i=i)],
self.EQ["L_new_v2_{i}_{N}".format(N=j, i=i)])

print(strftime("%H:%M:%S", gmtime()), "L_new", j)

for i in range(0, 3):
self.EQ["theta_new_{i}_{N}".format(N=j, i=i)] = self.EQ["L_new_{i}_{N}".format(N=j, i=i)] / \
self.EQ["L_{N}".format(N=j, i=i)]
Expand All @@ -159,13 +176,17 @@ def init_equation_system(self):
self.EQ["K_new_{i}_{N}".format(N=j, i=i)] ** \
self.EQ["betta_new_{i}".format(i=i)]

print(strftime("%H:%M:%S", gmtime()), "theta_new X_new", j)

for i in range(0, 3):
self.EQ["theta_old_{i}_{N}".format(i=i, N=j)] = self.EQ["theta_old_{i}_{pN}".format(i=i, pN=j - 1)] - \
self.EQ["theta_new_{i}_{N}".format(N=j, i=i)]

self.EQ["L_old_{i}_{N}".format(N=j, i=i)] = self.EQ["theta_old_{i}_{N}".format(i=i, N=j)] * \
self.EQ["L_{N}".format(N=j, i=i)]

print(strftime("%H:%M:%S", gmtime()), "theta_old L_old", j)

for i in range(0, 3):
self.EQ["su_old_{i}_{N}".format(N=j, i=i)] = symbols("su_old_{i}_{N}".format(N=j, i=i))
self.EQ["K_old_{i}_{N}".format(N=j, i=i)] = (-self.EQ["mu_{i}".format(i=i)] *
Expand All @@ -174,21 +195,30 @@ def init_equation_system(self):
self.EQ["X_old_1_{pN}".format(pN=j - 1, i=i)]) * dt + \
self.EQ["K_old_{i}_{pN}".format(pN=j - 1, i=i)]

print(strftime("%H:%M:%S", gmtime()), "su_old K_old", j)

for i in range(0, 3):
self.EQ["X_old_{i}_{N}".format(N=j, i=i)] = self.EQ["A_old_{i}".format(i=i)] * \
self.EQ["L_old_{i}_{N}".format(N=j, i=i)] ** \
self.EQ["alpha_old_{i}".format(i=i)] * \
self.EQ["K_old_{i}_{N}".format(N=j, i=i)] ** \
self.EQ["betta_old_{i}".format(i=i)]

print(strftime("%H:%M:%S", gmtime()), "X_old", j)

self.COND["balance_new_{N}".format(N=j)] = Abs(self.EQ["X_new_0_{N}".format(N=j)] -
sum([self.EQ["X_new_{i}_{N}".format(N=j, i=i)] *
self.EQ["a_{i}".format(i=i)] for i in range(0, 3)])) / \
self.EQ["L_{N}".format(N=j, i=i)]

print(strftime("%H:%M:%S", gmtime()), "balance_new", j)

self.COND["consuming_bound_{N}".format(N=j)] = self.EQ["X_new_2_{N}".format(N=j)] + \
self.EQ["X_old_2_{N}".format(N=j)]
print(strftime("%H:%M:%S", gmtime()), j)

print(strftime("%H:%M:%S", gmtime()), "consuming_bound", j)

# print(strftime("%H:%M:%S", gmtime()), j)

for j in range(tau, self.N):
_st_new, _st_old, _su_old = None, None, None
Expand All @@ -209,7 +239,7 @@ def init_equation_system(self):

for st_new in self.generate_s(self.ds, 1.0):

for st_old in self.generate_s(self.ds, 0.2):
for st_old in self.generate_s(self.ds, 0.1):

b = balance(*chain(st_new, st_old))

Expand Down
Loading

0 comments on commit 402649c

Please sign in to comment.