I am attempting to replicate the brachistochrone optimization from this article using pyomo. Unfortunately, I recive an error message due to invalid syntax. The piece of code is as follows:
def f_x_definition_FLIGHT(model, i):
return m.f_x_FLIGHT[i] == math.sqrt(2*g*m.y[i])*math.cos(m.angle[i])
m.f_x_FLIGHT = Constraint(m.N_notinitial rule = f_x_definition_FLIGHT)
The invalid syntax appears in the third line, in m.f_x_FLIGHT =...
I have also constructed the Y-axis dynamic variable as
def f_y_definition_FLIGHT(model, i):
return m.f_y_FLIGHT[i] == math.sqrt(2*g*m.y[i])*math.sin(m.angle[i])
m.f_y_FLIGHT = Constraint(m.N_notinitial rule = f_y_definition_FLIGHT)
And there is no issue there.
The dynamic functions are built as
m.f_x_FLIGHT = Var(m.N_notinitial, domain = Reals)
m.f_y_FLIGHT = Var(m.N_notinitial, domain = Reals)
So I am unable to find the reason why there is a syntax error there
In the end it was the lack of a comma behind m.N_notinitial; the code works fine if written asm.f_x_FLIGHT = Constraint(m.N_notinitial, rule = f_x_definition_FLIGHT)