void DirectMultipleShootingInternal::setOptimalSolution(const vector<double> &V_opt){
  // OCP solution
  Matrix<double> &p_opt = output(OCP_P_OPT);
  Matrix<double> &x_opt = output(OCP_X_OPT);
  Matrix<double> &u_opt = output(OCP_U_OPT);
  
  // Running index
  int el=0;

  // Pass optimized state
  for(int i=0; i<np_; ++i){
    p_opt(i) = V_opt[el++];
  }
    
  for(int k=0; k<nk_; ++k){
    
    // Pass optimized state
    for(int i=0; i<nx_; ++i){
      x_opt(i,k) = V_opt[el++];
    }
    
    // Pass optimized control
    for(int i=0; i<nu_; ++i){
      u_opt(i,k) = V_opt[el++];
    }
  }

  // Pass optimized terminal state
  for(int i=0; i<nx_; ++i){
    x_opt(i,nk_) = V_opt[el++];
  }
  casadi_assert(el==V_opt.size());
}
void DirectSingleShootingInternal::setOptimalSolution(const vector<double> &V_opt){
  // OCP solution
  Matrix<double> &p_opt = output(OCP_P_OPT);
  Matrix<double> &x_opt = output(OCP_X_OPT);
  Matrix<double> &u_opt = output(OCP_U_OPT);
  
  // Running index
  int el=0;

  // Pass optimized parameters
  for(int i=0; i<np_; ++i){
    p_opt(i) = V_opt[el++];
  }
    
  // Pass optimized initial state
  for(int i=0; i<nx_; ++i){
    x_opt(i,0) = V_opt[el++];
  }
  
  // Pass optimized control
  for(int k=0; k<nk_; ++k){
    for(int i=0; i<nu_; ++i){
      u_opt(i,k) = V_opt[el++];
    }
  }
  casadi_assert(el==V_opt.size());

  // Evaluate the constraint function to get the rest of the state trajectory
  G_.setInput(V_opt);
  G_.evaluate();
  const vector<double>& g_opt = G_.output().data();

  // Loop over the constraints
  el = 0;
  for(int k=0; k<nk_; ++k){

    // Get the state trajectory
    for(int i=0; i<nx_; ++i){
      x_opt(i,k+1) = g_opt[el++];
    }
    
    // Skip the path constraints (for now)
    el += nh_;
  }
  casadi_assert(el==g_opt.size());
}