罗马尼亚的城市广度优先搜索使用matlab

时间:2014-11-28 07:35:55

标签: matlab breadth-first-search

我正在开展一个涉及罗马尼亚城市广度优先搜索的项目:

romania cities map

我有一个创建邻居的功能:

function [NeighborName PathLength StraightLineDistance] = makeneighbor(x,y,z)
NeighborName=x; 
PathLength=y; % distance from current city to neighbor
StraightLineDistance=z; % i want to use it for a* model

在我的'main.m'中我定义了城市*和邻居:

clc;clear;
city1='Arad'
[neighbor_name neighbor_distance straight_line_distance]=makeneighbor('Zerind',75,374)
[neighbor_name neighbor_distance straight_line_distance]=makeneighbor('Sibiu',140,253)
[neighbor_name neighbor_distance straight_line_distance]=makeneighbor('Timisoara',118,329)

city2='Zerind'
[neighbor_name neighbor_distance straight_line_distance]=makeneighbor('Oradea',71,380)
[neighbor_name neighbor_distance straight_line_distance]=makeneighbor('Arad',75,366)
.
.
.
city20='Neamt'
[neighbor_name neighbor_distance straight_line_distance]=makeneighbor('Iasi',87,226)  

每次将城市与布加勒斯特进行比较

if city*=='bucharest'
break;
else
list= add the city to list.

下次我需要将其邻居与目标进行比较 每次如果城市〜='布加勒斯特'将该城市添加到列表中。同样在找到目标时,添加目标列表。

现在我需要一个功能来查找布加勒斯特并将之前的城市放在一个数组中。自动查找城市及其值。像这样:

path1=['arad' 'sibiu' 'fagaras' 'bucharest'];
distance1=[140 99 211];
path2=['arad' 'zerind' 'oradea' 'sibiu' 'fagaras' 'bucharest'];
distance2=[75 71 151 99 211];
path3=['arad' 'zerind' 'oradea' 'sibiu' 'vilcea' 'pitesti' 'bucharest'];
distance3=[75 71 151 80 97 101];
.
.
pathN=[city1:cityN 'bucharest'];
distanceN=[distance1:distanceN]

disp('please explain very simple. im not so expert in matlab, and my primary language is not english. many thanx...')

0 个答案:

没有答案