|
|
|
@ -149,3 +149,82 @@ void printff(){
|
|
|
|
|
for(j=0;j<nm.n;j++) cont[i][j]=MAX;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void createjz(){//创建邻接矩阵函数
|
|
|
|
|
edgenode *p;
|
|
|
|
|
aaa();
|
|
|
|
|
int i;
|
|
|
|
|
for(i=0;i<nm.n;i++){
|
|
|
|
|
p=nm.adjust[i].firstnode;
|
|
|
|
|
while(p!=NULL){
|
|
|
|
|
int h;
|
|
|
|
|
for(h=0;h<nm.n;h++)
|
|
|
|
|
if(!strcmp(p->a,nm.adjust[h].name)) break;
|
|
|
|
|
cont[i][h]=1;
|
|
|
|
|
p=p->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void print() {
|
|
|
|
|
edgenode* p;
|
|
|
|
|
int i;
|
|
|
|
|
for(i=0;i<nm.n;i++){
|
|
|
|
|
printf("[%s]",nm.adjust[i].name);
|
|
|
|
|
p=nm.adjust[i].firstnode;
|
|
|
|
|
while(p!=NULL){
|
|
|
|
|
printf("-->[%s]",p->a);
|
|
|
|
|
p=p->next;
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int num2=0;
|
|
|
|
|
int money=0;
|
|
|
|
|
void Dijkstra(int v1,int v2){
|
|
|
|
|
int dist[MAX],s[MAX],path[MAX];//s判断v1是否已经判断最短路径,path前驱
|
|
|
|
|
int min,i,j,u,pre;
|
|
|
|
|
for(i=0;i<nm.n;i++){
|
|
|
|
|
dist[i]=cont[v1][i];
|
|
|
|
|
s[i]=0;
|
|
|
|
|
if(cont[v1][i]<MAX) path[i]=v1;
|
|
|
|
|
else path[i]=-1;
|
|
|
|
|
}//初始化操作
|
|
|
|
|
s[v1]=1;
|
|
|
|
|
path[v1]=0;
|
|
|
|
|
for(i=0;i<nm.n;i++){
|
|
|
|
|
min=MAX;
|
|
|
|
|
u=-1;
|
|
|
|
|
for(j=0;j<nm.n;j++){
|
|
|
|
|
if(s[j]==0&&dist[j]<min){
|
|
|
|
|
u=j;
|
|
|
|
|
min=dist[j];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(u!=-1){
|
|
|
|
|
s[u]=1;
|
|
|
|
|
for(j=0;j<nm.n;j++)
|
|
|
|
|
if(s[j]==0){
|
|
|
|
|
if(cont[u][j]<MAX&&dist[u]+cont[u][j]<dist[j]){
|
|
|
|
|
dist[j]=dist[u]+cont[u][j];
|
|
|
|
|
path[j]=u;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("智能推荐路线如下(逆序):\n");
|
|
|
|
|
for(i=0;i<nm.n;i++){
|
|
|
|
|
if(i!=v1&&i==v2){
|
|
|
|
|
if(s[i]==1){
|
|
|
|
|
num2=dist[i];
|
|
|
|
|
pre=i;
|
|
|
|
|
while(pre!=v1){
|
|
|
|
|
printf("%s-->",nm.adjust[pre].name);
|
|
|
|
|
money++;
|
|
|
|
|
pre=path[pre];
|
|
|
|
|
}
|
|
|
|
|
printf("%s",nm.adjust[pre].name);
|
|
|
|
|
}
|
|
|
|
|
else printf("路径不存在!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|