简体   繁体   English

涉及C ++中图形的大型测试用例(使用STL)抛出std :: bad_alloc

[英]Large testcases involving graphs in C++ (using STL) throws std::bad_alloc

We are working on a graph (stored as adjacency list implementation) algorithm implementation which requires us to store the following : 我们正在研究一种图形(存储为邻接表实现)算法实现,该算法实现需要存储以下内容:

  1. An 2-dimensional n into n matrix of distances (stored as an array of floats) 二维n到n距离矩阵(存储为浮点数组)
  2. The number of shortest paths between every pair of vertices (stored as an array of integers). 每对顶点之间的最短路径数(存储为整数数组)。
  3. The predecessors for every vertex taking a given vertex as a source vertex, for all possible choices of source. 对于所有可能的源选择,将给定顶点作为源顶点的每个顶点的前驱体。 This is O(n*n*k) where k is the average number of predecessors for a all vertices over all possible choices of source vertex.In the worst case,this can be upto O(n^3) space. 这是O(n * n * k),其中k是在源顶点的所有可能选择上所有顶点的平均前代数。在最坏的情况下,这可以达到O(n ^ 3)空间。 However the average number of predecessors is likely to be small.(k is a constant). 但是,前任的平均数量可能很小。(k为常数)。 Predecessor is stored as a two level map with the list of predecessors stored as a STL vector. 前任者存储为两级映射,前任者列表存储为STL向量。

We tried testing on large graphs (>2^12 vertices) and this throws a std::bad_alloc after running for some time. 我们尝试在大型图(> 2 ^ 12顶点)上进行测试,并且在运行一段时间后会抛出std :: bad_alloc。 This is the case even when run on 8GB(Ubuntu 12.04) or 16GB using only 3GB of memory. 即使在仅使用3GB内存的8GB(Ubuntu 12.04)或16GB上运行时,也是如此。 Could you tell how we can get large test cases to work or are we going wrong somewhere? 您能否告诉我们如何使大型测试用例工作,或者我们在某个地方出错了?

尝试在64位操作系统上以64位模式编译代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM