求结构可靠性分析的分支限界法的程序
请问各位,有没有人有结构可靠性分析中寻找失效模式的分支限界法的程序啊,急用!多谢大家的帮忙! 我有几个分支限界法的应用程序,不过不是用于可靠性的,属于应用范例
比如用分支限界法解决0/1背包问题、最小圆排列的分支限界法
回复 #2 风花雪月 的帖子
能否传给我,也许有参考价值多谢了
我的邮箱 king101010101010@163.com 分支限界法中的单源最短路径问题的实现,是用VC++编写的 最小圆排列的分支限界法!
#include <queue>
#include <fstream>
#include<iostream>
#include <math.h>
#include <time.h>
using namespace std;
double **dic;//dic存放第i个圆与第j个圆得圆心
double *r;//存放n个圆的半径
double best;
template<class type>
int partition (type a[],int low,int high){
int pivotpos=low;
type pivot=a;
for (int i=low+1;i<=high;i++)
if (a<pivot&&++pivotpos!=i)
swap(a,a);
swap(a,a);
return pivotpos;}
template<class type>
void quicksort (type a[],int p,int r){
int i;
if(p<r)
{i=partition(a,p,r);
quicksort(a,p,i-1);
quicksort(a,i+1,r);}}
class circlenode
{
friend void circleperm(double *r,int n);
private:
int mink;//代排的圆中第mink个圆的半径最小
int s;//算法完成了s步,即排好了s个圆
int k;//镜像剪枝
double *x;//圆心坐标
int *rp;//所选的第s个圆得半径为r]
double compute(int n);
double center(int t);
};
double circlenode::compute(int n)
{
int i;
double low=0.0;
double high=x+r];
for(i=0;i<n;i++)
{
if(x-r]<low)
low=(double)x-r];
if(x+r]>high)
high=(double)x+r];
}
return (double)high-low;
};
double circlenode::center(int t)
{
double temp=0.0;
double valuex;
for(int i=0;i<t;i++)
{
valuex=x+(double)2*sqrt(r]*r]);
if(valuex>temp)
temp=valuex;
}
return temp;
};
void circleperm(double *r,int n)
{
int i,j;
int wk;
int tag;
int tt;
double bestt;
double *tsame;
int tsamen;
double rtemp;
double mintemp;
tsame=new double;
queue<circlenode> qu;
/*e.x=new double;
e.s=-1;
e.mink=0;
e.rp=new int ;
for(i=0;i<n;i++)
e.rp=i;*/
circlenode tempe;
tempe.x=new double;
tempe.rp=new int;
int fi=0;
int li=n-1;
i=0;
while(fi<=li)
{
tempe.rp=fi;
i++;
fi++;
if(fi<=li)
{
tempe.rp=li;
i++;
li--;
}
}
for(i=0;i<n;i++)
tempe.x=tempe.center(i);
best=tempe.compute(n);//算初值
/* for(i=0;i<n;i++)
cout<<tempe.rp<<" ";
cout<<endl;
for(i=0;i<n;i++)
{cout<<tempe.x<<endl;}//test best*/
delete []tempe.x;
delete []tempe.rp;
cout<<best<<endl;
// best=12345;//需修改
circlenode e;
for(i=0;i<n-1;i++)
{
//cout<<r<<endl;
if(i>0&&r==r) continue;
if(i==0) e.mink=1;
else e.mink=0;
e.k=n-i-1;//比i大的数字的个数
e.rp=new int;
e.x=new double;
for(j=0;j<n;j++)
{
e.rp=j;
};
e.x=0;
e.rp=i;
e.rp=0;
e.s=0;
qu.push(e);
}
while(!qu.empty())
{
e=qu.front();
qu.pop();
if (e.s==n-3)
{
if(e.rp>e.rp)
{
e.x=e.center(n-2);
e.x=e.center(n-1);
bestt=e.compute(n);
if(bestt<best)
best=bestt;
}
if(e.rp>e.rp)
{
tt=e.rp;
e.rp=e.rp;
e.rp=tt;
e.x=e.center(n-2);
e.x=e.center(n-1);
bestt=e.compute(n);
if(bestt<best)
best=bestt;
}
}
else
{
tsamen=0;
for(i=e.s+1;i<n;i++)
{
if(e.rp>e.rp) wk=e.k-1;
else wk=e.k;
if(wk) //镜像剪枝
{
tag=0;
rtemp=r];
for(j=0;j<tsamen;j++)
{
if(rtemp==tsame)
tag=1;
// continue;
}
if(!tag)
{
tsame=rtemp;
tsamen++;
circlenode w;
w.k=wk;
w.s=e.s+1;
w.x=new double;
w.rp=new int;
for(j=0;j<n;j++)
{
w.x=e.x;
w.rp=e.rp;
}
w.rp=e.rp;
w.rp=e.rp;
w.mink=e.mink;
if(w.mink==w.rp)
{
w.mink=w.rp;
for(j=w.s+2;j<n;j++)
{
if(r]<r)
w.mink=w.rp;
}
}
w.x=w.center(w.s);
mintemp=w.x+(2*n-2*w.s-1)*r+r];
if(mintemp<best)
{
qu.push(w);
}
else
{
delete []w.x;
delete []w.rp;
}
}//if(!tag)
}//if(wk)
}//for(i=e.s+1;i<n;i++)
}//else
delete []e.x;
delete []e.rp;
}//while
delete []tsame;
}
void main()
{
clock_t start, finish;
start=clock();
fstream infile,outfile;
int n;
int i;
int j;
infile.open("input.txt",ios::in);
outfile.open("output.txt",ios.out);
infile>>n;
r=new double;
dic=new double*;
for(i=0;i<n;i++)
dic=new double;
for(i=0;i<n;i++)
infile>>r;
if(n==1)
{
best=2.0*r;
outfile<<best<<endl;
cout<<best<<endl;
}
else if(n==2)
{
double temp2;
temp2=2*sqrt(r*r);
double low2,high2;
low2=0-r;
if(temp2-r<low2) low2=temp2-r;
high2=temp2+r;
if(high2<r) high2=r;
best=high2-low2;
outfile<<best<<endl;
cout<<best<<endl;
}
else
{
quicksort(r,0,n-1);
/* for(i=0;i<n;i++)
cout<<r<<endl;*/
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
dic=dic=sqrt(r*r);
}
circleperm(r,n);
outfile<<best<<endl;
cout<<best<<endl;
}
infile.close();
outfile.close();
delete []r;
for(i=0;i<n;i++)
delete []dic;
delete []dic;
finish=clock();
cout<<endl<<"Elapsed Time: "<<(double)(finish-start)/CLOCKS_PER_SEC<<" secouds"<<endl;
}
多些,会好好学习一下的 很好!:@) 感谢分享! 谢谢了,正在学习中 不要学了!30年前的东西了。。。
页:
[1]