awk: processing log and search pattern - bash

I am working with the log filles arranged in the following format:
fƒdfFinding intramodel H-bonds
Constraints relaxed by 0.5 angstroms and 20 degrees
Models used:
1.1 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.2 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.3 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.4 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.5 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.6 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.7 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.8 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.9 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.10 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.11 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.12 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.13 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.14 SarsCov2_structure49R_nsp5holo_rep1.pdb
14 H-bonds
H-bonds (donor, acceptor, hydrogen, D..A dist, D-H..A dist):
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.1/? ASN 142 ND2 SarsCov2_structure49R_nsp5holo_rep1.pdb #1.1/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.1/? ASN 142 1HD2 3.102 2.145
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.3/? GLU 166 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.3/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.3/? GLU 166 H 3.011 2.024
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.4/? GLU 166 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.4/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.4/? GLU 166 H 3.037 2.132
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.5/? HIS 163 NE2 SarsCov2_structure49R_nsp5holo_rep1.pdb #1.5/A UNL 888 O no hydrogen 3.388 N/A
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.5/? GLU 166 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.5/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.5/? GLU 166 H 2.806 1.792
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.7/? THR 26 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.7/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.7/? THR 26 H 3.093 2.142
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.7/? GLY 143 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.7/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.7/? GLY 143 H 3.030 2.193
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.9/? GLN 189 NE2 SarsCov2_structure49R_nsp5holo_rep1.pdb #1.9/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.9/? GLN 189 2HE2 3.052 2.301
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.10/? GLU 166 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.10/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.10/? GLU 166 H 2.854 1.868
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.12/? GLY 143 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.12/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.12/? GLY 143 H 3.103 2.070
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.13/? GLY 143 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.13/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.13/? GLY 143 H 3.161 2.224
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.13/? CYS 145 SG SarsCov2_structure49R_nsp5holo_rep1.pdb #1.13/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.13/? CYS 145 HG 3.421 2.842
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.14/? ASN 142 ND2 SarsCov2_structure49R_nsp5holo_rep1.pdb #1.14/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.14/? ASN 142 2HD2 3.055 2.465
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.14/? CYS 145 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.14/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.14/? CYS 145 H 2.924 2.143
I need to find the first occurence of the "GLU 166 N" pattern and print the number present on the same line just before the pattern as #1.number/?, associated with this pattern. So in the example the detected number should be 3 (since the associating number is #1.3/?).
I would start from basic pattern-detection
awk '/GLU 166 N/' file
but how to find correctly the number defined just before the pattern and print it as output ? Finally, in the case if the pattern can not be found, I would like that the script prints 1.

$ awk -vn=1 '/GLU 166 N/ {gsub(/.*\.|\/\?/,"",$2); n=$2; exit} END {print n}' file
3
$ awk -vn=1 '/GLU 166 N/ {gsub(/.*\.|\/\?/,"",$2); n=$2; exit} END {print n}' /dev/null
1
What you look for is in the second field ($2). gsub(/.*\.|\/\?/,"",$2) replaces in $2 all leading characters up to (and including) the period, and the trailing /? by the empty string.

Using GNU awk for the 3rd arg to match():
$ awk 'match($0,/([0-9]+).. GLU 166 N /,a){print a[1]; exit}' file
3
or using any awk:
$ awk 'match($0,/[0-9]+.. GLU 166 N /){sub("/.*",""); print substr($0,RSTART); exit}' file
3
$ awk 'match($0,/[0-9]+.. GLU 166 N /){print substr($0,RSTART,RLENGTH-13); exit}' file
3

If GNU awk which supports gensub function is available, would you please try:
awk '/GLU 166 N/ {
print gensub(/^.*#1\.([0-9]+)\/\? GLU 166 N.*$/, "\\1", 1)
exit
}' file
The regex ^.*#1\\.([0-9]+)/\\? GLU 166 N.*$ matches the line with the substring #1.<number>/? "GLU 166 N. The <number> portion, which is enclosed with the parentheses in the regex as ([0-9]+) is captured as group 1, then the entire line is replaced with the group 1, which is specified as the replacement \\1, then it is printed as the result.
Alternatively you can say with GNU sed as:
sed -nE '0,/GLU 166 N/s|^.*#1\.([0-9]+)/\? GLU 166 N.*|\1|p' file
The address 0,/pattern/, where 0 is specific to GNU sed as a starting line, makes the script exit immediately after the 1st pattern match.

If awk is not requirement, you can use grep and cut. Simple is good.
λ cat input.txt
fƒdfFinding intramodel H-bonds
Constraints relaxed by 0.5 angstroms and 20 degrees
Models used:
1.1 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.2 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.3 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.4 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.5 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.6 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.7 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.8 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.9 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.10 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.11 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.12 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.13 SarsCov2_structure49R_nsp5holo_rep1.pdb
1.14 SarsCov2_structure49R_nsp5holo_rep1.pdb
14 H-bonds
H-bonds (donor, acceptor, hydrogen, D..A dist, D-H..A dist):
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.1/? ASN 142 ND2 SarsCov2_structure49R_nsp5holo_rep1.pdb #1.1/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.1/? ASN 142 1HD2 3.102 2.145
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.3/? GLU 166 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.3/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.3/? GLU 166 H 3.011 2.024
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.4/? GLU 166 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.4/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.4/? GLU 166 H 3.037 2.132
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.5/? HIS 163 NE2 SarsCov2_structure49R_nsp5holo_rep1.pdb #1.5/A UNL 888 O no hydrogen 3.388 N/A
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.5/? GLU 166 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.5/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.5/? GLU 166 H 2.806 1.792
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.7/? THR 26 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.7/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.7/? THR 26 H 3.093 2.142
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.7/? GLY 143 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.7/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.7/? GLY 143 H 3.030 2.193
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.9/? GLN 189 NE2 SarsCov2_structure49R_nsp5holo_rep1.pdb #1.9/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.9/? GLN 189 2HE2 3.052 2.301
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.10/? GLU 166 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.10/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.10/? GLU 166 H 2.854 1.868
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.12/? GLY 143 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.12/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.12/? GLY 143 H 3.103 2.070
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.13/? GLY 143 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.13/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.13/? GLY 143 H 3.161 2.224
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.13/? CYS 145 SG SarsCov2_structure49R_nsp5holo_rep1.pdb #1.13/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.13/? CYS 145 HG 3.421 2.842
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.14/? ASN 142 ND2 SarsCov2_structure49R_nsp5holo_rep1.pdb #1.14/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.14/? ASN 142 2HD2 3.055 2.465
SarsCov2_structure49R_nsp5holo_rep1.pdb #1.14/? CYS 145 N SarsCov2_structure49R_nsp5holo_rep1.pdb #1.14/A UNL 888 O SarsCov2_structure49R_nsp5holo_rep1.pdb #1.14/? CYS 145 H 2.924 2.143
grep -om1 '[[:digit:]]*/? GLU 166 N' input.txt | cut -d/ -f1
3
To print 1 when the pattern is not found:
{ grep -om1 '[[:digit:]]*/? GLU 166 N' input.txt || echo 1; } | cut -d/ -f1

Related

Using GEKKO for Moving Horizon Estimation online 3

This is the following question after Using GEKKO for Moving Horizon Estimation online 2.
My code:
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
import matplotlib; matplotlib.use('TkAgg')
class Observer():
def __init__(self, window_size, r_init, alpha_init):
self.m = GEKKO(remote=False)
self.dt = 0.05
self.m.time = [i*self.dt for i in range(window_size)]
#Parameters
self.m.u = self.m.MV()
#Variables
self.m.r = self.m.CV(lb=0.01) # value=r_init) #ub=20 can be over 20
self.m.alpha = self.m.CV() # value=alpha_init) #ub lb for angle?
#Equations
self.m.Equation(self.m.r.dt() == -self.m.cos(self.m.alpha))
self.m.Equation(self.m.alpha.dt() == self.m.sin(self.m.alpha)/self.m.r - self.m.u) # differential equation
#Options
# self.m.options.MV_STEP_HOR = 2
self.m.options.IMODE = 5 # dynamic estimation
self.m.options.EV_TYPE = 1 #Default 1: absolute error form 2: squared error form
self.m.options.DIAGLEVEL = 0 #diagnostic level
self.m.options.NODES = 3 #nodes # collocation nodes default:2
self.m.options.SOLVER = 2 #solver_num
# STATUS = 0, optimizer doesn't adjust value
# STATUS = 1, optimizer can adjust
self.m.u.STATUS = 0
self.m.r.STATUS = 1
self.m.alpha.STATUS = 1
# FSTATUS = 0, no measurement
# FSTATUS = 1, measurement used to update model
self.m.u.FSTATUS = 1 #default
self.m.r.FSTATUS = 1
self.m.alpha.FSTATUS = 1
self.m.r.MEAS_GAP = 2
self.m.alpha.MEAS_GAP = 1
self.m.r.TR_INIT = 1
self.m.alpha.TR_INIT = 1
self.count = 0
def MHE(self, observed_state, u_data):
self.count =+ 1
self.m.u.MEAS = u_data
self.m.r.MEAS = observed_state[0]
self.m.alpha.MEAS = observed_state[1]
self.m.solve(disp=True)
return self.m.r.MODEL, self.m.alpha.MODEL
if __name__=="__main__":
FILE_PATH00 = '/home/shane16/Project/model_guard/uav_paper/adversarial/SA_PPO/src/DATA/4end_estimation_results_r.csv'
FILE_PATH01 = '/home/shane16/Project/model_guard/uav_paper/adversarial/SA_PPO/src/DATA/4end_estimation_results_alpha.csv'
FILE_PATH02 = '/home/shane16/Project/model_guard/uav_paper/adversarial/SA_PPO/src/DATA/4end_action_buffer_eps0.0_sig0.0.csv'
cycles = 250
x = np.arange(cycles) # 1...300
matrix00 = np.loadtxt(FILE_PATH00, delimiter=',')
matrix01 = np.loadtxt(FILE_PATH01, delimiter=',')
matrix02 = np.loadtxt(FILE_PATH02, delimiter=',')
vanilla_action_sigma_0 = matrix02
vanilla_estimation_matrix_r = np.zeros(cycles)
vanilla_estimation_matrix_alpha = np.zeros(cycles)
# sigma = 0.0
# vanilla model true/observed states
r_vanilla_sigma_0_true = matrix00[0, 3:] # from step 1
r_vanilla_sigma_0_observed = matrix00[1, 3:] # from step1
alpha_vanilla_sigma_0_true = matrix01[0, 3:]
alpha_vanilla_sigma_0_observed = matrix01[1, 3:]
# initialize estimator
sigma = 0.0 #1.0
solver_num = 2
nodes = 5
# for window_size in [5, 10, 20, 30, 40, 50]:
window_size = 8
observer = Observer(window_size, r_vanilla_sigma_0_observed[0], alpha_vanilla_sigma_0_observed[0])
for i in range(cycles):
if i % 100 == 0:
print('cylcle: {}'.format(i))
vanilla_observed_states = np.hstack((r_vanilla_sigma_0_observed[i], alpha_vanilla_sigma_0_observed[i])) # from current observed state
r_hat, alpha_hat = observer.MHE(vanilla_observed_states, vanilla_action_sigma_0[i]) # and current action -> estimate current state
vanilla_estimation_matrix_r[i] = r_hat
vanilla_estimation_matrix_alpha[i] = alpha_hat
#plot vanilla
plt.figure()
plt.subplot(3,1,1)
plt.title('Vanilla model_sig{}'.format(sigma))
plt.plot(x, vanilla_action_sigma_0[:cycles],'b:',label='action (w)')
plt.legend()
plt.subplot(3,1,2)
plt.ylabel('r')
plt.plot(x, r_vanilla_sigma_0_true[:cycles], 'k-', label='true_r')
plt.plot(x, r_vanilla_sigma_0_observed[:cycles], 'gx', label='observed_r')
plt.plot(x, vanilla_estimation_matrix_r, 'r--', label='time window: 10')
# plt.legend()
plt.subplot(3,1,3)
plt.xlabel('time steps')
plt.ylabel('alpha')
plt.plot(x, alpha_vanilla_sigma_0_true[:cycles], 'k-', label='true_alpha')
plt.plot(x, alpha_vanilla_sigma_0_observed[:cycles], 'gx', label='observed_alpha')
plt.plot(x, vanilla_estimation_matrix_alpha, 'r--', label='time window: {}'.format(window_size))
plt.legend()
plt.savefig('plot/revision/4estimated_STATES_vanilla_sig{}_window{}_cycles{}_solver{}_nodes{}.png'.format(sigma, window_size,cycles, solver_num, nodes))
plt.show()
I have studied and did set the problem as the example https://apmonitor.com/do/index.php/Main/EstimatorTypes.
But when I set window_size in my code over 10, the solution is not found:
(result of terminal when options.SOLVER = 0)
apm 165.132.48.158_gk_model0 <br><pre>
---------------------------------------------------------------- APMonitor, Version 1.0.1 APMonitor Optimization Suite
----------------------------------------------------------------
--------- APM Model Size ------------ Each time step contains Objects : 0 Constants : 0 Variables : 3 Intermediates: 0 Connections : 0 Equations : 2 Residuals : 2 Warning: CV( 1 ) on at cycle 1 with no MVs on Warning: CV( 2 ) on at cycle 1 with no MVs on Number of state variables: 261 Number of total equations: - 261 Number of slack variables: - 0 --------------------------------------- Degrees of freedom : 0 ---------------------------------------------- Dynamic Estimation with APOPT Solver
---------------------------------------------- Iter Objective Convergence
0 5.30547E+02 1.04898E+01
1 3.70823E+02 3.25000E-01
2 3.70724E+02 7.49963E-02
3 3.70689E+02 3.74995E-01
4 3.70716E+02 1.00000E-01
5 3.70717E+02 2.00000E-01
6 2.33359E+03 1.73260E-01
7 2.56047E+04 1.00000E-01
8 2.56261E+04 1.18140E-01
9 1.52748E+21 1.39682E+00 Iter Objective Convergence 10 1.08739E+30 1.39682E+00 11 1.06063E+30 1.39682E+00 12
1.03450E+30 1.39682E+00 13 2.40101E+32 1.39682E+00 14 2.34191E+32 1.39682E+00 15 2.28418E+32 1.39682E+00 16 1.68770E+32 1.39682E+00 17 1.64616E+32 1.39682E+00 18 1.60560E+32 1.39682E+00 19 1.72636E+32 1.39682E+00 Iter Objective Convergence 20 1.68387E+32 1.39682E+00 21
1.64239E+32 1.39682E+00 22 1.72644E+32 1.39682E+00 23 1.68395E+32 1.39682E+00 24 1.64243E+32 1.39682E+00 25 1.72645E+32 1.39682E+00 26 1.68395E+32 1.39682E+00 27 1.64243E+32 1.39682E+00 28 1.72645E+32 1.39682E+00 29 1.68395E+32 1.39682E+00 Iter Objective Convergence 30 1.64243E+32 1.39682E+00 31 1.72645E+32 1.39682E+00 32 1.68395E+32 1.39682E+00 33 1.64244E+32 1.39682E+00 34 1.72645E+32 1.39682E+00 35 1.68395E+32 1.39682E+00 36 1.64244E+32 1.39682E+00 37 1.72645E+32 1.39682E+00 38 1.68395E+32 1.39682E+00 39 1.64244E+32 1.39682E+00 Iter Objective Convergence 40 1.72645E+32 1.39682E+00 41
1.68395E+32 1.39682E+00 42 1.64244E+32 1.39682E+00 43 1.72645E+32 1.39682E+00 44 1.68395E+32 1.39682E+00 45 1.64245E+32 1.39682E+00 46 1.72645E+32 1.39682E+00 47 1.68395E+32 1.39682E+00 48 1.64243E+32 1.39682E+00 49 1.72645E+32 1.39682E+00 Iter Objective Convergence 50 1.68395E+32 1.39682E+00 51 1.64243E+32 1.39682E+00 52 1.72645E+32 1.39682E+00 53 1.68395E+32 1.39682E+00 54 1.64244E+32 1.39682E+00 55 1.72645E+32 1.39682E+00 56 1.68395E+32 1.39682E+00 57 1.64244E+32 1.39682E+00 58 1.72645E+32 1.39682E+00 59 1.68395E+32 1.39682E+00 Iter Objective Convergence 60 1.64244E+32 1.39682E+00 61
1.72645E+32 1.39682E+00 62 1.68395E+32 1.39682E+00 63 1.64243E+32 1.39682E+00 64 1.72645E+32 1.39682E+00 65 1.68395E+32 1.39682E+00 66 1.64243E+32 1.39682E+00 67 1.72645E+32 1.39682E+00 68 1.68395E+32 1.39682E+00 69 1.64244E+32 1.39682E+00 Iter Objective Convergence 70 1.72645E+32 1.39682E+00 71 1.68395E+32 1.39682E+00
... 81
1.64244E+32 1.39682E+00 82 1.72645E+32 1.39682E+00 83 1.68395E+32 1.39682E+00 84 1.64243E+32 1.39682E+00 85 1.72645E+32 1.39682E+00 86 1.68395E+32 1.39682E+00 87 1.64243E+32 1.39682E+00 88 1.72645E+32 1.39682E+00 89 1.68395E+32 1.39682E+00 Iter Objective Convergence 90 1.64243E+32 1.39682E+00 91 1.72645E+32 1.39682E+00 92 1.68395E+32 1.39682E+00 93 1.64243E+32 1.39682E+00 94 1.72645E+32 1.39682E+00 95 1.68395E+32 1.39682E+00 96 1.64243E+32 1.39682E+00 97 1.72645E+32 1.39682E+00 98 1.68395E+32 1.39682E+00 99 1.64243E+32 1.39682E+00 Iter Objective Convergence 100 1.72645E+32 1.39682E+00 101
1.68395E+32 1.39682E+00 102 1.64244E+32 1.39682E+00 103 1.72645E+32 1.39682E+00 104 1.68395E+32 1.39682E+00 105 1.64244E+32 1.39682E+00 106 1.72645E+32 1.39682E+00 107 1.68395E+32 1.39682E+00 108 1.64244E+32 1.39682E+00 109 1.72645E+32 1.39682E+00 Iter Objective Convergence 110 1.68395E+32 1.39682E+00 111 1.64243E+32 1.39682E+00 112 1.72645E+32 1.39682E+00 113 1.68395E+32 1.39682E+00 114 1.64243E+32 1.39682E+00 115 1.72645E+32 1.39682E+00 116 1.68395E+32 1.39682E+00 117 1.64244E+32 1.39682E+00 118 1.72645E+32 1.39682E+00 119 1.68395E+32 1.39682E+00 Iter Objective Convergence 120 1.64244E+32 1.39682E+00 121
1.72645E+32 1.39682E+00 122 1.68395E+32 1.39682E+00 123 1.64243E+32 1.39682E+00 124 1.72645E+32 1.39682E+00 125 1.68395E+32 1.39682E+00 126 1.64244E+32 1.39682E+00 127 1.72645E+32 1.39682E+00 128 1.68395E+32 1.39682E+00 129 1.64243E+32 1.39682E+00 Iter Objective Convergence 130 1.72645E+32 1.39682E+00 131 1.68395E+32 1.39682E+00 132 1.64244E+32 1.39682E+00 133 1.72645E+32 1.39682E+00 134 1.68395E+32 1.39682E+00 135 1.64243E+32 1.39682E+00 136 1.72645E+32 1.39682E+00 137 1.68395E+32 1.39682E+00 138 1.64243E+32 1.39682E+00 139 1.72645E+32 1.39682E+00 Iter Objective Convergence 140 1.68395E+32 1.39682E+00 141
1.64243E+32 1.39682E+00 142 1.72645E+32 1.39682E+00 143 1.68395E+32 1.39682E+00 144 1.64243E+32 1.39682E+00 145 1.72645E+32 1.39682E+00 146 1.68395E+32 1.39682E+00 147 1.64244E+32 1.39682E+00 148 1.72645E+32 1.39682E+00 149 1.68395E+32 1.39682E+00 Iter Objective Convergence 150 1.64243E+32 1.39682E+00 151 1.72645E+32 1.39682E+00 152 1.68395E+32 1.39682E+00 153 1.64244E+32 1.39682E+00 154 1.72645E+32 1.39682E+00 155 1.68395E+32 1.39682E+00 156 1.64244E+32 1.39682E+00 157 1.72645E+32 1.39682E+00 158 1.68395E+32 1.39682E+00 159 1.64243E+32 1.39682E+00 Iter Objective Convergence 160 1.72645E+32 1.39682E+00 161
1.68395E+32 1.39682E+00 162 1.64243E+32 1.39682E+00 163 1.72645E+32 1.39682E+00 164 1.68395E+32 1.39682E+00 165 1.64244E+32 1.39682E+00 166 1.72645E+32 1.39682E+00 167 1.68395E+32 1.39682E+00 168 1.64244E+32 1.39682E+00 169 1.72645E+32 1.39682E+00 Iter Objective Convergence 170 1.68395E+32 1.39682E+00 171 1.64243E+32 1.39682E+00 172 1.72645E+32 1.39682E+00 173 1.68395E+32 1.39682E+00 174 1.64244E+32 1.39682E+00 175 1.72645E+32 1.39682E+00 176 1.68395E+32 1.39682E+00 177 1.64243E+32 1.39682E+00 178 1.72645E+32 1.39682E+00 179 1.68395E+32 1.39682E+00 Iter Objective Convergence 180 1.64244E+32 1.39682E+00 181
1.72645E+32 1.39682E+00 182 1.68395E+32 1.39682E+00 183 1.64243E+32 1.39682E+00 184 1.72645E+32 1.39682E+00 185 1.68395E+32 1.39682E+00 186 1.64243E+32 1.39682E+00 187 1.72645E+32 1.39682E+00 188 1.68395E+32 1.39682E+00 189 1.64243E+32 1.39682E+00 Iter Objective Convergence 190 1.72645E+32 1.39682E+00 191 1.68395E+32 1.39682E+00 192 1.64243E+32 1.39682E+00 193 1.72645E+32 1.39682E+00 194 1.68395E+32 1.39682E+00 195 1.64244E+32 1.39682E+00 196 1.72645E+32 1.39682E+00 197 1.68395E+32 1.39682E+00 198 1.64243E+32 1.39682E+00 199 1.72645E+32 1.39682E+00 Iter Objective Convergence 200 1.68395E+32 1.39682E+00 201
1.64244E+32 1.39682E+00 202 1.72645E+32 1.39682E+00 203 1.68395E+32 1.39682E+00 204 1.64244E+32 1.39682E+00 205 1.72645E+32 1.39682E+00 206 1.68395E+32 1.39682E+00 207 1.64243E+32 1.39682E+00 208 1.72645E+32 1.39682E+00 209 1.68395E+32 1.39682E+00 Iter Objective Convergence 210 1.64243E+32 1.39682E+00 211 1.72645E+32 1.39682E+00 212 1.68395E+32 1.39682E+00 213 1.64244E+32 1.39682E+00 214 1.72645E+32 1.39682E+00 215 1.68395E+32 1.39682E+00 216 1.64244E+32 1.39682E+00 217 1.72645E+32 1.39682E+00 218 1.68395E+32 1.39682E+00 219 1.64243E+32 1.39682E+00 Iter Objective Convergence 220 1.72645E+32 1.39682E+00 221
1.68395E+32 1.39682E+00 222 1.64244E+32 1.39682E+00 223 1.72645E+32 1.39682E+00 224 1.68395E+32 1.39682E+00 225 1.64243E+32 1.39682E+00 226 1.72645E+32 1.39682E+00 227 1.68395E+32 1.39682E+00 228 1.64244E+32 1.39682E+00 229 1.72645E+32 1.39682E+00 Iter Objective Convergence 230 1.68395E+32 1.39682E+00 231 1.64243E+32 1.39682E+00 232 1.72645E+32 1.39682E+00 233 1.68395E+32 1.39682E+00 234 1.64243E+32 1.39682E+00 235 1.72645E+32 1.39682E+00 236 1.68395E+32 1.39682E+00 237 1.64243E+32 1.39682E+00 238 1.72645E+32 1.39682E+00 239 1.68395E+32 1.39682E+00 Iter Objective Convergence 240 1.64243E+32 1.39682E+00 241
1.72645E+32 1.39682E+00 242 1.68395E+32 1.39682E+00 243 1.64244E+32 1.39682E+00 244 1.72645E+32 1.39682E+00 245 1.68395E+32 1.39682E+00 246 1.64243E+32 1.39682E+00 247 1.72645E+32 1.39682E+00 248 1.68395E+32 1.39682E+00 249 1.64244E+32 1.39682E+00 Iter Objective Convergence 250 1.72645E+32 1.39682E+00 Maximum iterations --------------------------------------------------- Solver : APOPT (v1.0) Solution time : 5.02409999999873 sec Objective : 217.772371342953 Unsuccessful with error code 0
--------------------------------------------------- ---------------------------------------------- Dynamic Estimation with BPOPT Solver ----------------------------------------------
----------------------------------------------------- BPOPT Solver v1.0.6
----------------------------------------------------- Adjusting variables to interior region of bounds Iter Objective Convergence
0 -1.85748E+02 3.38018E+01
1 -1.05777E+02 2.71532E+01
2 1.26905E+02 2.76867E+02
3 4.04640E+03 7.58592E+02
4 1.22410E+08 1.22407E+04
5 1.88476E+03 1.95147E+04
-1.77050E+00 4.25888E+02
9.23784E+02 9.96666E+03
1.38670E+03 1.47370E+04
1.61835E+03 1.71234E+04
1.74542E+03 1.83168E+04
6 1.81543E+03 1.89153E+04
2.56695E+02 1.43715E+03
1.01483E+03 1.00785E+04
1.40039E+03 1.44630E+04
1.59401E+03 1.66629E+04
1.69819E+03 1.77867E+04
7 1.75705E+03 1.83500E+04
8 6.72094E+08 6.72094E+04
5.65658E+02 6.07154E+03
3.69827E+03 3.62246E+04
5.28094E+03 5.14597E+04
6.09958E+03 5.93489E+04
6.50835E+03 6.32875E+04
9 6.71243E+03 6.52535E+04 10 3.42908E+02 3.74813E+03 11 8.25957E+03 3.79110E+03 12 4.75089E+07 4.75089E+03 13 1.75564E+04 1.44171E+04
7.14522E+07 7.14522E+03
9.29139E+07 9.29140E+03
1.14506E+08 1.14506E+04
1.26204E+08 1.26204E+04
1.32081E+08 1.32081E+04 14 1.37395E+08 1.37395E+04 Iter Objective Convergence 15 9.73361E+07 9.73356E+03 16
5.10815E+08 5.10812E+04
3.34519E+03 1.54614E+04
5.68490E+03 3.27431E+04
6.90872E+03 4.19233E+04
7.53574E+03 4.66639E+04
7.82826E+03 4.88168E+04 17 7.97497E+03 4.98979E+04 18 1.02392E+09 1.02392E+05 19 7.77468E+09 7.77468E+05 20 9.02530E+09 1.30137E+06 21 8.22402E+12 8.22402E+08
8.27849E+07 7.85323E+08
6.67868E+07 6.46502E+08
6.68851E+07 6.58066E+08
7.40486E+07 7.34991E+08
7.80379E+07 7.77529E+08 22 8.00766E+07 7.99239E+08 23 8.85462E+12 8.85424E+08
3.10775E+08 2.89271E+08
3.88079E+08 5.70603E+08
4.28405E+08 7.28006E+08
4.48567E+08 8.06703E+08
4.58649E+08 8.46059E+08 24 4.63690E+08 8.65737E+08 25 1.86029E+07 1.48320E+08
1.17713E+10 1.17712E+06
7.44218E+11 7.44216E+07
1.11371E+12 1.11370E+08
1.29845E+12 1.29844E+08
1.39082E+12 1.39082E+08 26 1.43700E+12 1.43700E+08
9.97937E+09 9.97933E+05
7.20196E+11 7.20194E+07
1.07860E+12 1.07860E+08
1.25780E+12 1.25780E+08
1.34740E+12 1.34740E+08 27 1.39221E+12 1.39220E+08
4.87457E+09 4.87453E+05
6.97347E+11 6.97346E+07
1.04477E+12 1.04477E+08
1.21849E+12 1.21848E+08
1.30535E+12 1.30534E+08 28 1.34878E+12 1.34877E+08
7.02507E+04 6.33467E+05
8.46417E+06 6.74433E+07
1.26923E+07 1.01160E+08
1.48064E+07 1.18019E+08
1.58634E+07 1.26448E+08 29 1.63920E+07 1.30662E+08 Iter Objective Convergence 30 6.88703E+05 1.60107E+06
1.15163E+08 8.31826E+05
1.68185E+08 1.21658E+06
1.94691E+08 1.40891E+06
2.07914E+08 1.50487E+06
2.14555E+08 1.55306E+06 31 2.17836E+08 1.57686E+06 *** WARNING MESSAGE FROM SUBROUTINE MA27BD *** INFO(1) = 3
MATRIX IS SINGULAR. RANK= 683 Problem with linear solver, INFO: 3 --------------------------------------------------- Solver : BPOPT (v1.0) Solution time : 4.249999999956344E-002 sec Objective : 528860.935305211 Unsuccessful with error code 0 ---------------------------------------------------
********************************************** Dynamic Estimation with Interior Point Solver
**********************************************
Info: Exact Hessian
****************************************************************************** This program contains Ipopt, a library for large-scale nonlinear optimization. Ipopt is released as open source code under the Eclipse Public License (EPL).
For more information visit http://projects.coin-or.org/Ipopt
******************************************************************************
This is Ipopt version 3.12.10, running with linear solver ma57.
Number of nonzeros in equality constraint Jacobian...: 257 Number of nonzeros in inequality constraint Jacobian.: 324 Number of nonzeros in Lagrangian Hessian.............: 54
Total number of variables............................: 261
variables with only lower bounds: 180
variables with lower and upper bounds: 0
variables with only upper bounds: 0 Total number of equality constraints.................: 99 Total number of inequality constraints...............: 162
inequality constraints with only lower bounds: 162 inequality constraints with lower and upper bounds: 0
inequality constraints with only upper bounds: 0
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls 0 8.8000164e-01 1.05e+01 9.00e+00 0.0 0.00e+00 -
0.00e+00 0.00e+00 0 1 1.0609900e+00 1.05e+01 9.02e+00 -6.7 3.88e+01 - 1.84e-03 1.78e-03h 1 2 9.3143493e+00 1.02e+01 2.21e+01 0.4 3.87e+01 - 1.79e-02 1.98e-02f 1 3 9.3142593e+00 1.02e+01 1.15e+04 -0.3 3.79e+01 - 2.86e-01 2.02e-04h 1 4r 9.3142593e+00 1.02e+01 1.00e+03 1.0 0.00e+00 - 0.00e+00 2.53e-07R 4 5r 5.3654124e+01 8.37e+00 1.16e+03 1.6 2.57e+02 - 2.05e-03 7.22e-03f 1 6 5.3675353e+01 8.36e+00 2.99e+02 -6.2 4.01e+01 - 2.12e-01 7.00e-04h 1 7r 5.3675353e+01 8.36e+00 9.99e+02 0.9 0.00e+00 - 0.00e+00 4.38e-07R 5 8r 1.6618000e+02 2.86e+00 9.90e+02 1.0 6.80e+02 - 2.20e-02 8.16e-03f 1 9 1.6613771e+02 2.86e+00 7.01e+02 -6.2 3.78e+01 - 4.05e-01 5.72e-04h 1 iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls 10r 1.6613771e+02
2.86e+00 9.99e+02 0.5 0.00e+00 - 0.00e+00 3.58e-07R 5 11r 2.2518286e+02 1.89e+00 9.97e+02 1.8 1.58e+03 - 5.31e-03 1.80e-03f 1 12 2.2512388e+02 1.89e+00 1.12e+03 -6.1 3.77e+01 - 4.42e-01 3.90e-04f 1 13r 2.2512388e+02 1.89e+00 1.00e+03 0.3 0.00e+00 - 0.00e+00 4.87e-07R 4 14r 2.2721384e+02 1.87e+00 9.91e+02 -5.9 6.07e+01 - 3.73e-03 7.55e-03f 1 15r 2.2764670e+02 6.34e-01 9.89e+02 1.5 2.10e+04 - 3.96e-03 1.18e-03f 1 16 2.2763736e+02 6.34e-01 5.40e+03 -6.1 1.48e+02 - 4.36e-01 7.99e-05h 1 17r 2.2763736e+02 6.34e-01 1.00e+03 -0.0 0.00e+00 - 0.00e+00 4.00e-07R 2 18r 2.3088007e+02 5.58e-01 9.95e+02 1.9 9.63e+02 - 7.10e-03 2.87e-03f 1 19 2.3089464e+02 5.58e-01 5.63e+04 0.1 1.19e+02 - 4.79e-01 4.76e-04h 1 iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls 20r 2.3089464e+02 5.58e-01 1.00e+03
-0.3 0.00e+00 - 0.00e+00 2.98e-07R 5 21r 2.3319530e+02 5.24e-01 1.31e+03 1.7 1.33e+03 - 1.50e-02 3.54e-03f 1 22r 2.5899287e+02 3.78e-01 1.77e+03 1.9 1.04e+02 - 5.59e-02 4.32e-02f 1 23 2.5842489e+02 3.78e-01 6.85e+02 0.2 6.86e+01 - 8.90e-01 1.48e-03f 3 24 2.5843511e+02 3.82e-01 3.36e+04 0.2 6.84e+01 - 2.20e-01 4.46e-03f 1 25 2.5843515e+02 3.82e-01 1.36e+08 0.2 6.48e+01 - 1.80e-01 4.47e-05h 1 26r 2.5843515e+02 3.82e-01 1.00e+03 0.2 0.00e+00 - 0.00e+00 2.24e-07R 2 27r 2.6284498e+02 2.08e-01 1.34e+03 1.9 1.55e+02 - 7.63e-02 5.34e-03f 1 28 2.6244784e+02 2.08e-01 4.34e+03 0.2 4.59e+01 - 9.14e-01 9.61e-04h 1 29r 2.6244784e+02 2.08e-01 1.00e+03 0.2 0.00e+00 - 0.00e+00 3.01e-07R 6 iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls 30r
2.7090035e+02 2.28e-01 9.50e+02 1.6 7.37e+01 - 2.96e-01 1.63e-02f 1 31r 2.7157286e+02 2.27e-01 9.22e+02 0.4 2.45e+00 - 4.94e-01 3.05e-02f 1 32r 2.7252200e+02 2.29e-01 5.15e+02 -1.1 1.18e+00 - 8.32e-01 4.55e-01f 1 33r 2.8772420e+02 2.25e-01 9.40e+01 -0.7 2.22e+00 - 9.83e-01 9.15e-01f 1 34r 2.8769913e+02 1.95e+00 1.26e+02 -6.6 1.40e+03 - 1.66e-04 1.08e-03f 1 35r 2.9223102e+02 1.54e+00 1.29e+03 -1.2 1.05e+00 0.0 3.03e-01 8.71e-01f 1 36r 2.9225465e+02 1.07e+00 9.01e+02 -0.9 5.35e-01 2.2 4.81e-01 6.15e-01f 1 37r 2.9231013e+02 5.11e-01 1.06e+03 -0.4 2.19e-01 2.7 1.36e-01 1.00e+00f 1 38r 2.9231181e+02 4.23e-01 9.15e+02 -0.6 1.86e-01 3.1 9.06e-02 1.77e-01f 1 39r 2.9231198e+02 4.04e-01 1.12e+03 -0.6 2.11e-01 3.5 2.88e-01 4.46e-02f 1 iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls 40r 2.9231360e+02 3.01e-01
9.53e+02 -0.6 2.60e-01 3.0 6.51e-02 1.35e-01f 1 41r 2.9231693e+02 2.72e-01 1.66e+03 -0.6 2.67e-01 2.6 1.00e+00 9.33e-02f 1 42r 2.9232719e+02 1.98e-01 2.41e+02 -0.6 1.29e-01 3.0 2.20e-01 7.65e-01h 1 43r 2.9243143e+02 2.09e-01 5.65e+02 0.3 2.98e-01 2.5 1.00e+00 2.52e-01f 1 44r 2.9246350e+02 2.10e-01 8.61e+02 -0.4 2.92e-01 2.0 9.92e-01 2.01e-01f 1 45r 2.9245480e+02 2.09e-01 1.93e+02 -1.4 1.20e-01 2.5 1.00e+00 7.37e-01f 1 46r 2.9259452e+02 2.03e-01 1.27e+03 0.2 1.80e+00 2.0 7.20e-01 1.20e-01f 1 47r 2.9277900e+02 2.04e-01 7.72e+02 -0.3 1.25e+00 1.5 3.93e-01 2.34e-01f 1 48r 2.9280994e+02 2.04e-01 5.33e+02 -0.3 1.78e+00 1.0 3.76e-01 1.16e-02h 1 49r 2.9962583e+02 2.28e-01 3.45e+02 -0.3 7.89e-01 0.5 7.13e-01 1.00e+00f 1 iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls 50r 3.2677031e+02 4.59e-01 7.44e+01
-0.3 6.06e-01 - 1.00e+00 7.82e-01f 1 51r 4.2678794e+02 4.44e-01 1.12e+01 -0.3 4.39e+00 - 1.00e+00 1.00e+00f 1 52r 3.4495773e+02 1.99e-01 1.01e+01 -1.0 2.60e+00 - 8.72e-01 1.00e+00f 1 53r 3.4520580e+02 2.23e-01 3.63e+02 -1.0 4.22e-01 0.1 1.00e+00 3.00e-01f 2 54r 3.2340242e+02 2.25e-01 2.00e+00 -1.1 1.11e+00 - 1.00e+00 1.00e+00f 1 55r 2.9817629e+02 2.31e-01 6.43e+01 -2.2 7.79e-01 - 9.99e-01 7.57e-01f 1 56r 2.8673872e+02 2.25e-01 4.58e-01 -2.7 2.41e-01 - 1.00e+00 1.00e+00f 1 57r 2.7428826e+02 2.23e-01 8.35e-02 -3.9 3.26e-01 - 1.00e+00 1.00e+00f 1 58r 2.7154701e+02 2.21e-01 1.36e+00 -4.8 2.86e+00 - 9.99e-01 6.82e-01f 1 59r 2.7155377e+02 2.21e-01 5.33e-03 -4.2 2.28e-02 -0.4 1.00e+00 1.00e+00h 1 iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls 60r
2.7041602e+02 2.21e-01 8.88e+00 -4.9 4.62e+00 - 9.97e-01 1.64e-01h 1 61r 2.7039401e+02 2.21e-01 1.33e-02 -6.0 7.91e-02 -0.9 1.00e+00 9.97e-01h 1 62r 2.7037446e+02 2.21e-01 1.52e-02 -7.6 3.26e-01 -1.4 1.00e+00 1.00e+00f 1 63r 2.7036542e+02 2.21e-01 1.24e-01 -8.6 1.25e+00 -1.8 1.00e+00 1.00e+00f 1 64r 2.7035672e+02 2.21e-01 3.74e+00 -9.0 7.13e+00 -2.3 1.00e+00 1.00e+00f 1 65r 2.7035462e+02 2.21e-01 7.83e-01 -8.7 3.27e+00 -1.9 1.00e+00 1.00e+00h 1 66r 2.7034622e+02 5.19e-01 3.07e+01 -8.5 2.10e+01 -2.4 1.00e+00 1.00e+00f 1 67r 2.7034197e+02 2.66e-01 7.12e+00 -8.8 1.02e+01 -1.9 1.00e+00 1.00e+00f 1 68r 2.7033259e+02 3.97e+01 2.03e+02 -8.9 9.24e+01 -2.4 1.00e+00 1.00e+00f 1 69r 2.6360194e+02 1.39e+01 5.98e+02 -7.3 4.14e+01 - 1.00e+00 1.00e+00h 1 iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls 70r 2.6287479e+02 1.17e+01
4.25e+02 -7.1 1.33e+01 - 1.00e+00 1.00e+00h 1 71r 2.6399459e+02 4.20e+00 3.71e+02 -6.2 1.24e+01 - 1.00e+00 6.63e-01h 1 72r 2.6277485e+02 2.15e-01 1.34e+00 -6.7 5.00e+00 - 1.00e+00 1.00e+00h 1 73r 2.6249804e+02 2.14e-01 8.71e-02 -8.0 2.35e-01 - 1.00e+00 1.00e+00h 1 74r 2.6246138e+02 2.14e-01 1.06e-01 -9.0 1.43e-01 - 1.00e+00 1.00e+00h 1 75r 2.6248456e+02 2.15e-01 3.45e-03 -9.0 2.17e-02 - 1.00e+00 1.00e+00h 1 76r 2.6248458e+02 2.15e-01 3.74e-03 -9.0 2.15e-03 - 1.00e+00 1.00e+00h 1 77r 2.6248458e+02 2.15e-01 1.26e-04 -9.0 4.26e-04 - 1.00e+00 1.00e+00h 1
Number of Iterations....: 77
(scaled) (unscaled) Objective...............: 2.6248457642008947e+02
2.6248457642008947e+02 Dual infeasibility......: 1.9999999998163066e+01 1.9999999998163066e+01 Constraint violation....: 2.1450238157252022e-01 2.1450238157252022e-01 Complementarity.........: 1.0000004294468675e-09
1.0000004294468675e-09 Overall NLP error.......: 1.9999999998163066e+01 1.9999999998163066e+01
Number of objective function evaluations = 118 Number of objective gradient evaluations = 29 Number of equality constraint evaluations = 118 Number of inequality constraint evaluations = 118 Number of equality constraint Jacobian evaluations = 87 Number of inequality constraint Jacobian evaluations = 87 Number of Lagrangian Hessian evaluations
= 78 Total CPU secs in IPOPT (w/o function evaluations) = 0.131 Total CPU secs in NLP function evaluations = 0.053
EXIT: Converged to a point of local infeasibility. Problem may be infeasible. An error occured. The error code is 2
and if I set window_size = 5, the estimation result does not follow true states:
What am I doing wrong?
How should I fix this?
Sorry if I'm asking something that is easily known through studying example, but I still don't get the solution.
Thank you for your kind instruction.
Sincerely, Shane K.
The objective function value from the solver iterations gives a clue that one of the variables is getting very large. It could be related to the divide-by-zero issue that is in the response to Using GEKKO for Moving Horizon Estimation online 2.
One of the equations may be the source of the problem:
self.m.alpha.dt() == self.m.sin(self.m.alpha)/self.m.r - self.m.u
The initial value of r is zero (default) because no initial value is provided when it is declared as self.m.r = self.m.CV(lb=0). A comment suggests that it was formerly initialized with value r_init. The zero value creates a divide-by-zero for that equation. Try rearranging the equation into an equivalent form that avoids the potential for divide-by-zero either with the initial guess or when the solver is iterating.
self.m.r*self.m.alpha.dt() == self.m.sin(self.m.alpha) - self.m.r*self.m.u
The initialization strategies article also gives suggestions on methods to obtain a successful solution:
Safdarnejad, S.M., Hedengren, J.D., Lewis, N.R., Haseltine, E., Initialization Strategies for Optimization of Dynamic Systems, Computers and Chemical Engineering, 2015, Vol. 78, pp. 39-50, DOI: 10.1016/j.compchemeng.2015.04.016.

zsh: no such file or directory error but file exist

I'm trying to run a compiler but I'm getting an error saying it can not be found, but it looks to exist and the path is good. I even tried a different shell incase zsh was mis-configured, but got the same error. Lost at what to do, any suggestions?
6909077c228a% ls -l toolchain/bin/armv7l-timesys-linux-gnueabi-gcc
-rwxr-xr-x 2 root root 2287465 Sep 11 13:19 toolchain/bin/armv7l-timesys-linux-gnueabi-gcc
6909077c228a% ./toolchain/bin/armv7l-timesys-linux-gnueabi-gcc
zsh: no such file or directory: ./toolchain/bin/armv7l-timesys-linux-gnueabi-gcc
#switch to bash
6909077c228a:~$ ./toolchain/bin/armv7l-timesys-linux-gnueabi-gcc
bash: ./toolchain/bin/armv7l-timesys-linux-gnueabi-gcc: No such file or directory
Edit:
Update showing suggestion, don't see any odd character inserted.
6909077c228a% ls -l toolchain/bin/armv7l-timesys-linux-gnueabi-gcc | od -xcb
0000000 722d 7877 2d72 7278 782d 3220 7220 6f6f
- r w x r - x r - x 2 r o o
055 162 167 170 162 055 170 162 055 170 040 062 040 162 157 157
0000020 2074 6f72 746f 3220 3832 3437 3536 5320
t r o o t 2 2 8 7 4 6 5 S
164 040 162 157 157 164 040 062 062 070 067 064 066 065 040 123
0000040 7065 3120 2031 3331 313a 2039 6f74 6c6f
e p 1 1 1 3 : 1 9 t o o l
145 160 040 061 061 040 061 063 072 061 071 040 164 157 157 154
0000060 6863 6961 2f6e 6962 2f6e 7261 766d 6c37
c h a i n / b i n / a r m v 7 l
143 150 141 151 156 057 142 151 156 057 141 162 155 166 067 154
0000100 742d 6d69 7365 7379 6c2d 6e69 7875 672d
- t i m e s y s - l i n u x - g
055 164 151 155 145 163 171 163 055 154 151 156 165 170 055 147
0000120 756e 6165 6962 672d 6363 000a
n u e a b i - g c c \n
156 165 145 141 142 151 055 147 143 143 012
Depending on how you typed in your initial ls -l line, there may be funny characters in the file name. If you use auto completion, it may have put those funny characters in for you so, if you subsequently attempt to type in the file name without auto completion, that could result in a file not found situation.
The first thing you should do is to check the filename completely, with something like:
ls -l toolchain/bin/armv7l-timesys-linux-gnueabi-gcc | od -xcb
and check the output to ensure there's no funny characters in the name.
If the file does exist in that for (no funny characters), one other possibility is that you're trying to run a 32-bit ELF program on a system that's not correctly set up to run them (i.e., a 64-bit system without the libraries and support infrastructure for 32-bit).
That results in an unhelpful error message since it really should be complaining about not being able to find the loader for your 32-bit executable, rather than the executable itself.
If this is the case, you will need to identify those missing items and install them.

Run script on powershell exit

How would I run a powershell script that would run on either, the exit command, or the shell closing. I would want this script to run on every shell close not just for one shell.
Script
Using Register-EngineEvent you can do this:
Register-EngineEvent PowerShell.Exiting –Action { 'Type your Code' }
# Alternatively with hiding the event:
Register-EngineEvent PowerShell.Exiting -SupportEvent –Action { yourExitFunction; }
Get it out of the function and run it in the scriptblock, like this:
Register-EngineEvent PowerShell.Exiting –Action {
$foo = #"
.d8888b. 8888888888 8888888888 Y88b d88P .d88888b. 888 888
d88P Y88b 888 888 Y88b d88P d88P" "Y88b 888 888
"Y888b. 8888888 8888888 Y888P 888 888 888 888
"Y88b. 888 888 888 888 888 888 888
"888 888 888 888 888 888 888 888
Y88b d88P 888 888 888 Y88b. d88P Y88b. .d88P
"Y8888P" 8888888888 8888888888 888 "Y88888P" "Y88888P"
.d8888b. 8888888b. d8888 .d8888b. 8888888888
d88p Y88b 888 Y88b d88888 d88P Y88b 888
"Y888b. 888 d88P d88P 888 888 8888888
"Y88b. 8888888P" d88P 888 888 888
"888 888 d88P 888 888 888 888
Y88b d88P 888 d8888888888 Y88b d88P 888
"Y8888P" 888 d88P 888 "Y8888P" 8888888888
.d8888b. .d88888b. 888 888 888888b. .d88888b. Y88b d88P
d88P Y88b d88P" "Y88b 888 o 888 888 "88b d88P" "Y88b Y88b d88P
888 888 888 888 d888b 888 8888888K. 888 888 Y888P
888 888 888 8888888888888 888 "Y88b 888 888 888
888 888 888 888 88888P Y88888 888 888 888 888 888
Y88b d88P Y88b. .d88P 8888P Y8888 888 d88P Y88b. .d88P 888
"Y8888P" "Y88888P" 888P Y888 8888888P" "Y88888P" 888
"#
$file="c:\.seeyouspacecowboy"
$foo | out-file $file
$colour=("red","yellow","darkyellow","green","cyan","darkcyan","darkmagenta")
[int]$num=-1
$info = (get-content $file)
Write-Host ""
foreach($i in $info)
{
[int]$perspective=($num / 3)
write-host $i -foregroundcolor $colour[$perspective]
$num++
}
Write-Host ""
}
*of course, make sure you are with admin privilege as it write to c:\
Another option is a try-finally block, which will execute the finally block on error or ctrl-c:
try {
# Main code
} finally {
# Code to run on exit
}

how to replace alphabet 'L' with alphabet 'H' in specific column with specific numbers of rows?

i want to replace alphabet "L" with alphabet "H" in coulmn 5 and starting row from 2334 till 2343. how i can do this
ATOM 2328 C PRO H 216 2.775 27.948 31.304 1.00 54.68 C
ANISOU 2328 C PRO H 216 6662 6876 7238 231 -273 -901 C
ATOM 2329 O PRO H 216 3.081 27.188 32.221 1.00 33.86 O
ANISOU 2329 O PRO H 216 4076 4302 4486 297 -305 -920 O
ATOM 2330 CB PRO H 216 0.348 28.666 31.322 1.00 32.21 C
ANISOU 2330 CB PRO H 216 3856 4070 4311 245 -165 -866 C
ATOM 2331 CG PRO H 216 -0.233 27.810 32.376 1.00 35.76 C
ANISOU 2331 CG PRO H 216 4380 4616 4590 319 -134 -850 C
ATOM 2332 CD PRO H 216 -0.205 26.395 31.831 1.00 29.01 C
ANISOU 2332 CD PRO H 216 3545 3784 3691 274 -64 -735 C
TER 2333 PRO H 216
ATOM 2334 N ASP L 1 12.679 9.090 -25.911 1.00 24.97 N
ANISOU 2334 N ASP L 1 3340 2560 3588 66 89 -196 N
ATOM 2335 CA ASP L 1 11.386 9.008 -25.214 1.00 22.13 C
ANISOU 2335 CA ASP L 1 3001 2290 3117 87 13 -178 C
ATOM 2336 C ASP L 1 10.586 10.270 -25.405 1.00 24.75 C
ANISOU 2336 C ASP L 1 3332 2595 3476 107 45 -149 C
ATOM 2337 O ASP L 1 11.150 11.366 -25.533 1.00 25.78 O
ANISOU 2337 O ASP L 1 3423 2631 3741 109 104 -176 O
ATOM 2338 CB ASP L 1 11.594 8.775 -23.699 1.00 23.18 C
ANISOU 2338 CB ASP L 1 3081 2475 3250 109 -77 -274 C
ATOM 2339 CG ASP L 1 12.293 7.471 -23.340 1.00 26.65 C
ANISOU 2339 CG ASP L 1 3535 2947 3645 108 -126 -303 C
ATOM 2340 OD1 ASP L 1 12.541 6.650 -24.258 1.00 24.18 O
ANISOU 2340 OD1 ASP L 1 3268 2622 3300 81 -97 -250 O
ATOM 2341 OD2 ASP L 1 12.537 7.243 -22.126 1.00 26.04 O
ANISOU 2341 OD2 ASP L 1 3432 2911 3553 145 -200 -379 O
ATOM 2342 N ILE L 2 9.260 10.129 -25.359 1.00 19.52 N
ANISOU 2342 N ILE L 2 2706 2012 2698 123 3 -103 N
ATOM 2343 CA ILE L 2 8.371 11.280 -25.505 1.00 19.22 C
ANISOU 2343 CA ILE L 2 2671 1960 2672 154 16 -82 C
.
.
.
.
HETATM 4661 O HOH L2236 8.200 18.486 2.750 1.00 58.70 O
HETATM 4662 O HOH L2237 2.087 16.407 1.748 1.00 45.02 O
HETATM 4663 O HOH L2238 1.933 41.087 7.631 1.00 31.01 O
HETATM 4664 O HOH L2239 4.744 42.515 11.051 1.00 60.18 O
HETATM 4665 O HOH L2240 2.258 41.306 12.333 1.00 45.78 0
expected outcomes
ATOM 2328 C PRO H 216 2.775 27.948 31.304 1.00 54.68 C
ANISOU 2328 C PRO H 216 6662 6876 7238 231 -273 -901 C
ATOM 2329 O PRO H 216 3.081 27.188 32.221 1.00 33.86 O
ANISOU 2329 O PRO H 216 4076 4302 4486 297 -305 -920 O
ATOM 2330 CB PRO H 216 0.348 28.666 31.322 1.00 32.21 C
ANISOU 2330 CB PRO H 216 3856 4070 4311 245 -165 -866 C
ATOM 2331 CG PRO H 216 -0.233 27.810 32.376 1.00 35.76 C
ANISOU 2331 CG PRO H 216 4380 4616 4590 319 -134 -850 C
ATOM 2332 CD PRO H 216 -0.205 26.395 31.831 1.00 29.01 C
ANISOU 2332 CD PRO H 216 3545 3784 3691 274 -64 -735 C
TER 2333 PRO H 216
ATOM 2334 N ASP H 1 12.679 9.090 -25.911 1.00 24.97 N
ANISOU 2334 N ASP H 1 3340 2560 3588 66 89 -196 N
ATOM 2335 CA ASP H 1 11.386 9.008 -25.214 1.00 22.13 C
ANISOU 2335 CA ASP H 1 3001 2290 3117 87 13 -178 C
ATOM 2336 C ASP H 1 10.586 10.270 -25.405 1.00 24.75 C
ANISOU 2336 C ASP H 1 3332 2595 3476 107 45 -149 C
ATOM 2337 O ASP H 1 11.150 11.366 -25.533 1.00 25.78 O
ANISOU 2337 O ASP H 1 3423 2631 3741 109 104 -176 O
ATOM 2338 CB ASP H 1 11.594 8.775 -23.699 1.00 23.18 C
ANISOU 2338 CB ASP H 1 3081 2475 3250 109 -77 -274 C
ATOM 2339 CG ASP H 1 12.293 7.471 -23.340 1.00 26.65 C
ANISOU 2339 CG ASP H 1 3535 2947 3645 108 -126 -303 C
ATOM 2340 OD1 ASP H 1 12.541 6.650 -24.258 1.00 24.18 O
ANISOU 2340 OD1 ASP H 1 3268 2622 3300 81 -97 -250 O
ATOM 2341 OD2 ASP H 1 12.537 7.243 -22.126 1.00 26.04 O
ANISOU 2341 OD2 ASP H 1 3432 2911 3553 145 -200 -379 O
ATOM 2342 N ILE H 2 9.260 10.129 -25.359 1.00 19.52 N
ANISOU 2342 N ILE H 2 2706 2012 2698 123 3 -103 N
ATOM 2343 CA ILE H 2 8.371 11.280 -25.505 1.00 19.22 C
ANISOU 2343 CA ILE H 2 2671 1960 2672 154 16 -82 C
.
.
.
.
HETATM 4661 O HOH L2236 8.200 18.486 2.750 1.00 58.70 O
HETATM 4662 O HOH L2237 2.087 16.407 1.748 1.00 45.02 O
HETATM 4663 O HOH L2238 1.933 41.087 7.631 1.00 31.01 O
HETATM 4664 O HOH L2239 4.744 42.515 11.051 1.00 60.18 O
HETATM 4665 O HOH L2240 2.258 41.306 12.333 1.00 45.78 0
This works for your input sample:
sed '/2334/,/ANISOU 2343/s/ L / H /'
Note that it doesn't check the column number, you might need to tweak the expression to do that.
Using sed:
sed '2334,2343s/\(\([^ ]* \)\{4\}\)L/\1 H/' input
You can use sed:
sed '2334,2343s/\([^ ]* \+\)L/\1H/' input.txt
You can use awk for this:
awk 'NR>=2334 && NR<=2343 {gsub(/L/, "H", $5)} 1' file
Try this awk command,
awk '$2>=2334 && $2<=2343 {gsub(/L/,"H",$5)}1' file

Bash: ls says file not found

I tried the following command
for i in `ls`; do ls $i; done
and got the following output:
ls: a.out: No such file or directory
ls: c: No such file or directory
ls: contest: No such file or directory
ls: cpp: No such file or directory
ls: java: No such file or directory
ls: : No such file or directory
It is confusing since the list of files was also obtained using ls. When I tried to do an od on echo, i see the following:
0000000 033 133 060 155 033 133 060 061 073 063 062 155 141 056 157 165
033 [ 0 m 033 [ 0 1 ; 3 2 m a . o u
0000020 164 033 133 060 155 012
t 033 [ 0 m \n
0000026
0000000 033 133 060 061 073 063 064 155 143 033 133 060 155 012
033 [ 0 1 ; 3 4 m c 033 [ 0 m \n
0000016
0000000 033 133 060 061 073 063 064 155 143 157 156 164 145 163 164 033
033 [ 0 1 ; 3 4 m c o n t e s t 033
0000020 133 060 155 012
[ 0 m \n
0000024
0000000 033 133 060 061 073 063 064 155 143 160 160 033 133 060 155 012
033 [ 0 1 ; 3 4 m c p p 033 [ 0 m \n
0000020
0000000 033 133 060 155 146 151 154 145 056 164 170 164 033 133 060 155
033 [ 0 m f i l e . t x t 033 [ 0 m
0000020 012
\n
0000021
0000000 033 133 060 061 073 063 064 155 152 141 166 141 033 133 060 155
033 [ 0 1 ; 3 4 m j a v a 033 [ 0 m
0000020 012
\n
0000021
0000000 033 133 155 012
033 [ m \n
0000004
What does these "033 [ 0 m" characters stand for? How do I avoid them? Are they the cause of this problem?
Please help.
Thanks,
Karthick S.
You don't need `ls` or $(ls). You can use * instead. This way you avoid fancy colored outputs while leaving your code both portable, readable and compact.
This is #1 in Bash Pitfalls
NEVER use ls as input for another command...
The "033 [ 0 m" characters are escape codes for colouring terminal output. Try using this instead:
for file in $(unset LS_COLORS \ls);
do
ls "$file";
done
Or
for file in $(ls -1 -Q --quoting-style=shell --color=never);
do
ls "$file";
done

Resources