我的这段程序在tcforwin和tc2.0下调试都没有问题,但在运行时tc总是提示:floating point error:domain.不知道是怎么回事,请各位高手帮忙。周四就要交了,5555555~!! 我的程序是进行交通分配的,先求最短路,再依次取出两个点组成路进行分配,最后检查精度,然后输出。 我的注释用拼音写的,呵呵,不好意思~!! #include <conio.h> /* 此头函数请不要删除 */ #include<stdio.h> #include<math.h> #define inf 32767.00/*wuqiongda panding*/ #define n 9/*N biaoshi jiedian shu*/ void shortestpath(int begin,int terminal); void distribution(int n1,int n2); void check(); void shuchu(); int snode[12];
/*system chushihua*/ int v[n][n], v1[n][n]; double t[n][n],t0[n][n],t1[n][n]; /*V shi cunfang diyici fenpei de liuliang shuzu*/ /*v1 shi cunfang diedai hou de liuliang shuzu*/ /*t shi diyici de luquan shuzu*/ /*t0 shi lingliu shi de luquan shuzu*/ /*t1 shi diedai hou de luquan shuzu*/ int DS[n][n]; int OD[4][4]={{0,200,200,500},{200,0,500,100},{200,500,0,250},{500,100,250,0}}; int i,j; int v0;/*v0 shi shejichesu*/ int jiedian[4]={1,3,7,9}; /*shi jiedian A,B,C,D de shuzu*/ int flag,flag1,flag2;/*flag shi kongzhi quanju xunhuan de tag*/ /*flag1 shi kongzhi liuliang jingdu de xunhuan tag*/ /*flag2 shi kongzhi luquan jingdu de xunhuan tag*/ /*chushihua luquan shuzu he juli shuzu*/ double L[9][9]={ {0.00,4.20,inf,4.20,inf,inf,inf}, {4.20,0.00,4.20,inf,3.93,inf,inf,inf}, {inf,4.20,0.00,inf,inf,4.20,inf,inf,inf}, {4.20,inf,inf,0.00,1.96,inf,4.20,inf,inf}, {inf,3.93,inf,1.96,0.00,1.96,inf,3.93,inf}, {inf,inf,4.20,inf,1.96,0.00,inf,inf,4.20}, {inf,inf,inf,4.20,inf,inf,0.00,4.20,inf}, {inf,inf,inf,inf,3.93,inf,4.20,0.00,4.20}, {inf,inf,inf,inf,inf,4.20,inf,4.20,0.00}, };/*chushihua juli juzhen*/
main() { for(i=0;i<n;i++) { for(j=0;j<n;j++) { if (i!=j && L[i][j]<inf) v0=50; t0[i][j]=L[i][j]/v0; t[i][j]=t0[i][j]*(1+0.15*((v[i][j]/600)^4)); /*yi xiaoshi jisuan jingdu gao*/ } }/*jisuan chushi de luquan*/
/*kaishi xunhuan jisuan zuiduanlu,fenpei od,check jingdu*/ do { /*dang xunhuan dao di er ci yihou,xian jiang qian yi ci de luquan juzhen*/ /*he liuliang juzhen fuzhi gei t[][] he v[][],yi bian zuihou de shuchu*/ while(flag!=0) { for(i=0;i<n;i++) for(j=0;j<n;j++) { t[i][j]=t1[i][j]; v[i][j]=v1[i][j]; DS[i][j]=0;/*meici diedai zhi qian jiang ds[][] qingling ,chongxinfenpei*/ } } for(i=0;i<4;i++) for(j=0;j<4;j++) { shortestpath(jiedian[i],jiedian[j]); distribution(jiedian[i],jiedian[j]); } check(); } while(flag<=5 || (flag1*flag2)==0); shuchu(); } void shortestpath(int begin,int terminal) { int vnum; double dist[n]; int s[n];/*shi biaozhi zhe gai dian shifou zai zuiduan lujing shang*/ /*zhiyou 0 he 1 liang ge zhi*/ int u,w; double wm; int n1,n2; n1=begin; n2=terminal; if(n1>n2) shortestpath(n2,n1); for(i=0;i<12;i++) { snode[i]=0; } do { /* 采用Dijkstra算法求最短路径的程序始段 */ for(w=0;w<n;w++) /* 最短路径初始化 */ { dist[w]=t[n1][w]; if(t[n1][w]<inf) snode[w]=n1; /* path记录当前最短路径 */ } for(w=0;w<n;w++) s[w]=0; s[n1]=1; vnum=1; /* s集合中顶点个数的初值 */ while(vnum<n-1) /* 最后一个顶点已无选择余地 */ { wm=inf; u=n1; for(w=0;w<n;w++) if(s[w]==0 && dist[w]<wm) { u=w; wm=dist[w]; /* 找最小dist[w] */ } s[u]=1; vnum++; /* u为找到最短路径的终点 */ for(w=1;w<=n;w++) if(s[w]==0 && dist[u]+t[u][w]<dist[w]) { dist[w]=dist[u]+t[u][w]; /* 调整非s集合点最短路径值 */ snode[w]=u; /* 调整非s集合点最短路径 */ } }
} while(u!=n2); /* 采用Dijkstra算法求最短路径的程序段结束 */ } void distribution(int n1,int n2) { int theta1,theta2; for(j=0;j<9;j++) { while(snode[j+1]!=0)/*dang xia yi dian bu shi zhongdian shi*/ { theta1=snode[j]; theta2=snode[j+1]; /*youyu qiu zuiduanlu shi,zhi suan le n1<n2 de qingkuang*/ /*yinci fenpei shi yao jiang liang ge fangxiang de dou jia shangqu*/ DS[theta1][theta2]=DS[theta1][theta2]+OD[theta1][theta2]; DS[theta2][theta1]=DS[theta2][theta1]+OD[theta2][theta2]; v1[theta1][theta2]=DS[theta1][theta2]; v1[theta2][theta1]=DS[theta2][theta1]; } for(i=0;i<9;i++) for(j=0;j<9;j++) { t1[i][j]=t0[i][j]*(1+0.15*((v1[i][j]/600)^4)); } } } void check() { int q; double r; double deltat[n][n]; int deltav[n][n];/*yonglai jiang ge luduan de liuliang he*/ /*luquan de cha biaoshi chulai*/ ++flag; flag1=flag2=1; for(i=0;i<n;i++) for(j=0;j<n;j++) { deltat[i][j]=abs(t1[i][j]-t0[i][j]); r=(deltat[i][j]<0.01)?1:0; flag1=flag1*r;/*liancheng,zhiyoudang suoyou de r dou wei yi shi*/ /*flag1 cai huiwei1,fouze dou wei ling*/ deltav[i][j]=abs(v1[i][j]-v[i][j]); q=(deltav[i][j]<10)?1:0; flag2=flag2*q; } }
void shuchu() { int deltav[n][n]; double deltat[n][n]; printf("diandui v v1 t t1 deltav deltat\n"); for(i=0;i<9;i++) { for(j=0;j<9;j++) { if(L[i][j]!=0 && L[i][j]!=inf) { printf("%d %d %d %d %d %d %d %d\n",i+1,j+1,v[i][j],v1[i][j],t[i][j],t1[i][j],deltav[i][j],deltat[i][j]); } } } }