Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. qf = [] #vector containing the state to compute the objective function
  2. tis0 = ... # containing initialization of t_1,t_2, ...
  3.  
  4. #init integrator
  5. solver = ode(dyn).set_integrator('dopri5')
  6.  
  7. #function to compute the dynamcis
  8. def dyn(t,z,n,N):
  9. #compute dq/dt
  10. dqdt = [0. for i in range(0,n+N)]
  11. dqdt[...] = ... #heaviside function applied to (t-ti) appearing here
  12. dqdt[n:-1] = 0. #dynamics for the (constants) ti
  13. return dqdt
  14.  
  15. #compute the state q
  16. def solout(t,q):
  17. qf.append(q)
  18.  
  19. #function to compute the objective
  20. def objfun(tis):
  21. solver.set_solout(solout)
  22. y0[n:n+N] = tis
  23. solver.set_initial_value(y0,0.).set_f_params(n,N)
  24. solver.integrate(T)
  25. return norm(qf[-1])
  26.  
  27. #argument for the optimization routines : bounds, constraints...
  28. bnds = tuple([(0.,T) for i in range(0,N)])
  29. cons = ({'type':'ineq', 'fun': lambda x: x[0] < x[1]},...)
  30. #call to the optimization routine
  31. res = minimize(objfun,tis0,method='SLSQP',bounds=bnds,constraints=cons)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement