Hi, I asked a similar problem days ago and the error is solved by updating the igraph to 0.8.3.
Yesterday I change my code and this error appear again, I try to minimize the problem and reproduce it with a simple iterative graph building code and I attach it here for your testing
Environment: Visual Studio 2019 16.7.3, std=c++14, igraph 0.8.3
Problem: I failed at gCount=44, or the 45 rounds, exactly same error with this: Need help with igraph error:[ igraph_error.c:186: Assertion `no < 100’ failed.’]. but with 0.8.3:
Assertion failed: no < 100, file D:\igraph-0.8.3-msvc\src\igraph_error.c, line 186
sample code: run igraph_debug_test(). Sorry I extract the code from a long pipeline in a hurry, you may need OpenCV for it, or you can change my code to replace that cv::DMatch which is just a matching id storage object.
PS: If anyone can help adjusting the format, I try every option on editor none of them format the code properly.
bool extend1to2(igraph_t& sourceGraph, igraph_t& extendGraph, std::vector <cv::DMatch>& matches) {
if (matches.size() == 0) {
std::cerr << "graph.extend1to2: matches size is zero, invalid extention! return source graph instead!\n";
return true;
}
int n_source_vertices = GAN(&sourceGraph, "n_vertices");
int n_exd_vertices = GAN(&extendGraph, "n_vertices");
std::unique_ptr<igraph_vector_t, void(*)(igraph_vector_t*)>
source_label(new igraph_vector_t(), &igraph_vector_destroy),
exd_label(new igraph_vector_t(), &igraph_vector_destroy),
source_edge_weight(new igraph_vector_t(), &igraph_vector_destroy),
exd_edge_weight(new igraph_vector_t(), &igraph_vector_destroy);
igraph_vector_init(source_label.get(),0);
igraph_vector_init(exd_label.get(), 0);
igraph_vector_init(source_edge_weight.get(), 0);
igraph_vector_init(exd_edge_weight.get(), 0);
VANV(&sourceGraph, "label",source_label.get());
VANV(&extendGraph, "label", exd_label.get());
EANV(&sourceGraph, "weight", source_edge_weight.get());
EANV(&extendGraph, "weight", exd_edge_weight.get());
igraph_t union_graph;
igraph_disjoint_union(&union_graph, &sourceGraph, &extendGraph);
igraph_vector_append(source_label.get(), exd_label.get());
igraph_vector_append(source_edge_weight.get(), exd_edge_weight.get());
SETVANV(&union_graph, "label", source_label.get());
SETEANV(&union_graph, "weight", source_edge_weight.get());
igraph_vector_t contract_vertices_list;
std::vector<igraph_real_t> vertices_ids(igraph_vcount(&union_graph),-1);
for (int k = 0; k < matches.size(); k++) {
vertices_ids[matches[k].queryIdx + n_source_vertices] = matches[k].trainIdx;
}
int count = 0;
for (int i = 0; i < vertices_ids.size(); i++) {
if (vertices_ids[i] == -1.0) {
vertices_ids[i] = count;
count++;
}
}
igraph_vector_view(&contract_vertices_list, vertices_ids.data(), vertices_ids.size());
igraph_attribute_combination_t comb;
igraph_attribute_combination(&comb,
"weight", IGRAPH_ATTRIBUTE_COMBINE_SUM,
"", IGRAPH_ATTRIBUTE_COMBINE_FIRST,
IGRAPH_NO_MORE_ATTRIBUTES);
igraph_contract_vertices(&union_graph, &contract_vertices_list, &comb);
igraph_simplify(&union_graph, 1, 1, &comb);
SETGAN(&union_graph, "n_vertices", igraph_vcount(&union_graph));
SETGAS(&union_graph, "name", GAS(&sourceGraph, "name"));
sourceGraph = union_graph;
}
bool buildFull(std::vector<DMatch>& matches, std::vector<KeyPoint>& kpts, igraph_t& mygraph) {
igraph_init::attri_init();
igraph_integer_t n_vertices = matches.size();
igraph_bool_t loops = false;
if (matches.size() == 0) {
igraph_empty(&mygraph, 0, IGRAPH_UNDIRECTED);
SETGAN(&mygraph, "n_vertices", 0);
SETGAS(&mygraph, "name", "UNDEFINED");
std::cout << "graph.build: warning: zero matches empty graph returned" << std::endl;
return true;
}
int status = igraph_full(&mygraph, n_vertices, false, loops);
SETGAS(&mygraph, "name", "fullgraph");
SETGAN(&mygraph, "n_vertices", n_vertices);
if (status == IGRAPH_EINVAL) {
std::cout << "build full graph: Invalid number of graph vertices" << std::endl;
return false;
}
std::vector<igraph_real_t> labs(n_vertices);
igraph_real_t* labels = labs.data();
for (size_t i = 0; i < n_vertices; i++) {
labs[i] = matches[i].trainIdx;
}
igraph_vector_t lab_vec;
igraph_vector_view(&lab_vec, labels, n_vertices);
SETVANV(&mygraph, "label", &lab_vec);
igraph_simplify(&mygraph, 1, 1, 0);
int n_edges = igraph_ecount(&mygraph);
std::vector<igraph_real_t> w(n_edges);
igraph_real_t* weights = w.data();
for (size_t i = 0; i < n_edges; i++) {
w[i] = 1.0;
}
igraph_vector_t weight_vec;
igraph_vector_view(&weight_vec, weights, n_edges);
SETEANV(&mygraph, "weight", &weight_vec);
igraph_attribute_combination_destroy(&comb);*/
return true;
}
void igraph_debug_test() {
int gCount = 0;
while (gCount != 50) {
for(int i=0;i<1;i++){
int total_num_feats_i = 100;
std::vector<cv::DMatch> dbmatches;
for (int i = 0; i < 100; i++) {
dbmatches.push_back(cv::DMatch(i, i, -1, 0));
}
igraph_t base_graph;
std::vector<cv::KeyPoint> pts;
buildFull(dbmatches, pts, base_graph);
if (GAN(&base_graph, "n_vertices") == 0) {
std::cerr << "nbhdGraph.Next: error: base graph is empty!\n";
break;
}
//extend the graph
for(int j=0;j<2;j++){
std::vector<cv::DMatch> exdmatches;
for (int k = 0; k < 100; k++) {
exdmatches.push_back(cv::DMatch(k, k + 80, -1, 0));
}
igraph_t exd_graph;
std::vector<cv::KeyPoint> pts;
buildFull(exdmatches, pts, exd_graph);
if (GAN(&exd_graph, "n_vertices") == 0) {
std::cerr << "nbhdGraph.Next: error: extend graph is empty!\n";
break;
}
std::vector < cv::DMatch> newMatches;
newMatches.reserve(20);
for (int k = 0; k < 20; k++) {
newMatches.push_back(cv::DMatch(k, k + 80, -1, 0));
}
if (!extend1to2(base_graph, exd_graph, newMatches)) {
std::cerr << "nbhdGraph: error: graph extention failed! with img id " << i << "\n";
break;
}
igraph_destroy(&exd_graph);
}
igraph_destroy(&base_graph);
}
std::cout << "\ngcount: " << gCount;
gCount++;
}
return;
}