void get_ordering(cholmod_sparse* const NNE, const int MIS_method, const bool directed, std::list<int>& ordering, cholmod_common* const cholmod_c) { cholmod_sparse* adja_mat; switch(MIS_method) { case FSTPOWORDER: if (directed) { // adja_mat = NNE | t(NNE) cholmod_sparse* NNEt = cholmod_transpose(NNE, CHOLMOD_PATTERN, cholmod_c); adja_mat = cholmod_add(NNE, NNEt, NULL, NULL, false, false, cholmod_c); cholmod_free_sparse(&NNEt, cholmod_c); } else { // adja_mat = NNE adja_mat = cholmod_copy_sparse(NNE, cholmod_c); } break; case SNDPOWORDER: case HEURISTIC: adja_mat = get_second_power(NNE, directed, cholmod_c); break; default: error("Unknown MIS method."); } // adja_mat_p: array with pointer to elements for each column // where `i' is start and `i+1' is finish. // Can thus be used to get col sums. const int* const adja_mat_p = static_cast<const int*>(adja_mat->p); std::list<std::pair<int,int> > tmp_order; int n_vertices = static_cast<int>(NNE->ncol); for (int i = 0; i < n_vertices; ++i) { tmp_order.push_back(std::make_pair(adja_mat_p[i + 1] - adja_mat_p[i], i)); } cholmod_free_sparse(&adja_mat, cholmod_c); // sorts first according to colsum (i.e., first el) // then by vertex id. As ID is unique, sorting is stable. tmp_order.sort(); for (std::list<std::pair<int,int> >::const_iterator it = tmp_order.begin(); it != tmp_order.end(); ++it) { ordering.push_back(it->second); } }
void findMaxIS_in_sp(cholmod_sparse* const NNE, const bool directed, std::list<int>& MaxIs, cholmod_common* const cholmod_c) { cholmod_sparse* second_power = get_second_power(NNE, directed, cholmod_c); const int* const sp_p = static_cast<const int*>(second_power->p); const int* const sp_i = static_cast<const int*>(second_power->i); bool inSetI[NNE->ncol]; std::fill_n(inSetI, NNE->ncol, true); int removed_indices[NNE->ncol]; int sizeMaxIS = 0; recur_MaxIS(inSetI, 0, removed_indices, removed_indices + NNE->ncol, sp_p, sp_i, 0, &sizeMaxIS, MaxIs); cholmod_free_sparse(&second_power, cholmod_c); }
/** * \brief Apply the forced movement to the items representing a power for the * case where there are three power. * \param item The item for the third power. */ void ptb::power_effect::apply_movement_3( bear::engine::base_item& item ) { bear::universe::forced_rotation f( create_forced_movement() ); const double ref_angle = get_center_of_mass().slope_angle ( get_first_power()->get_center_of_mass() ); double a = ref_angle - 2 * 3.14159 / 3; f.set_start_angle(a); f.set_end_angle(a + 2 * 3.14159); item.set_forced_movement(f); a = ref_angle + 2 * 3.14159 / 3; f.set_start_angle(a); f.set_end_angle(a + 2 * 3.14159); get_second_power()->set_forced_movement(f); } // power_effect::apply_movement_3()