贴出程序,关于corrupted double-linked list错误的问题
在 Linux 下面用 g++ 编译,运行通过。
但是程序跑到最后,该算出的正确结果也已经算出来了,可是就在最后一句出现。
*** Error in `./KL2': corrupted double-linked list: 0x08553170 *** 的错误提示。
#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
#include<time.h>
#include<vector>
#define M 14
#define N 2
using std::cout;
using std::endl;
using std::vector;
using namespace std;
int main(int argc, char* argv[])
{
int i,j,Numnode,Numedge;
ifstream openfile(argv[1]);
openfile>>Numnode>>Numedge; // Still running
int **data;
data=new int* [Numedge];
for(i=0;i<Numedge+1; i++)
data[i]=new int [2];
data[0][0]=Numnode;
data[0][1]=Numedge;
for(i=1;i<Numedge+1;i++)
{
openfile>>data[i][0]>>data[i][1];
}
cout<<"-1"<<endl;
Numnode=data[0][0]; // The number of nodes in this graph
Numedge=data[0][1]; // The number of edges in this graph
//vector<vector<int> > c(Numnode+2,vector<int>(Numnode+2));
int **c;
c=new int* [Numnode];
for(i=0;i<Numnode; i++)
c[i]=new int [Numnode];
int cindex1,cindex2;
for(i=0;i<Numnode;i++)
{
for(j=0; j<Numnode; j++)
{
c[i][j]=0;
}
}
cout<<"Numedge"<<Numedge<<endl;
for(i=1;i<Numedge;i++)
{
cindex1=data[i][0]-1;
cindex2=data[i][1]-1;
cout<<"i="<<i<<endl<<cindex1<<cindex2<<endl;
cout<<c[cindex1][cindex2]<<endl;
c[cindex1][cindex2]=1;
c[cindex2][cindex1]=1;
cout<<c[cindex1][cindex2]<<endl;
}
cout<<"00000"<<endl;
//openfile.close(); //// We stopped here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
cout<<"0"<<endl;
//determine a balanced initial partition of the nodes into sets A and B
int *a;
a=new int [Numnode/2];
int *b;
b=new int [Numnode/2];
for(i=0;i<Numnode;i++)
{
if (i<Numnode/2) // odd
a[i]=i+1; // First label is 1, not 0
else // even
b[i-Numnode/2]=i+1; // First label is 1, not 0
}
/////////////////////////// Calculate D for each a ///////////////////////////
int Ec, Enc; // D=Ec-Enc
int k;
int *Da;
Da=new int [Numnode/2];
int *Db;
Db=new int [Numnode/2];
int n, swapi,swapj,swaptemp;
int gmax,g,Gmax,Kmax,m;
int **SwapTable;
SwapTable=new int*[Numnode/2+1];
for(i=0;i<Numnode/2+1;i++)
SwapTable[i]=new int[2];
int p=0;
cout<<"1"<<endl;
do
{
cout<<"The current do loop is:"<<p<<endl;
p++;
int* ignore_a;
ignore_a=new int[Numnode/2];
int* ignore_b;
ignore_b=new int[Numnode/2]; //// We stopped here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for(i=0;i<Numnode/2;i++)
{
ignore_a[i]=0;
ignore_b[i]=0;
}
cout<<"baga"<<endl;
Gmax=0;
Kmax=0;
for(n=0; n<Numnode/2; n++) // Every time you remove a pair of a and b, so after |V|/2 iterations, the loop stops.
{
/////////////////////////// Calculate D for each a ///////////////////////////
for(i=0;i<Numnode/2;i++)
{
Ec=0; Enc=0;
for(j=1;j<Numedge+1;j++) // Scan through data file except the first line
{
if((a[i]==data[j][0])||(a[i]==data[j][1])) // If an edge involving a particular node in A1 is detected
{
if(a[i]==data[j][0]) // Then data[j][1] will be check based on a and b
{
for(k=0;k<Numnode/2;k++)
{
if((data[j][1]==a[k])) // &&(ignore_a[k]==0)
Enc++;
if((data[j][1]==b[k])) // &&(ignore_b[k]==0)
Ec++;
}
}
else // Then data[j][0] will be check based on a and b
{
for(k=0;k<Numnode/2;k++)
{
if((data[j][0]==a[k])) //&&(ignore_a[k]==0)
Enc++;
if((data[j][0]==b[k])) //&&(ignore_b[k]==0)
Ec++;
}
}
}
}
Da[i]=Ec-Enc;
}
cout<<"2"<<endl;
/////////////////////////// Calculate D for each b //////////////////////
for(i=0;i<Numnode/2;i++)
{
Ec=0; Enc=0;
for(j=1;j<Numedge+1;j++) // Scan through data file except the first line
{
if((b[i]==data[j][0])||(b[i]==data[j][1])) // If an edge involving a particular node in A1 is detected
{
if(b[i]==data[j][0]) // Then data[j][1] will be check based on a and b
{
for(k=0;k<Numnode/2;k++)
{
if((data[j][1]==b[k])) // &&(ignore_b[k]==0)
Enc++;
if((data[j][1]==a[k])) //&&(ignore_a[k]==0)
Ec++;
}
}
else // Then data[j][0] will be check based on a and b
{
for(k=0;k<Numnode/2;k++)
{
if((data[j][0]==b[k])) //&&(ignore_b[k]==0)
Enc++;
if((data[j][0]==a[k])) //&&(ignore_a[k]==0)
Ec++;
}
}
}
}
Db[i]=Ec-Enc;
}
gmax=-31410;
for(i=0;i<Numnode/2;i++)
{
if(ignore_a[i]==0)
{
for(j=0;j<Numnode/2;j++)
{
if(ignore_b[j]==0)
{
g=Da[i]+Db[j]-2*c[a[i]-1][b[j]-1];
if(g>gmax)
{
gmax=g; swapi=i; swapj=j;
}
}
}
}
}
Gmax=Gmax+gmax;
swaptemp=a[swapi];
a[swapi]=b[swapj];
b[swapj]=swaptemp;
ignore_a[swapi]=1;
ignore_b[swapj]=1;
if(Gmax>Kmax)
{
Kmax=Gmax;
m=n;
}
cout<<"The max n (m)="<<m<<endl;
SwapTable[n][0]=swapi;
SwapTable[n][1]=swapj;
}
cout<<"The maximun G is:"<<Kmax<<endl;
//////// Set a and b to the original problem /////////////////////////////////////////////
if(Kmax>0)
{
for(i=0;i<Numnode;i++)
{
if (i<Numnode/2) // odd
a[i]=i+1; // First label is 1, not 0
else // even
b[i-Numnode/2]=i+1; // First label is 1, not 0
}
for(k=0;k<m+1;k++)
{
swapi=SwapTable[k][0];
swapj=SwapTable[k][1];
swaptemp=a[swapi];
a[swapi]=b[swapj];
b[swapj]=swaptemp;
}
}
for(i=0;i<Numnode/2;i++)
{
cout<<"a"<<i<<"="<<a[i]<<" b"<<i<<"="<<b[i]<<"\n"<<endl;
}
}
while(Kmax>0);
cout<<"hahaha"<<endl;
openfile.close();
return 0;
}
输入文件叫做 data.txt, 里面的内容是:
8 13
1 2
1 5
1 6
2 5
2 6
3 6
3 7
3 8
3 4
4 7
4 8
5 6
7 8
已经卡在这里很久了,请高手帮忙看下,为什么会出现这种错误。
相关推荐
Coredump-N: corrupted double-linked list
可以看到是这一行的调用。查看unlink_chunk函数的汇编,出现coredump时的地址是 817ab,这里可以通过寄存器esi的值算出来;这种没有什么好 的办法,只能通过加-g,使用Valgrind 调试程序,看看问题到底出现在哪里?从逻辑上看,就是双向链表出现了逻辑错误。也就是内存使用上有错误,溢出等。这里可以看出来,在做exit退出时出现了异常;另一种耗时的方法就是看代码,不可取。
【Bugfix系列】通过工具定位corrupted double-linked list: 0xxxxxxxx
在遇到内存问题的时候,gdb调试的报错位置可能并不是真正的内存泄漏点,需要借助内存检查工具比如valgrind进一步定位具体的泄漏点位置,进而分析出问题所在。
MATLABSimulink模拟及会议论文,关于具备自动温度控制和能耗分析的智能太阳能热水系统。.zip
1.版本:matlab2014a/2019b/2024b 2.附赠案例数据可直接运行。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
完美复现基于自适应虚拟谐波阬的光储VSG并网电流谐波抑制模型(Simulink仿真实现)
内容概要:本文围绕基于自适应虚拟谐波阬的光储VSG并网电流谐波抑制模型展开研究,提出了一种结合虚拟同步发电机(VSG)控制与自适应虚拟谐波阬技术的谐波治理方案,旨在有效应对光伏发电与储能系统并网过程中产生的特定次谐波问题。通过在Simulink中构建完整的系统仿真模型,详细实现了VSG的惯量阻尼控制、功率环调控以及自适应谐波阬的频率识别与阻抗重塑机制,能够动态跟踪并抑制并网电流中的谐波成分,从而提升电能质量和系统并网稳定性。文章深入剖析了控制器结构设计、关键参数整定方法及谐波抑制效果的仿真验证过程,充分验证了该方法在复杂工况下的有效性、鲁棒性与工程应用潜力。; 适合人群:具备电力电子、新能源并网、电力系统分析等相关专业知识背景的科研人员与工程技术人员,尤其适用于熟悉Simulink仿真环境、掌握基本控制理论与信号处理技术的研究生、高校教师及企业研发人员。; 使用场景及目标:①应用于光伏-储能联合系统的并网逆变器控制设计;②用于提升VSG并网系统的电能质量与抗扰动能力;③为高比例新能源接入场景下的谐波分析与主动抑制策略提供仿真验证平台与技术支撑;④辅助开展新型电力系统中电能质量治理相关的教学与科研工作。; 阅读建议:建议读者结合提供的Simulink模型文件进行同步仿真操作,重点理解VSG控制架构与自适应虚拟谐波阬模块的耦合关系,关注谐波检测、频率自适应调整与复矢量控制的实现细节,并可通过改变负载条件或电网阻抗参数进行多工况测试,以深入掌握系统的动态响应特性与控制性能边界。
机械三维3D设计图-食品皮带机输送除尘消毒设备.zip
机械三维3D设计图-食品皮带机输送除尘消毒设备.zip


