题模拟退活算法程序代码_第1页
题模拟退活算法程序代码_第2页
题模拟退活算法程序代码_第3页
题模拟退活算法程序代码_第4页
题模拟退活算法程序代码_第5页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、A题第二问,模拟退火算法matlab程序function d = data_file()cities = 0.6606,0.9695,0.5906,0.2124,0.0398,0.1367,0.9536,0.6091,0.8767,. 0.8148,0.3876,0.7041,0.0213,0.3429,0.7471,0.5449,0.9464,0.1247,0.1636,. 0.8668,;0.9500,0.6740,0.5029,0.8274,0.9697,0.5979,0.2184,0.7148,0.2395,. 0.2867,0.8200,0.3296,0.1649,0.3025,0.

2、8192,0.9392,0.8191,0.4351,0.8646,. 0.6768;save cities.mat cities -V6;function d = distance(inputcities)% DISTANCE% d = DISTANCE(inputcities) calculates the distance between n cities as% required in a Traveling Salesman Problem. The input argument has two rows% and n columns, where n is the number of

3、 cities and each column represent% the coordinate of the corresponding city. d = 0;for n = 1 : length(inputcities) if n = length(inputcities) d = d + norm(inputcities(:,n) - inputcities(:,1); else d = d + norm(inputcities(:,n) - inputcities(:,n+1); endendfunction c = loadeil101()% LOADEIL101 Loads t

4、he data file. % COMMENT : 101-city problem (Christofides/Eilon)% TYPE : TSP% DIMENSION : 101% Source: www.iwr.uni-heidelberg.de/groups/comopt/software/TSPLIB95/tspclear all;temp_x = 1 41 492 35 173 55 454 55 205 15 306 25 307 20 508 10 439 55 6010 30 6011 20 6512 50 3513 30 2514 15 1015 30 516 10 20

5、17 5 3018 20 4019 15 6020 45 6521 45 2022 45 1023 55 524 65 3525 65 2026 45 3027 35 4028 41 3729 64 4230 40 6031 31 5232 35 6933 53 5234 65 5535 63 6536 2 6037 20 2038 5 539 60 1240 40 2541 42 742 24 1243 23 344 11 1445 6 3846 2 4847 8 5648 13 5249 6 6850 47 4751 49 5852 27 4353 37 3154 57 2955 63 2

6、356 53 1257 32 1258 36 2659 21 2460 17 3461 12 2462 24 5863 27 6964 15 7765 62 7766 49 7367 67 568 56 3969 37 4770 37 5671 57 6872 47 1673 44 1774 46 1375 49 1176 49 4277 53 4378 61 5279 57 4880 56 3781 55 5482 15 4783 14 3784 11 3185 16 2286 4 1887 28 1888 26 5289 26 3590 31 6791 15 1992 22 2293 18

7、 2494 26 2795 25 2496 22 2797 25 2198 19 2199 20 26100 18 18101 35 35;cities = temp_x(:,2);temp_x(:,3);save cities.mat cities -V6;function c = loadst70()% LOADST70 Loads the data file% NAME: st70% TYPE: TSP% COMMENT: 70-city problem (Smith/Thompson)% DIMENSION: 70% EDGE_WEIGHT_TYPE : EUC_2D% NODE_CO

8、ORD_SECTIONclear all;temp_x = 1 64 962 80 393 69 234 72 425 48 676 58 437 81 348 79 179 30 2310 42 6711 7 7612 29 5113 78 9214 64 815 95 5716 57 9117 40 3518 68 4019 92 3420 62 121 28 4322 76 7323 67 8824 93 5425 6 826 87 1827 30 928 77 1329 78 9430 55 331 82 8832 73 2833 20 5534 27 4335 95 8636 67

9、9937 48 8338 75 8139 8 1940 20 1841 54 3842 63 3643 44 3344 52 1845 12 1346 25 547 58 8548 5 6749 90 950 41 7651 25 7652 37 6453 56 6354 10 5555 98 756 16 7457 89 6058 48 8259 81 7660 29 6061 17 2262 5 4563 79 7064 9 10065 17 8266 74 6767 10 6868 48 1969 83 8670 84 94;cities = temp_x(:,2);temp_x(:,3

10、);save cities.mat cities -V6;function varargout = stsp(varargin)% STSP M-file for stsp.fig% STSP, by itself, creates a new STSP or raises the existing% singleton*.% H = STSP returns the handle to a new STSP or the handle to% the existing singleton*.% STSP(CALLBACK,hObject,eventData,handles,.) calls

11、the local% function named CALLBACK in STSP.M with the given input arguments.% STSP(Property,Value,.) creates a new STSP or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before stsp_OpeningFunction gets called. An% unrecognized property name or

12、invalid value makes property application% stop. All inputs are passed to stsp_OpeningFcn via varargin.% *See GUI Options on GUIDEs 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 stsp% Last

13、 Modified by GUIDE v2.5 12-Jan-2006 22:46:00% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, stsp_OpeningFcn, . gui_OutputFcn, stsp_OutputFcn, . gui_LayoutFcn, , . gui_Callback, );if nargin & ischar(v

14、arargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before stsp is made visible.function stsp_OpeningFcn(hObject, eventdata, hand

15、les, 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 stsp (see VARARGIN)% Choose default command lin

16、e output for stsphandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes stsp wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the command line.function varargout = stsp_OutputFcn(hObject, eventdata, han

17、dles) % 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 structurevarargout1 = handles.

18、output;function initial_temperature_Callback(hObject, eventdata, handles)% hObject handle to initial_temperature (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,String) returns contents of in

19、itial_temperature as text% str2double(get(hObject,String) returns contents of initial_temperature as a doubles = str2double(get(hObject,String);if isnan(s) set(hObject,String,1000)endif s 10000 set(hObject,String,1000)end% - Executes during object creation, after setting all properties.function init

20、ial_temperature_CreateFcn(hObject, eventdata, handles)% hObject handle to initial_temperature (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Wi

21、ndows.% See ISPC and COMPUTER.if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);endfunction maximum_iterations_Callback(hObject, eventdata, handles)% hObject handle to maximum_iterations (see GCBO)% eventdata reserved - to be de

22、fined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,String) returns contents of maximum_iterations as text% str2double(get(hObject,String) returns contents of maximum_iterations as a doubles = str2double(get(hObject,String);if isnan(s)

23、set(hObject,String,10000)endif s set(hObject,String,10000)end% - Executes during object creation, after setting all properties.function maximum_iterations_CreateFcn(hObject, eventdata, handles)% hObject handle to maximum_iterations (see GCBO)% eventdata reserved - to be defined in a future version o

24、f MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end% - Exe

25、cutes on slider movement.function cooling_rate_Callback(hObject, eventdata, handles)% hObject handle to cooling_rate (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,Value) returns position of

26、 slider% get(hObject,Min) and get(hObject,Max) to determine range of sliders = sprintf(Cooling Rate : %0.3f,get(hObject,Value);set(handles.cooling_rate_display, String, s);% - Executes during object creation, after setting all properties.function cooling_rate_CreateFcn(hObject, eventdata, handles)%

27、hObject handle to cooling_rate (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: slider controls usually have a light gray background.if isequal(get(hObject,BackgroundColor), get(0,defaultUicontr

28、olBackgroundColor) set(hObject,BackgroundColor,.9 .9 .9);end% - Executes on slider movement.function cities_to_swap_Callback(hObject, eventdata, handles)% hObject handle to cities_to_swap (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and

29、 user data (see GUIDATA)% Hints: get(hObject,Value) returns position of slider% get(hObject,Min) and get(hObject,Max) to determine range of sliders = sprintf(Cities to swap : %d,get(hObject,Value);set(handles.cities_to_swap_display,String,s)% - Executes during object creation, after setting all prop

30、erties.function cities_to_swap_CreateFcn(hObject, eventdata, handles)% hObject handle to cities_to_swap (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: slider controls usually have a light gray

31、 background.if isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,.9 .9 .9);end% - Executes during object creation, after setting all properties.function cooling_rate_display_CreateFcn(hObject, eventdata, handles)% hObject handle to cooling_rate_

32、display (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% - Executes during object creation, after setting all properties.function cities_to_swap_display_CreateFcn(hObject, eventdata, handles)% hObject

33、 handle to cities_to_swap_display (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% - Executes on button press in start_button.function start_button_Callback(hObject, eventdata, handles)% hObject handl

34、e to start_button (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)selection = get(handles.select_data_set, Value);switch selection case 2 data_file; case 3 loadbays29; case 4 loadatt48; case 5 loadst70; case 6 lo

35、adpr76; case 7 loadgr96; case 8 loadeil101; case 9 loadpcb442; case 10 loadeil535;endif selection = 1 set(handles.initial_temperature, Enable, Off) set(handles.cooling_rate, Enable, Off) set(handles.maximum_iterations, Enable, Off) set(handles.cities_to_swap, Enable, Off) set(handles.start_button, E

36、nable, Off) set(handles.select_data_set, Enable, Off) cities = load (cities.mat); cities = cities.cities; simulatedannealing(cities,. str2double(get(handles.initial_temperature,String),. get(handles.cooling_rate,Value),. str2double(get(handles.maximum_iterations,String),. get(handles.cities_to_swap,

37、Value); set(handles.initial_temperature, Enable, On) set(handles.cooling_rate, Enable, On) set(handles.maximum_iterations, Enable, On) set(handles.cities_to_swap, Enable, On) set(handles.start_button, Enable, On) set(handles.select_data_set, Enable, On)end% - Executes on selection change in select_d

38、ata_set.function select_data_set_Callback(hObject, eventdata, handles)% hObject handle to select_data_set (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,String) returns select_dat

39、a_set contents as cell array% contentsget(hObject,Value) returns selected item from select_data_set% - Executes during object creation, after setting all properties.function select_data_set_CreateFcn(hObject, eventdata, handles)% hObject handle to select_data_set (see GCBO)% eventdata reserved - to

40、be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: popupmenu controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObj

41、ect,BackgroundColor,white);endfunction varargout = stsp_v61_export(varargin)% STSP_V61_EXPORT M-file for stsp_v61_export.fig% STSP_V61_EXPORT, by itself, creates a new STSP_V61_EXPORT or raises the existing% singleton*.% H = STSP_V61_EXPORT returns the handle to a new STSP_V61_EXPORT or the handle t

42、o% the existing singleton*.% STSP_V61_EXPORT(CALLBACK,hObject,eventData,handles,.) calls the local% function named CALLBACK in STSP_V61_EXPORT.M with the given input arguments.% STSP_V61_EXPORT(Property,Value,.) creates a new STSP_V61_EXPORT or raises the% existing singleton*. Starting from the left

43、, property value pairs are% applied to the GUI before stsp_v61_export_OpeningFunction gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to stsp_v61_export_OpeningFcn via varargin.% *See GUI Options on GUIDEs Tools menu. Choose GUI al

44、lows only one% instance to run (singleton).% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help stsp_v61_export% Last Modified by GUIDE v2.5 22-Mar-2006 20:15:26% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct(gui_Name, mfilename, .

45、gui_Singleton, gui_Singleton, . gui_OpeningFcn, stsp_v61_export_OpeningFcn, . gui_OutputFcn, stsp_v61_export_OutputFcn, . gui_LayoutFcn, stsp_v61_export_LayoutFcn, . gui_Callback, );if nargin & ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargout1:nargout = gui_main

46、fcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before stsp_v61_export is made visible.function stsp_v61_export_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject ha

47、ndle 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 stsp_v61_export (see VARARGIN)% Choose default command line output for stsp_v61_exporthandles.output = hObject;% Update han

48、dles structureguidata(hObject, handles);% UIWAIT makes stsp_v61_export wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the command line.function varargout = stsp_v61_export_OutputFcn(hObject, eventdata, handles) % varargout cell array for

49、 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 structurevarargout1 = handles.output;function initial_temperat

50、ure_Callback(hObject, eventdata, handles)% hObject handle to initial_temperature (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,String) returns contents of initial_temperature as text% str2d

51、ouble(get(hObject,String) returns contents of initial_temperature as a doubles = str2double(get(hObject,String);if isnan(s) set(hObject,String,1000)endif s 10000 set(hObject,String,1000)end% - Executes during object creation, after setting all properties.function initial_temperature_CreateFcn(hObjec

52、t, eventdata, handles)% hObject handle to initial_temperature (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolB

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论