int float_vectors(float vector1[], float vector2[], int size) { for (int i = 0; i < size; i++){ if ((vector1[i] >= (vector2[i] + 0.0005)) || (vector1[i] <= (vector2[i] - 0.0005))){ print_float_vector(vector1, size); print_float_vector(vector2, size); printf("%f != %f\n", vector1[i], vector2[i]); return(0); } } return(1); }
std::string JSON_printer::print_float_vec_vector(std::vector<std::vector<float>> vec) { std::string out_string = "["; for (int i = 0; i < vec.size(); i++) { out_string = out_string + print_float_vector(vec[i]); if (i != vec.size() - 1) { out_string = out_string + ","; } } out_string.append("]"); return out_string; }
std::string JSON_printer::print_vectors_with_info(std::string graph_name, int num_nodes, int num_edges, std::vector<std::vector<float>> rel_counts, std::vector<std::vector<int> > abs_counts) { std::vector<int> two_graphletsABS = abs_counts[0]; std::vector<int> three_graphletsABS = abs_counts[1]; std::vector<int> four_graphletsABS = abs_counts[2]; std::vector<int> five_graphletsABS = abs_counts[3]; std::vector<float> two_graphletsNORM = rel_counts[0]; std::vector<float> three_graphletsNORM = rel_counts[1]; std::vector<float> four_graphletsNORM = rel_counts[2]; std::vector<float> five_graphletsNORM = rel_counts[3]; std::string quot_marks = "\""; std::string out_str = "{ \"Graphname\" : " + quot_marks + graph_name + quot_marks + ", \"Number of vertices\" : " + std::to_string(num_nodes) + ", "; out_str = out_str + "\"Number of edges\" : " + std::to_string(num_edges) + ", "; std::string abs_str = "\"Absolute Counts\" : { "; std::string norm_str = "\"Normalized Counts\" : { "; if (two_graphletsABS.empty()) { abs_str += "\"2-graphlets\" : null, "; } else { abs_str += "\"2-graphlets\" : " + print_int_vector(two_graphletsABS) + ", "; } if (three_graphletsABS.empty()) { abs_str += "\"3-graphlets\" : null, "; } else { abs_str += "\"3-graphlets\" : " + print_int_vector(three_graphletsABS) + ", "; } if (four_graphletsABS.empty()) { abs_str += "\"4-graphlets\" : null, "; } else { abs_str += "\"4-graphlets\" : " + print_int_vector(four_graphletsABS) + ", "; } if (five_graphletsABS.empty()) { abs_str += "\"5-graphlets\" : null}"; } else { abs_str += "\"5-graphlets\" : " + print_int_vector(five_graphletsABS) + "}, "; } out_str += abs_str; if (two_graphletsNORM.empty()) { norm_str += "\"2-graphlets\" : null, "; } else { norm_str += "\"2-graphlets\" : " + print_float_vector(two_graphletsNORM) + ", "; } if (three_graphletsNORM.empty()) { norm_str += "\"3-graphlets\" : null, "; } else { norm_str += "\"3-graphlets\" : " + print_float_vector(three_graphletsNORM) + ", "; } if (four_graphletsNORM.empty()) { norm_str += "\"4-graphlets\" : null, "; } else { norm_str += "\"4-graphlets\" : " + print_float_vector(four_graphletsNORM) + ", "; } if (two_graphletsNORM.empty()) { norm_str += "\"5-graphlets\" : null}"; } else { norm_str += "\"5-graphlets\" : " + print_float_vector(five_graphletsNORM) + "}"; } out_str += norm_str + "}"; return out_str; }