📄 path_choose.asv
字号:
function varargout = path_choose(varargin)
% PATH_CHOOSE M-file for path_choose.fig
% PATH_CHOOSE, by itself, creates a new PATH_CHOOSE or raises the existing
% singleton*.
%
% H = PATH_CHOOSE returns the handle to a new PATH_CHOOSE or the handle to
% the existing singleton*.
%
% PATH_CHOOSE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PATH_CHOOSE.M with the given input arguments.
%
% PATH_CHOOSE('Property','Value',...) creates a new PATH_CHOOSE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before path_choose_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to path_choose_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help path_choose
% Last Modified by GUIDE v2.5 25-Apr-2006 20:33:02
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @path_choose_OpeningFcn, ...
'gui_OutputFcn', @path_choose_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before path_choose is made visible.
function path_choose_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to path_choose (see VARARGIN)
% Choose default command line output for path_choose
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes path_choose wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = path_choose_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
handles.width=1;
set(handles.width1,'checked','on');
set(handles.width2,'checked','off');
handles.city_name=['北京 ';'天津 ';'上海 ';'重庆 ';'哈尔滨 ';'长春 ';'沈阳 ';'呼和浩特';'石家庄 ';'太原 ';'西安 ';'兰州 ';'西宁 ';'乌鲁木齐';...
'拉萨 ';'成都 ';'昆明 ';'贵阳 ';'银川 ';'长沙 ';'武汉 ';'郑州 ';'济南 ';'合肥 ';'南京 ';'杭州 ';'南昌 ';'福州 ';'广州 ';'南宁 '];
handles.city_position=2*[10.38 10.60 11.75 8.45 12.30 12.14 11.95 9.40 10.00 9.65 8.80 7.70 7.25 4.59 4.45 7.65 7.22 8.24 8.26 9.80 10.06 9.88 10.82 10.74...
11.15 11.50 10.52 11.40 9.90 8.60;6.90 6.50 4.30 3.70 8.74 8.15 7.51 6.92 6.10 6.08 4.94 5.46 5.66 8.30 3.96 3.90 2.30 2.69 6.22 3.16 3.90...
5.14 5.85 4.35 4.44 3.95 3.34 2.70 1.79 1.69];
handles.road_start_end=[5 6 7 8 1 7 2 2 1 10 9 23 8 10 11 22 21 23 24 23 25 25 3 26 26 27 28 20 21 20 20 30 21 19 12 11 16 4 17 18 16 16 14 13 19;6 7 1 1 ...
2 2 23 9 9 9 22 22 19 11 22 21 24 24 25 25 3 26 26 27 28 28 29 27 20 30 29 29 16 11 11 16 4 18 18 30 17 15 12 12 12];
handles.road_length=zeros(1,45);
handles.total_length=0;
handles.road_load=[50 100 80 60 30 80 120 90 70 60 40 50 110 55 80 70 85 95 105 60 70 40 60 40 80 90 40 55 95 40 85 75 90 45 130 40 50 40 70 90 55 40 50 60 75];
for k=1:30
axis([0,30,0,22.4]);
plot(handles.city_position(1,k),handles.city_position(2,k),'b*');
if k==8||k==14
text(handles.city_position(1,k)-1.2,handles.city_position(2,k)+0.6,strcat(handles.city_name(k,:)),'Fontsize',9);
elseif k==5||k==9
text(handles.city_position(1,k)-0.8,handles.city_position(2,k)+0.6,strcat(handles.city_name(k,:)),'Fontsize',9);
elseif k==24
text(handles.city_position(1,k)-1.0,handles.city_position(2,k)+0.6,strcat(handles.city_name(k,:)),'Fontsize',9);
elseif k==10||k==13||k==17||k==20
text(handles.city_position(1,k)-1.4,handles.city_position(2,k)+0.2,strcat(handles.city_name(k,:)),'Fontsize',9);
elseif k==3||k==26||k==2||k==6||k==7||k==23||k==4||k==18||k==28
text(handles.city_position(1,k)+0.2,handles.city_position(2,k),strcat(handles.city_name(k,:)),'Fontsize',9);
elseif k==29||k==30||k==11
text(handles.city_position(1,k)-0.4,handles.city_position(2,k)-0.6,strcat(handles.city_name(k,:)),'Fontsize',9);
else
text(handles.city_position(1,k)-0.4,handles.city_position(2,k)+0.6,strcat(handles.city_name(k,:)),'Fontsize',9);
end
hold on;
end
for k=1:45
axis([0,30,0,22.4]);
handles.road_length(k)=200*sqrt((handles.city_position(1,handles.road_start_end(1,k))-handles.city_position(1,handles.road_start_end(2,k)))*...
(handles.city_position(1,handles.road_start_end(1,k))-handles.city_position(1,handles.road_start_end(2,k)))+...
(handles.city_position(2,handles.road_start_end(1,k))-handles.city_position(2,handles.road_start_end(2,k)))*...
(handles.city_position(2,handles.road_start_end(1,k))-handles.city_position(2,handles.road_start_end(2,k))));
handles.total_length=handles.total_length+handles.road_length(k);
H=plot([handles.city_position(1,handles.road_start_end(1,k)),handles.city_position(1,handles.road_start_end(2,k))],...
[handles.city_position(2,handles.road_start_end(1,k)),handles.city_position(2,handles.road_start_end(2,k))],'b','linewidth',handles.width);
if k==1
handles.h=[H];
else
handles.h=[handles.h;H];
end
end
guidata(hObject, handles);
varargout{1} = handles.output;
% --- Executes on button press in ok1.
function start_point_name=ok1_Callback(hObject, eventdata, handles)
% hObject handle to ok1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.start_point=get(handles.Start_point,'value');
handles.end_point=get(handles.End_point,'value');
handles.V1=zeros(1,30);
handles.V2=zeros(1,30);
handles.V3=zeros(1,30);
handles.V4=zeros(1,30);
handles.D1=zeros(1,45);
handles.D2=zeros(1,45);
handles.V1(handles.start_point)=1;
for k=1:29
length=handles.total_length;
for l=1:45
if handles.V1(handles.road_start_end(1,l))+handles.V1(handles.road_start_end(2,l))==1
if handles.V1(handles.road_start_end(1,l))==1
if handles.V2(handles.road_start_end(1,l))+handles.road_length(l)<length
length=handles.V2(handles.road_start_end(1,l))+handles.road_length(l);
t=l;
end
else
if handles.V2(handles.road_start_end(2,l))+handles.road_length(l)<length
length=handles.V2(handles.road_start_end(2,l))+handles.road_length(l);
t=l;
end
end
end
end
handles.D1(t)=1;
if handles.V1(handles.road_start_end(1,t))==1
handles.V1(handles.road_start_end(2,t))=1;
handles.V2(handles.road_start_end(2,t))=length;
handles.V3(handles.road_start_end(2,t))=handles.V3(handles.road_start_end(1,t))+1;
else
handles.V1(handles.road_start_end(1,t))=1;
handles.V2(handles.road_start_end(1,t))=length;
handles.V3(handles.road_start_end(1,t))=handles.V3(handles.road_start_end(2,t))+1;
end
end
handles.v1=zeros(1,30);
handles.v2=zeros(1,30);
handles.v3=zeros(1,30);
handles.v4=zeros(1,30);
handles.d1=zeros(1,45);
handles.d2=zeros(1,45);
handles.v1(handles.start_point)=1;
handles.v2(handles.start_point)=Inf;
for k=1:29
load=0;
for l=1:45
if handles.v1(handles.road_start_end(1,l))+handles.v1(handles.road_start_end(2,l))==1
if handles.v1(handles.road_start_end(1,l))==1
if min(handles.v2(handles.road_start_end(1,l)),handles.road_load(l))>load
load=min(handles.v2(handles.road_start_end(1,l)),handles.road_load(l));
t=l;
end
else
if min(handles.v2(handles.road_start_end(2,l)),handles.road_load(l))>load
load=min(handles.v2(handles.road_start_end(2,l)),handles.road_load(l));
t=l;
end
end
end
end
handles.d1(t)=1;
if handles.v1(handles.road_start_end(1,t))==1
handles.v1(handles.road_start_end(2,t))=1;
handles.v2(handles.road_start_end(2,t))=load;
handles.v3(handles.road_start_end(2,t))=handles.v3(handles.road_start_end(1,t))+1;
else
handles.v1(handles.road_start_end(1,t))=1;
handles.v2(handles.road_start_end(1,t))=load;
handles.v3(handles.road_start_end(1,t))=handles.v3(handles.road_start_end(2,t))+1;
end
end
legend(strcat('从',handles.city_name(handles.start_point,:),'到',handles.city_name(handles.end_point,:),'的最短距离为',...
int2str(round(handles.V2(handles.end_point))),'公里'),strcat('从',handles.city_name(handles.start_point,:),'到',...
handles.city_name(handles.end_point,:),'的最大载重量为',int2str(round(handles.v2(handles.end_point))),'吨'),3);
guidata(hObject, handles);
% --- Executes on button press in draw_path1.
function draw_path1_Callback(hObject, eventdata, handles)
% hObject handle to draw_path1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.V4(handles.end_point)=1;
for k=0:handles.V3(handles.end_point)-1
for l=1:45
if handles.D1(l)==1
if handles.V4(handles.road_start_end(1,l))+handles.V4(handles.road_start_end(2,l))==1
if (handles.V3(handles.road_start_end(1,l))+handles.V3(handles.road_start_end(2,l))==2*(handles.V3(handles.end_point)-k)-1)&&...
(handles.V3(handles.road_start_end(1,l))*handles.V3(handles.road_start_end(2,l))==(handles.V3(handles.end_point)-k)*...
(handles.V3(handles.end_point)-k-1))
handles.D2(l)=1;
if handles.V4(handles.road_start_end(1,l))==1
handles.V4(handles.road_start_end(2,l))=1;
else
handles.V4(handles.road_start_end(1,l))=1;
end
break;
end
end
end
end
end
for l=0:10
pause(0.2);
if rem(l,2)==0
for k=1:45
if handles.D2(k)==1
set(handles.h(k),'color',[1 0 0],'linewidth',handles.width+1);
else
set(handles.h(k),'color',[0,0,1],'linewidth',handles.width);
end
end
else
for k=1:45
set(handles.h(k),'color',[0,0,1],'linewidth',handels.width);
end
end
end
handles.V4=zeros(1,30);
guidata(hObject, handles);
% --- Executes on button press in draw_path2.
function draw_path2_Callback(hObject, eventdata, handles)
% hObject handle to draw_path2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.v4(handles.end_point)=1;
for k=0:handles.v3(handles.end_point)-1
for l=1:45
if handles.d1(l)==1
if handles.v4(handles.road_start_end(1,l))+handles.v4(handles.road_start_end(2,l))==1
if (handles.v3(handles.road_start_end(1,l))+handles.v3(handles.road_start_end(2,l))==2*(handles.v3(handles.end_point)-k)-1)&&...
(handles.v3(handles.road_start_end(1,l))*handles.v3(handles.road_start_end(2,l))==(handles.v3(handles.end_point)-k)*...
(handles.v3(handles.end_point)-k-1))
handles.d2(l)=1;
if handles.v4(handles.road_start_end(1,l))==1
handles.v4(handles.road_start_end(2,l))=1;
else
handles.v4(handles.road_start_end(1,l))=1;
end
break;
end
end
end
end
end
for l=1:10
pause(0.2);
if rem(l,2)==0
for k=1:45
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -