I am working on implementing the Brachistochrone problem in Pyomo using Chebishev optimization as defined in this article.
The initial conditions of the problem state that x(0)=y(0)=0.
However, once I run the code I obtain the following error
Error evaluating constraint 1: can't evaluate sqrt'(0).
I have written my variables as
def x_initialize (model,i):
return 0.5*(i/value(m.n))
m.x = Var(m.N, within = NonNegativeReals, initialize = x_initialize)
def y_initialize (model,i):
return 0.5*((i)/value(m.n))
m.y = Var(m.N, within = NonNegativeReals, initialize = y_initialize)
and
def f_x_definition(model, i):
return m.f_x[i] == sqrt(2*g*m.y[i])*cos(m.angle[i])
m.f_x_const = Constraint(m.N, rule = f_x_definition)
def f_y_definition(model, i):
return m.f_y[i] == sqrt(2*g*m.y[i])*sin(m.angle[i])
m.f_y_const = Constraint(m.N, rule = f_y_definition)
I have tried to add a small number to def x_initialize (model,i): and def y_initialize (model,i): to compensate, but then, the program returned a restoration failed error. Another attempt has been to use **(1/2) instead of sqrt, but it hasn't worked either.
I can't think of any other solution to solve this issue.
Regards.
In the end I have manually introduced the value for i=0 using an if as
def f_x_definition(model, i):
if i == 0:
return m.f_x[i] ==0
else:
return m.f_x[i] == ((2*g*m.y[i])**(1/2))*cos(m.angle[i])