InteractionGraph::InteractionGraph(MILPP* problem) : graph_t(problem->get_num_cols()) { int ri; /* row index */ int ci; /* col index */ int ni; /* neighbor index */ PackedVector* row; problem_ = problem; /* Start forming variable neighbourhoods by using constraints */ for (ri = 0; ri < problem->get_num_rows(); ri++) { row = problem->get_row(ri); for (ci = 0; ci < row->get_num_elements(); ci++) for (ni = 0; ni < row->get_num_elements(); ni++) { if ((ci == ni) || /* Skip variables with the same index */ edge(row->get_index_by_pos(ci), row->get_index_by_pos(ni), *this).second) continue; /* Add variable with index n as a neighbor for a variable with index c*/ add_edge(row->get_index_by_pos(ci), row->get_index_by_pos(ni), *this); } } }
void MILPP::set_cons_matrix(const PackedMatrix* matrix) { cons_matrix_ = *matrix; for (int i = 0; i < get_num_rows(); i++) { PackedVector* row = get_row(i); for (int j = 0; j < row->get_num_elements(); j++) { col_to_row_mapping_[ row->get_index_by_pos(j) ]->insert(i); row_to_col_mapping_[i]->insert( row->get_index_by_pos(j) ); } } }
void MILPP::print() { int i; int j; int offset; /* Print objective function sense and its coefficients */ for (int i = 0; i < get_num_cols(); ++i) { if (i) printf(" + "); printf("%.1fx%d", get_obj_coef(i), i); } printf(" -> %s\n", obj_sense_to_string()); /* Print constraints represented by rows */ printf("subject to\n"); for (i = 0; i < cons_matrix_.get_num_rows(); i++) { int t = 0; /* start from col zero */ PackedVector* row = cons_matrix_.get_vector(i); printf("(%d) ", i); for (j = 0; j < row->get_num_elements(); j++) { if (j > 0) printf(" + "); //printf("[%d|%d]", row->get_index_by_pos(j), t); if ((offset = row->get_index_by_pos(j) - t) >= 1) { if (j > 0) offset -= 1; //printf("(%d)", offset); offset *= 5 + 3; for (int s = 0; s < offset; s++) printf(" "); } t = row->get_index_by_pos(j); printf("%.1fx%d", row->get_element_by_pos(j), row->get_index_by_pos(j)); } /* Print row sense */ printf(" <= "); /* Print row upper bound */ printf("%.1f", get_row_upper_bound(i)); printf("\n"); } }