#line_handles = ax.plot(x_endeff,y_endeff,linewidth=0.5)
    #line_handles = ax.plot(t,cost_vars[:,1:1+n_dofs],linewidth=0.5)
    line_handles = ax.plot(x_endeff, y_endeff, linewidth=0.5)
    ax.plot(0.5, 0.5, 'or')
    ax.axis('equal')
    return line_handles


if __name__ == '__main__':

    for n_dofs in [3]:

        # Initialize a viapoint task and save it to file
        viapoint = 0.5 * np.ones(2)  # Always 2D!
        task = TaskViapoint(viapoint)
        directory = "./demoOptimizationDmpArm2DDataTmp/" + str(n_dofs) + "D/"
        task.saveToFile(directory, "viapoint_task.txt")

        # Call the executable with the directory to which results should be written
        print("Call executable to run optimization with " + str(n_dofs) +
              "D viapoint.")
        executable = "./demoOptimizationDmpArm2D"
        print(executeBinary(executable, str(n_dofs) + " " + directory))

        print("  Plotting")
        fig = plt.figure(n_dofs, figsize=(12, 4))
        plotOptimizationRollouts(directory, fig, plotRollout)
        #plotOptimizationRolloutsTask(directory,fig,task)

    print("Showing")
lib_path = os.path.abspath('../')
sys.path.append(lib_path)
from executeBinary import executeBinary

lib_path = os.path.abspath('../../python/')
sys.path.append(lib_path)
from dmp_bbo.dmp_bbo_plotting import plotOptimizationRollouts
from dmp_bbo.dmp_bbo_plotting import plotOptimizationRolloutsTask
from dmp_bbo.tasks.TaskViapoint import TaskViapoint

if __name__=='__main__':
    
    # Initialize a viapoint task and save it to file
    n_dims = 2
    viapoint = np.linspace(1.5,2,n_dims)
    viapoint_time = 0.2
    viapoint_radius = 0.0
    task = TaskViapoint(viapoint,viapoint_time, viapoint_radius)
    directory = "/tmp/demoOptimizationDmpParallel/"+str(n_dims)+"D/"
    task.saveToFile(directory,"viapoint_task.txt")
    
    # Call the executable with the directory to which results should be written
    executable = "../../bin/demoOptimizationDmpParallel"
    executeBinary(executable, directory)
      
    fig = plt.figure(1,figsize=(12, 4))
    plotOptimizationRolloutsTask(directory,fig,task)
    plt.show()
    

        dmp = Dmp(tau, y_init, y_attr, function_apps)
    
        # Make the task
        viapoint = 3*np.ones(n_dims)
        viapoint_time = 0.3
        if n_dims==2:
            # Do not pass through viapoint at a specific time, but rather pass
            # through it at any time.
            viapoint_time = None
        viapoint_radius=0.1
        goal=y_attr
        goal_time=1.1*tau
        viapoint_weight=1.0
        acceleration_weight=0.0001
        goal_weight=0.0
        task = TaskViapoint(viapoint,viapoint_time, viapoint_radius, goal,goal_time,viapoint_weight, acceleration_weight,goal_weight)


        # Make task solver, based on a Dmp
        dt = 0.01
        integrate_dmp_beyond_tau_factor = 1.5
        task_solver = TaskSolverDmp(dmp,dt,integrate_dmp_beyond_tau_factor);
    
        n_search =  dmp.getParameterVectorSelectedSize()
    
        covar_update = 'decay'
        mean_init  =  np.full(n_search,0.0)
        covar_init =  1000.0*np.eye(n_search)
        distribution = DistributionGaussian(mean_init, covar_init)
        
        eliteness = 10