Пример #1
0
    # bounds
    ocp.bound('thrust',(-1.3,0.9))
    ocp.bound('pos',(-10,10))
    ocp.bound('vel',(-10,10))
    ocp.bound('mass',(0.001,1000))

    # boundary conditions
    ocp.bound('pos',(0,0),timestep=0)
    ocp.bound('pos',(5,5),timestep=-1)

    ocp.bound('vel',(0,0),timestep=0)
    ocp.bound('vel',(0,0),timestep=-1)

    ocp.bound('mass',(1,1),timestep=0)

    ocp.guess("pos",0)
    ocp.guess("vel",0)
    ocp.guess("mass",1)
    ocp.guess("thrust",0)

    # lookup states/actions/outputs/params
    thrust4 = ocp.lookup('thrust',timestep=4)
    thrust4 = ocp('thrust',timestep=4)

    # can specify index of collocation point
    posvel4_2 = ocp('posvel',timestep=4, degIdx=2)

    # add nonlinear constraint
    ocp.constrain(thrust4, '<=', posvel4_2**2)

    # fix objective and setup solver
Пример #2
0
    ocp.setupCollocation( endTime )

    # bounds
    ocp.bound('abspos',(0,10))
    ocp.bound('pos',(-1000,1000))
    ocp.bound('vel',(-100,100))
    ocp.bound('force',(-30,30))

    # boundary conditions
    ocp.bound('pos',(5,5),timestep=0)
    ocp.bound('pos',(0.1,0.1),timestep=-1)

    ocp.bound('vel',(0,0),timestep=0)
    ocp.bound('vel',(0,0),timestep=-1)

    ocp.guess("abspos",0)
    ocp.guess("pos",0)
    ocp.guess("vel",0)
    ocp.guess("force",0)
    
    # add slacks
    for k in range(N):
        for j in range(ocp.deg+1):
            pos =    ocp('pos',   timestep=k, degIdx=j)
            abspos = ocp('abspos',timestep=k, degIdx=j)
            
            ocp.constrain(    pos, '<=', abspos)
            ocp.constrain(-abspos, '<=',    pos)
    pos =    ocp('pos',   timestep=N, degIdx=0)
    abspos = ocp('abspos',timestep=N, degIdx=0)
    ocp.constrain(    pos, '<=', abspos)
Пример #3
0
    ocp.setupCollocation( endTime )

    # bounds
    ocp.bound('abspos',(0,10))
    ocp.bound('pos',(-1000,1000))
    ocp.bound('vel',(-100,100))
    ocp.bound('force',(-30,30))

    # boundary conditions
    ocp.bound('pos',(5,5),timestep=0)
    ocp.bound('pos',(0.1,0.1),timestep=-1)

    ocp.bound('vel',(0,0),timestep=0)
    ocp.bound('vel',(0,0),timestep=-1)

    ocp.guess("abspos",0)
    ocp.guess("pos",0)
    ocp.guess("vel",0)
    ocp.guess("force",0)

    # add slacks
    for k in range(N):
        for j in range(ocp.deg+1):
            pos =    ocp('pos',   timestep=k, degIdx=j)
            abspos = ocp('abspos',timestep=k, degIdx=j)

            ocp.constrain(    pos, '<=', abspos)
            ocp.constrain(-abspos, '<=',    pos)
    pos =    ocp('pos',   timestep=N, degIdx=0)
    abspos = ocp('abspos',timestep=N, degIdx=0)
    ocp.constrain(    pos, '<=', abspos)