Romania's Cities Breadth-First Search using matlab

佐手、 提交于 2019-12-01 12:23:56

问题


I'm working on a project that referred to Romania cities Breadth-First Search:

romania cities map

I have a function for creating the neighbors:

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

and in my 'main.m' I have defined city* and neighbors:

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)  

each time compare the city with bucharest

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

for next time I need to compare its neighbor with goal and each time if city ~= 'bucharest' add that city to list. Also when find the goal, add goal to list.

Now I need a function to find bucharest and putting previous cities in an array. Automatically find cities and them values. like this:

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...')

来源:https://stackoverflow.com/questions/27183944/romanias-cities-breadth-first-search-using-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!