void run_persistence( Complex & complex, Cell_less & less, Barcode & barcode, Timer & timer, const Tag tag){ typedef ctl::Filtration< Complex, Cell_less > Filtration; //Boundary Operator //NOTE: This is not a general purpose boundary operator. //It works correctly only when successive //boundaries are taken in a filtration order //typedef typename Filtration::iterator Filtration_iterator; typedef ctl::Filtration_boundary< Filtration> Filtration_boundary; typedef typename Filtration::Term Filtration_term; typedef typename Filtration_term::Coefficient Coefficient; typedef typename ctl::Sparse_matrix< Coefficient> Sparse_matrix; typedef typename ctl::Offset_map< typename Filtration::iterator> Offset_map; typedef typename ctl::Sparse_matrix_map< Coefficient, Offset_map> Chain_map; //produce a filtration timer.start(); Filtration complex_filtration( complex); Filtration_boundary filtration_boundary( complex_filtration); timer.stop(); double complex_filtration_time = timer.elapsed(); //display some info std::cout << "time to compute complex filtration (secs): " << complex_filtration_time << std::endl; //begin instantiate our vector of cascades homology Sparse_matrix R( complex.size()); Offset_map offset_map( complex_filtration.begin()); //we hand persistence a property map for genericity! Chain_map R_map( R.begin(), offset_map); timer.start(); auto times = ctl::persistence( complex_filtration.begin(), complex_filtration.end(), filtration_boundary, R_map, false, offset_map); timer.stop(); double boundary_map_build = times.first; double complex_persistence = times.second; std::cout << "initialize_cascade_data (complex): " << boundary_map_build << std::endl; std::cout << "serial persistence (complex): " << complex_persistence << std::endl; std::cout << "total time : " << timer.elapsed() << std::endl; ctl::compute_barcodes( complex_filtration, R_map, barcode, tag, true); std::vector< std::size_t> bti; compute_betti( complex_filtration, R_map, bti, true); }
/* Uses all of the information calculated so far to set up the various qpDUNES datastructures in preparation for the feedback step. This is really inefficient right now – there's heaps of probably unnecessary copying going on. */ void OptimalControlProblem::initialise_qp() { uint32_t i; real_t Q[NMPC_DELTA_DIM*NMPC_DELTA_DIM]; Eigen::Map<StateWeightMatrix> Q_map(Q); real_t R[NMPC_CONTROL_DIM*NMPC_CONTROL_DIM]; Eigen::Map<ControlWeightMatrix> R_map(R); real_t P[NMPC_DELTA_DIM*NMPC_DELTA_DIM]; Eigen::Map<StateWeightMatrix> P_map(P); real_t g[NMPC_GRADIENT_DIM]; Eigen::Map<GradientVector> g_map(g); real_t C[(NMPC_STATE_DIM-1)*NMPC_GRADIENT_DIM]; Eigen::Map<ContinuityConstraintMatrix> C_map(C); real_t c[NMPC_DELTA_DIM]; Eigen::Map<DeltaVector> c_map(c); real_t zLow[NMPC_GRADIENT_DIM]; Eigen::Map<GradientVector> zLow_map(zLow); real_t zUpp[NMPC_GRADIENT_DIM]; Eigen::Map<GradientVector> zUpp_map(zUpp); zLow_map.segment<NMPC_DELTA_DIM>(0) = lower_state_bound; zUpp_map.segment<NMPC_DELTA_DIM>(0) = upper_state_bound; /* Set up problem dimensions. */ /* TODO: Determine number of affine constraints (D), and add them. */ qpDUNES_setup( &qp_data, OCP_HORIZON_LENGTH, NMPC_DELTA_DIM, NMPC_CONTROL_DIM, 0, &qp_options); return_t status_flag; /* Gradient vector fixed to zero. */ g_map = GradientVector::Zero(); /* Continuity constraint constant term fixed to zero. */ c_map = DeltaVector::Zero(); /* Zero Jacobians for now */ C_map = ContinuityConstraintMatrix::Zero(); Q_map = state_weights; R_map = control_weights; /* Copy the relevant data into the qpDUNES arrays. */ zLow_map.segment<NMPC_CONTROL_DIM>(NMPC_DELTA_DIM) = lower_control_bound; zUpp_map.segment<NMPC_CONTROL_DIM>(NMPC_DELTA_DIM) = upper_control_bound; for(i = 0; i < OCP_HORIZON_LENGTH; i++) { status_flag = qpDUNES_setupRegularInterval( &qp_data, qp_data.intervals[i], 0, Q, R, 0, g, C, 0, 0, c, zLow, zUpp, 0, 0, 0, 0, 0, 0, 0); AssertOK(status_flag); } /* Set up final interval. */ P_map = terminal_weights; status_flag = qpDUNES_setupFinalInterval(&qp_data, qp_data.intervals[i], P, g, zLow, zUpp, 0, 0, 0); AssertOK(status_flag); qpDUNES_setupAllLocalQPs(&qp_data, QPDUNES_FALSE); qpDUNES_indicateDataChange(&qp_data); }