Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Failures due to tangent in nonlinear constraint, and Couenne error #15

Open
jelavice opened this issue Mar 11, 2016 · 1 comment
Open

Comments

@jelavice
Copy link

first version of model with tangent

using JuMP
using CoinOptServices
dt = 0.10;        # sampling time
L = 1; 
g = 9.81;
mu = 0.8;
N = 5 # prediction horizont
mdl = Model(solver = OsilCouenneSolver())
err = 0;
δ_traj = zeros(N);
a_traj = zeros(N);
x_traj = zeros(N+1);
y_traj = zeros(N+1);
ψ_traj = zeros(N+1);
v_traj = zeros(N+1);
errLateral = minimum([err 0.2]);
rateLimits = [20*pi/180, 10];
δ_old = 0;
a_old = 0;
@defNLParam(mdl, δ_ref[i=1:N] == δ_traj[i])
@defNLParam(mdl, a_ref[i=1:N] == a_traj[i])
@defNLParam(mdl, x_ref[i=1:(N+1)] == x_traj[i])
@defNLParam(mdl, y_ref[i=1:(N+1)] == y_traj[i])
@defNLParam(mdl, ψ_ref[i=1:(N+1)] == ψ_traj[i])
@defNLParam(mdl, v_ref[i=1:(N+1)] == v_traj[i])
@defNLParam(mdl, D == errLateral)
@defVar(mdl, x[1:(N+1)])
@defVar(mdl, y[1:(N+1)])
@defVar(mdl, ψ[1:(N+1)])
@defVar(mdl, v[1:(N+1)])
@defVar(mdl, δ[1:N])
@defVar(mdl, a[1:N])
@defVar(mdl, p[1:3], Bin)
Q = eye(4);
R = eye(2);
@setNLObjective(mdl, Min, sum{ Q[1,1]*(x[i] - x_ref[i])^2 + Q[2,2]*(y[i] - y_ref[i])^2 + Q[3,3]*(ψ[i] - ψ_ref[i])^2 + Q[4,4]*(v[i] - v_ref[i])^2, i = 2:N} + 
                          sum{100*(ψ[i+1] - ψ[i])^2 ,i=1:N} +
                          sum{ R[1,1]*(δ[i] - δ_ref[i])^2 + R[1,1]*(a[i] - a_ref[i])^2 , i=1:N} +
                          Q[1,1]*(x[N+1] - x_ref[N+1])^2 + Q[2,2]*(y[N+1] - y_ref[N+1])^2 + Q[3,3]*(ψ[N+1] - ψ_ref[N+1])^2 + Q[4,4]*(v[N+1] - v_ref[N+1])^2 );
x0 = 0;
y0 = 0;
ψ0 = 0;
v0 = 0;
@addNLConstraint(mdl, x[1] == x0)
@addNLConstraint(mdl, y[1] == y0)
@addNLConstraint(mdl, ψ[1] == ψ0)
@addNLConstraint(mdl, v[1] == v0)
@addNLConstraint(mdl,  abs(δ[1] - δ_old) <= rateLimits[1]*dt);
@addNLConstraint(mdl,  abs(a[1] - a_old) <= rateLimits[2]*dt);
for i = 1:N
    @addNLConstraint(mdl, x[i+1] == x[i] +dt*v[i]*cos(ψ[i]));       
    @addNLConstraint(mdl, y[i+1] == y[i] +dt*v[i]*sin(ψ[i]));       
    @addNLConstraint(mdl, ψ[i+1] == ψ[i] +dt*v[i]*tan(δ[i])/L); # CHANGEME
#    @addNLConstraint(mdl, ψ[i+1] == ψ[i] +dt*v[i]*sin(δ[i])/(L*cos(δ[i])));  
    @addNLConstraint(mdl, x[i+1] == v[i] +dt*a[i]); 
    @addNLConstraint(mdl, abs(δ[i]) <= 30*pi/180);       
    @addNLConstraint(mdl, abs(a[i]) <= mu*g/4);     
    if i < N
        @addNLConstraint(mdl, abs(δ[i+1] - δ[i]) <= rateLimits[1]*dt);
        @addNLConstraint(mdl, abs(a[i+1] - a[i]) <= rateLimits[1]*dt);
    end
    @addNLConstraint(mdl, abs(ψ[i] - ψ_ref[i])  <= 45*pi/180 );
    if i <= N
        @addNLConstraint(mdl, abs(ψ[i+1] - ψ[i])  <= dt*30*pi/180);
    end
end
for i=1:3
    @addNLConstraint(mdl, p[i]*( (x[N+1] - x_ref[(N+1)-i+1])^2 + (y[N+1] - y_ref[(N+1)-i+1])^2 ) <= D^2);
    @addNLConstraint(mdl, p[i]*(abs(ψ[N+1] - ψ_ref[(N+1)-i+1])) <= 5*pi/180);                 
end             
@addNLConstraint(mdl, sum{p[i] ,i=1:3} >= 1);
solve(mdl)

This is using Julia 0.4.3 on 32 bit Windows. With tan in the constraint line that says # CHANGEME this gives an error from OSSolverService:

<message>encountered a spurious character in the lexer
The first character is: <
See line number: 546

Replacing the tan with sin/cos results in Couenne exiting. OsilBonminSolver and CouenneNLSolver both work fine here.

tkelman added a commit that referenced this issue Mar 11, 2016
@tkelman
Copy link
Contributor

tkelman commented Mar 11, 2016

Thanks Edo. 3e072fe works around the issue with tangent, giving a more sane Julia error message for now. The underlying solvers seem able to handle tangent since AmplNLWriter works, so I should probably report this along with the Couenne exiting issue to the upstream Optimization Services developers if I can reproduce on their latest version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants