Thank you, I've realised my mistake and corrected the code. It now works as expected! Thanks On Sep 25, 2015 1:28 PM, "Miles Lubin" <[email protected]> wrote:
> It's not too clear to me what's trying to be accomplished here, but "gear" > and "N" are optimization variables and can't be used inside conditional > statements. You can use getValue() to query the value of the variables in > an optimal solution after calling solve(). If these statements are supposed > to be constraints in the optimization problem, you'll have to reformulate > them into standard nonlinear programming form, possibly with the addition > of integer variables to model logical relationships. > > On Friday, September 25, 2015 at 10:22:15 AM UTC-4, NV wrote: >> >> Yes, I have a transmission model to implement. I used the following code. >> But I need it to run for as long as I have initialized the time variable to. >> >> using JuMP, Ipopt >> Truck = Model(solver=IpoptSolver(print_level=0)) >> #Initial Values >> gear_0 = 1 >> v_0 = 20 >> N_0 = 600 >> #Constants: >> i_f = 3.27 >> eta_f = 0.95 >> eta_t = 0.95 >> r_w = 0.52 >> i = [11.27; 9.14; 7.17; 5.81; 4.62; 3.75; 3.01; 2.44; 1.91; 1.55; 1.23; 1] >> #Discretization >> n = 500 >> @defVar(Truck,Δt≥0,start = 1/n) >> @defNLExpr(t_f,Δt*n) >> @defVar(Truck,600<=N[1:n]<=2500) >> @defVar(Truck,1<=gear[1:n]<=12) >> @defVar(Truck,i_t[1:n]) >> @addConstraint(Truck,N[0]==N_0) >> @addConstraint(Truck,gear[0]==gear_0) >> @addConstraint(Truck,i_t[0]==i[1]) >> @defNLExpr(N[j=0:n],(30*i_t[j]*i_f)/(pi*r_w)) >> for j in 1:1:n >> if(gear[j]==1) >> if(N[j]>=1500) >> gear[j+1]= 2 >> else >> gear[j+1] = 1 >> end >> elseif(gear[j]==2) >> if(N[j]>=1501) >> gear[j+1] = 3 >> elseif(N[j]<=950) >> gear[j+1]= 1 >> else >> gear[j+1] = 2 >> end >> elseif(gear[j]==3) >> if(N[j]>=1502) >> gear[j+1] = 4 >> elseif(N[j]<=960) >> gear[j+1] = 2 >> else >> gear[j+1] = 3 >> end >> elseif(gear[j]==4) >> if(N[j]>=1503) >> gear[j+1] = 5; >> elseif(N[j]<=970) >> gear[j+1] = 3 >> else >> gear[j+1] = 4 >> end >> elseif(gear[j]==5) >> if(N[]>=1504) >> gear[j+1] = 6; >> elseif(N[j]<=980) >> gear[j+1] = 4 >> else >> gear[j+1] = 5 >> end >> elseif(gear[j]==6) >> if(N[j]>=1505) >> gear[j+1] = 7 >> elseif(N[j]<=990) >> gear[j+1] = 5 >> else >> gear[j+1] = 6 >> end >> elseif(gear[j]==7) >> if(N[j]>=1497) >> gear[j+1] = 8 >> elseif(N[j]<=1000) >> gear[j+1] = 6 >> else >> gear[j+1] = 7 >> end >> elseif(gear[j]==8) >> if(N[j]>=1489) >> gear[j+1] = 9 >> elseif(N[j]<=1006) >> gear[j+1] = 7 >> else >> gear[j+1] = 8 >> end >> elseif(gear[j]==9) >> if(N[j]>=1481) >> gear[j+1] = 10 >> elseif(N[j]<=1012) >> gear[j+1] = 8 >> else >> gear[j+1] = 9 >> end >> elseif(gear[j]==10) >> if(N[j]>=1473) >> gear[j+1] = 11 >> elseif(N[j]<=1018) >> gear[j+1] = 9 >> else >> gear[j+1] = 10 >> end >> elseif(gear[j]==11) >> if(N[j]>=1465) >> gear[j+1] = 12 >> elseif(N[j]<=1024) >> gear[j+1] = 10 >> else >> gear[j+1] = 11 >> end >> elseif(gear[j]==12) >> if(N[j]<=1030) >> gear[j+1] = 11 >> else >> gear[j+1] = 12 >> end >> end >> i_t[j] = i[gear[j+1]] >> end >> >> To solve for the system dynamics, I am following the example in >> http://www.juliaopt.org/notebooks/JuMP-Rocket.html . I tried passing >> gear position(gear), engine rpm(N) and transmission ratio(i_t) as variables >> and have added the necessary constraints as well. However, on trying to run >> it, I kept getting an error: >> >> >> The comparison operator == has been deprecated for constructing constraints. >> Use the macro form @addConstraint instead. >> >> >> LoadError: TypeError: non-boolean >> (JuMP.GenericRangeConstraint{JuMP.GenericAffExpr{Float64,JuMP.Variable}}) >> used in boolean context >> while loading In[2], in expression starting on line 30 >> >> in anonymous at no file >> >> >> On Friday, 25 September 2015 08:18:53 UTC-5, Spencer Russell wrote: >>> >>> Welcome to Julia! >>> >>> To get useful answers you’re going to need to provide quite a bit more >>> detail on what problems you’re running into. What did you try? What errors >>> are you getting? Are there specific concepts from the documentation that >>> you’re having trouble with? >>> >>> -s >>> >>> > On Sep 25, 2015, at 1:18 AM, Narayani Vedam <[email protected]> >>> wrote: >>> > >>> > Hi, >>> > I am new to Julia. I tried implementing a logic that I had in >>> Simulink - Stateflow using Julia, but ran into trouble. Any heads-up on >>> this? >>> > >>> > Thank you >>> >>>
