声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 3343|回复: 9

[经典算法] 求结构可靠性分析的分支限界法的程序

[复制链接]
发表于 2007-3-19 10:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
请问各位,有没有人有结构可靠性分析中寻找失效模式的分支限界法的程序啊,急用!
多谢大家的帮忙!
回复
分享到:

使用道具 举报

发表于 2007-3-20 07:19 | 显示全部楼层
我有几个分支限界法的应用程序,不过不是用于可靠性的,属于应用范例

比如用分支限界法解决0/1背包问题、最小圆排列的分支限界法
 楼主| 发表于 2007-3-21 19:35 | 显示全部楼层

回复 #2 风花雪月 的帖子

能否传给我,也许有参考价值
多谢了
我的邮箱 king101010101010@163.com
发表于 2007-3-27 09:30 | 显示全部楼层
分支限界法中的单源最短路径问题的实现,是用VC++编写的

单源最短路径.cpp

315 Bytes, 下载次数: 36

XCEPT.H

136 Bytes, 下载次数: 28

shortpath.H

1.46 KB, 下载次数: 28

MINHEAP.H

1.88 KB, 下载次数: 28

MAKE2DB.H

724 Bytes, 下载次数: 27

DATA.TXT

84 Bytes, 下载次数: 28

发表于 2007-3-27 09:31 | 显示全部楼层
最小圆排列的分支限界法!

  1. #include <queue>
  2. #include <fstream>
  3. #include<iostream>
  4. #include <math.h>
  5. #include <time.h>
  6. using namespace std;
  7. double **dic;//dic[i][j]存放第i个圆与第j个圆得圆心
  8. double *r;//存放n个圆的半径
  9. double best;


  10. template<class type>
  11. int partition (type a[],int low,int high){
  12.         int pivotpos=low;
  13.         type pivot=a[low];
  14.     for (int i=low+1;i<=high;i++)
  15.                 if (a[i]<pivot&&++pivotpos!=i)
  16.                         swap(a[pivotpos],a[i]);
  17.                 swap(a[low],a[pivotpos]);
  18.                 return pivotpos;}
  19. template<class type>
  20. void quicksort (type a[],int p,int r){
  21.         int i;
  22.         if(p<r)
  23.         {i=partition(a,p,r);
  24.         quicksort(a,p,i-1);
  25.         quicksort(a,i+1,r);}}
  26. class circlenode
  27. {
  28.         friend void circleperm(double *r,int n);
  29.        
  30. private:
  31.         int mink;//代排的圆中第mink个圆的半径最小
  32.         int s;//算法完成了s步,即排好了s个圆
  33.         int k;//镜像剪枝
  34.         double *x;//圆心坐标
  35.         int *rp;//所选的第s个圆得半径为r[rp[s]]
  36.         double compute(int n);
  37.         double center(int t);
  38.        
  39. };




  40. double circlenode::compute(int n)
  41. {
  42.         int i;
  43.         double low=0.0;
  44.         double high=x[n-1]+r[rp[n-1]];
  45.         for(i=0;i<n;i++)
  46.         {
  47.                 if(x[i]-r[rp[i]]<low)
  48.                         low=(double)x[i]-r[rp[i]];
  49.                 if(x[i]+r[rp[i]]>high)
  50.                         high=(double)x[i]+r[rp[i]];
  51.         }
  52.         return (double)high-low;
  53. };



  54. double circlenode::center(int t)
  55. {
  56.         double temp=0.0;
  57.         double valuex;
  58.         for(int i=0;i<t;i++)
  59.         {
  60.                 valuex=x[i]+(double)2*sqrt(r[rp[i]]*r[rp[t]]);
  61.                 if(valuex>temp)
  62.                         temp=valuex;
  63.         }
  64.         return temp;
  65. };


  66. void circleperm(double *r,int n)
  67. {
  68.         int i,j;
  69.         int wk;
  70.         int tag;
  71.         int tt;
  72.         double bestt;
  73.         double *tsame;
  74.         int tsamen;
  75.         double rtemp;
  76.         double mintemp;
  77.         tsame=new double[n];
  78.     queue<circlenode> qu;
  79.        
  80.         /*e.x=new double[n];
  81.     e.s=-1;
  82.         e.mink=0;
  83.     e.rp=new int [n];
  84.         for(i=0;i<n;i++)
  85.         e.rp[i]=i;*/
  86.         circlenode tempe;
  87.         tempe.x=new double[n];
  88.         tempe.rp=new int[n];
  89.         int fi=0;
  90.         int li=n-1;
  91.         i=0;
  92.         while(fi<=li)
  93.         {
  94.                 tempe.rp[i]=fi;
  95.                 i++;
  96.                 fi++;
  97.                 if(fi<=li)
  98.                 {
  99.                         tempe.rp[i]=li;
  100.                         i++;
  101.                         li--;
  102.                 }
  103.         }
  104.         for(i=0;i<n;i++)
  105.                 tempe.x[i]=tempe.center(i);
  106.         best=tempe.compute(n);//算初值
  107.         /* for(i=0;i<n;i++)
  108.         cout<<tempe.rp[i]<<" ";
  109.          cout<<endl;
  110.          
  111.          
  112.       for(i=0;i<n;i++)
  113.         {cout<<tempe.x[i]<<endl;}//test best*/
  114.        
  115.         delete []tempe.x;
  116.         delete []tempe.rp;
  117.        
  118.         cout<<best<<endl;
  119.        
  120.         // best=12345;//需修改
  121.         circlenode e;
  122.         for(i=0;i<n-1;i++)
  123.         {
  124.                
  125.                
  126.                
  127.                 //cout<<r[i]<<endl;
  128.                 if(i>0&&r[i-1]==r[i]) continue;
  129.                 if(i==0) e.mink=1;
  130.                 else e.mink=0;
  131.                 e.k=n-i-1;//比i大的数字的个数
  132.                 e.rp=new int[n];
  133.                 e.x=new double[n];
  134.                
  135.                 for(j=0;j<n;j++)
  136.                 {
  137.                         e.rp[j]=j;
  138.                        
  139.                 };
  140.                 e.x[0]=0;
  141.                 e.rp[0]=i;
  142.                 e.rp[i]=0;
  143.                
  144.                 e.s=0;
  145.                 qu.push(e);
  146.         }
  147.         while(!qu.empty())
  148.         {
  149.                 e=qu.front();
  150.                 qu.pop();
  151.                 if (e.s==n-3)
  152.                 {
  153.                         if(e.rp[n-1]>e.rp[0])
  154.                         {
  155.                                 e.x[n-2]=e.center(n-2);
  156.                                 e.x[n-1]=e.center(n-1);
  157.                                 bestt=e.compute(n);
  158.                                
  159.                                
  160.                                
  161.                                
  162.                                 if(bestt<best)
  163.                                         best=bestt;
  164.                         }
  165.                         if(e.rp[n-2]>e.rp[0])
  166.                         {
  167.                                 tt=e.rp[n-2];
  168.                                 e.rp[n-2]=e.rp[n-1];
  169.                                 e.rp[n-1]=tt;
  170.                                
  171.                                
  172.                                 e.x[n-2]=e.center(n-2);
  173.                                 e.x[n-1]=e.center(n-1);
  174.                                 bestt=e.compute(n);
  175.                                
  176.                                
  177.                                 if(bestt<best)
  178.                                         best=bestt;
  179.                         }
  180.                 }
  181.                 else
  182.                 {
  183.                        
  184.                         tsamen=0;
  185.                        
  186.                         for(i=e.s+1;i<n;i++)
  187.                         {
  188.                                 if(e.rp[i]>e.rp[0]) wk=e.k-1;
  189.                                 else wk=e.k;
  190.                                
  191.                                 if(wk) //镜像剪枝
  192.                                 {
  193.                                        
  194.                                         tag=0;
  195.                                         rtemp=r[e.rp[i]];
  196.                                         for(j=0;j<tsamen;j++)
  197.                                         {
  198.                                                 if(rtemp==tsame[j])
  199.                                                         tag=1;
  200.                                                 //        continue;
  201.                                         }
  202.                                         if(!tag)
  203.                                         {
  204.                                                
  205.                                                 tsame[tsamen]=rtemp;
  206.                                                 tsamen++;
  207.                                                 circlenode w;
  208.                                                 w.k=wk;
  209.                                                 w.s=e.s+1;
  210.                                                 w.x=new double[n];
  211.                                                 w.rp=new int[n];
  212.                                                
  213.                                                 for(j=0;j<n;j++)
  214.                                                 {
  215.                                                         w.x[j]=e.x[j];
  216.                                                         w.rp[j]=e.rp[j];
  217.                                                 }
  218.                                                
  219.                                                
  220.                                                 w.rp[w.s]=e.rp[i];
  221.                                                 w.rp[i]=e.rp[w.s];
  222.                                                
  223.                                                 w.mink=e.mink;
  224.                                                 if(w.mink==w.rp[w.s])
  225.                                                 {
  226.                                                         w.mink=w.rp[w.s+1];
  227.                                                         for(j=w.s+2;j<n;j++)
  228.                                                         {
  229.                                                                 if(r[w.rp[j]]<r[w.mink])
  230.                                                                         w.mink=w.rp[j];
  231.                                                         }
  232.                                                        
  233.                                                 }
  234.                                                 w.x[w.s]=w.center(w.s);
  235.                                                 mintemp=w.x[w.s]+(2*n-2*w.s-1)*r[w.mink]+r[w.rp[0]];
  236.                                                 if(mintemp<best)
  237.                                                 {
  238.                                                         qu.push(w);
  239.                                                 }
  240.                                                 else
  241.                                                 {
  242.                                                         delete []w.x;
  243.                                                         delete []w.rp;
  244.                                                 }
  245.                                         }  //if(!tag)
  246.                                 }//if(wk)
  247.                         }//for(i=e.s+1;i<n;i++)
  248.                        
  249.                 }//else
  250.                 delete []e.x;
  251.                 delete []e.rp;       
  252.         }//while
  253.         delete []tsame;
  254.        
  255. }
  256. void main()
  257. {
  258.         clock_t start, finish;
  259.         start=clock();
  260.         fstream infile,outfile;
  261.         int n;
  262.         int i;
  263.         int j;
  264.        
  265.         infile.open("input.txt",ios::in);
  266.         outfile.open("output.txt",ios.out);
  267.         infile>>n;
  268.         r=new double[n];
  269.         dic=new double*[n];
  270.         for(i=0;i<n;i++)
  271.                 dic[i]=new double[n];
  272.         for(i=0;i<n;i++)
  273.                 infile>>r[i];
  274.        
  275.     if(n==1)
  276.         {
  277.                 best=2.0*r[0];
  278.                 outfile<<best<<endl;
  279.                 cout<<best<<endl;
  280.         }
  281.         else if(n==2)
  282.         {
  283.                 double temp2;
  284.                 temp2=2*sqrt(r[0]*r[1]);
  285.                 double low2,high2;
  286.                 low2=0-r[0];
  287.                 if(temp2-r[1]<low2) low2=temp2-r[1];
  288.                 high2=temp2+r[1];
  289.                 if(high2<r[0]) high2=r[0];
  290.                 best=high2-low2;
  291.                 outfile<<best<<endl;
  292.                 cout<<best<<endl;
  293.         }
  294.         else
  295.         {
  296.                 quicksort(r,0,n-1);
  297.                 /*        for(i=0;i<n;i++)
  298.                 cout<<r[i]<<endl;*/
  299.                 for(i=0;i<n-1;i++)
  300.                 {
  301.                         for(j=i+1;j<n;j++)
  302.                                 dic[i][j]=dic[j][i]=sqrt(r[i]*r[j]);
  303.                 }
  304.                
  305.                 circleperm(r,n);
  306.                 outfile<<best<<endl;
  307.                 cout<<best<<endl;
  308.         }
  309.         infile.close();
  310.         outfile.close();
  311.         delete []r;
  312.         for(i=0;i<n;i++)
  313.                 delete []dic[i];
  314.         delete []dic;
  315.        
  316.         finish=clock();
  317.         cout<<endl<<"Elapsed Time: "<<(double)(finish-start)/CLOCKS_PER_SEC<<" secouds"<<endl;
  318.        
  319. }       
复制代码
 楼主| 发表于 2007-3-27 18:23 | 显示全部楼层
多些,会好好学习一下的
发表于 2007-4-3 09:31 | 显示全部楼层
很好!:@)
发表于 2009-6-28 02:00 | 显示全部楼层
感谢分享!
发表于 2009-9-18 09:21 | 显示全部楼层
谢谢了,正在学习中
发表于 2009-9-18 14:35 | 显示全部楼层
不要学了!30年前的东西了。。。
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-18 20:15 , Processed in 0.066685 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表