⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabu_c file reference.htm

📁 禁忌算法的源程序和一个示例的PPT演示稿 以及几个使用的关于禁忌算法的HTML文稿
💻 HTM
📖 第 1 页 / 共 2 页
字号:
00036      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/structList__routes.html">list_of_routes</A> aspirantlist;
00037      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/structlist__of__tabu.html">link</A> present;
00038         
00039      <SPAN class=comment>//This defines a routes called best_so_far which stores best routes and its fitness value</SPAN>
00040      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/structindividualroute.html">route</A> current;
00041      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/structindividualroute.html">route</A> blank;
00042         
00043         
00044      <SPAN class=keywordtype>int</SPAN> i, j, l, m, result = 0;
00045      <SPAN class=keywordtype>int</SPAN> count = 0;
00046 
00047 
00048    <SPAN class=keywordtype>int</SPAN> stop_time = 0;           <SPAN class=comment>//This stores the amount of time the code should run</SPAN>
00049     <SPAN class=keywordtype>int</SPAN> stop = 1;                       <SPAN class=comment>//The loop for the time stop</SPAN>
00050    clock_t time1;       <SPAN class=comment>//stores the finish time</SPAN>
00051    
00052     time1 = clock (); <SPAN class=comment>//get start time</SPAN>
00053   
00054   
00055   <SPAN class=comment>//convert argument to integer</SPAN>
00056   stop_time = atoi (argv[1]);
00057   
00058    time1+=stop_time*CLOCKS_PER_SEC; <SPAN class=comment>//calculate what finish time is</SPAN>
00059   <SPAN class=comment>//This function creates the data and initialises it </SPAN>
00060   <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2getspace_8c.html#a0">get_space</A> (&amp;size, &amp;no_vehicles, &amp;neighbourhood, &amp;aspirantlist, &amp;constraint, &amp;current, &amp;blank);
00061        
00062 
00063     <SPAN class=comment>//This function creates a circular tabu list of size TABUSIZE and returrns the present position it the list(use casting to get rid of warning)</SPAN>
00064      present = (link) <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabulist_8c.html#a0">create_tabu_list</A> ();
00065      
00066      
00067   <SPAN class=comment>//Gets the data from the files</SPAN>
00068     <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2getdata_8c.html#a0">getdata</A> (&amp;size, &amp;no_vehicles, &amp;constraint, &amp;current, &amp;blank );
00069      printf(<SPAN class=stringliteral>"\ncurrent with fitness\n"</SPAN>); 
00070      <SPAN class=comment>//get the first routes fitness</SPAN>
00071      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2fitness_8c.html#a1">onefitness</A> (&amp;size, &amp;no_vehicles,&amp;constraint, &amp;blank, &amp;current);
00072 
00073 
00074      <SPAN class=comment>//print the original route to the screen</SPAN>
00075      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2initialise_8c.html#a8">print_current</A> (&amp;size, &amp;no_vehicles,&amp;current);
00076 
00077      <SPAN class=comment>//create a  neighbourhood  for the current solution</SPAN>
00078      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/neighbourhood_8c.html#a0">get_neighbourhood</A> (&amp;size, &amp;no_vehicles, &amp;current, &amp;neighbourhood);
00079 
00080 
00081      <SPAN class=comment>//fitness takes in a list of routes of size listsize and finds there fitness </SPAN>
00082      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2fitness_8c.html#a0">fitness</A> (&amp;size, &amp;no_vehicles, &amp;neighbourhood,&amp;constraint, &amp;blank);
00083      
00084      printf(<SPAN class=stringliteral>"\nneighbourhood with fitness\n"</SPAN>);
00085      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2initialise_8c.html#a7">print_list_of_routes</A> (&amp;size, &amp;no_vehicles,&amp;neighbourhood);
00086 
00087      <SPAN class=comment>//Any route in the neighbourhood that has a better fitness that the current is added to the current</SPAN>
00088      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/neighbourhood_8c.html#a4">get_aspirant</A> (&amp;size, &amp;no_vehicles, &amp;aspirantlist, &amp;neighbourhood, &amp;current);
00089      
00090       printf(<SPAN class=stringliteral>"\naspirant with fitness\n"</SPAN>);
00091     <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2initialise_8c.html#a7">print_list_of_routes</A> (&amp;size, &amp;no_vehicles,&amp;aspirantlist);
00092 printf(<SPAN class=stringliteral>"help\n\n\n"</SPAN>);
00093      <SPAN class=keywordflow>for</SPAN> (m = 0; m &lt; stop; m++)
00094        {
00095      <SPAN class=comment>//print the original route to the screen</SPAN>
00096      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2initialise_8c.html#a8">print_current</A> (&amp;size, &amp;no_vehicles,&amp;current);
00097                 count=0;
00098                 <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/genetic__algorithm_2terminate_8c.html#a0">time_termination</A> (&amp;stop, &amp;time1);
00099             result = <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/neighbourhood_8c.html#a5">get_solution</A> (&amp;size, &amp;no_vehicles, &amp;neighbourhood, &amp;aspirantlist, present, &amp;current);
00100                  count=0;
00101              <SPAN class=comment>//print_tabu_list (present, count);  </SPAN>
00102             <SPAN class=comment>//If get solution returns 0 that means it must be run again as the solution was tabu</SPAN>
00103             <SPAN class=keywordflow>while</SPAN> (result == 0)
00104               {
00105                 printf(<SPAN class=stringliteral>"0"</SPAN>);
00106                    result = <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/neighbourhood_8c.html#a5">get_solution</A> (&amp;size, &amp;no_vehicles, &amp;neighbourhood, &amp;aspirantlist, present, &amp;current);
00107                    <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2initialise_8c.html#a7">print_list_of_routes</A> (&amp;size, &amp;no_vehicles, &amp;neighbourhood);
00108               }
00109 
00110             <SPAN class=keywordtype>int</SPAN> terminate = 0;
00111             <SPAN class=comment>//If get solution returns 2, if there is no better solution in the current neighbourhood</SPAN>
00112             <SPAN class=keywordflow>while</SPAN> (result == 2 &amp;&amp; terminate &lt; 10)
00113               {
00114                    <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/neighbourhood_8c.html#a0">get_neighbourhood</A> (&amp;size, &amp;no_vehicles, &amp;current, &amp;neighbourhood);
00115                    <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2fitness_8c.html#a0">fitness</A> (&amp;size, &amp;no_vehicles, &amp;neighbourhood,&amp;constraint, &amp;blank);
00116                    <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/neighbourhood_8c.html#a4">get_aspirant</A> (&amp;size, &amp;no_vehicles, &amp;aspirantlist, &amp;neighbourhood, &amp;current);
00117                    result = <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/neighbourhood_8c.html#a5">get_solution</A> (&amp;size, &amp;no_vehicles, &amp;neighbourhood, &amp;aspirantlist, present, &amp;current);
00118                    terminate++;
00119               }
00120         <SPAN class=keywordflow>if</SPAN>(terminate &gt;9){
00121         <SPAN class=comment>// m=100000;</SPAN>
00122           }
00123 
00124             <SPAN class=comment>//If get solution returns 1 that it has created a new solution and we must add it to the tabu list</SPAN>
00125             <SPAN class=keywordflow>if</SPAN> (result == 1)
00126               {
00127                 <SPAN class=comment>//printf("1");</SPAN>
00128                    <SPAN class=comment>//Add the current move to the tabu list and returns the position in the list</SPAN>
00129                    present = (link) <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabulist_8c.html#a2">add_tabu_list</A> (&amp;current, present);
00130                    <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/neighbourhood_8c.html#a0">get_neighbourhood</A> (&amp;size, &amp;no_vehicles, &amp;current, &amp;neighbourhood);
00131                    <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2fitness_8c.html#a0">fitness</A>(&amp;size, &amp;no_vehicles, &amp;neighbourhood,&amp;constraint, &amp;blank);
00132                    <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/neighbourhood_8c.html#a4">get_aspirant</A> (&amp;size, &amp;no_vehicles, &amp;aspirantlist, &amp;neighbourhood, &amp;current);
00133 
00134               }
00135        }
00136 
00137 
00138     
00139      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2initialise_8c.html#a8">print_current</A>( &amp;size, &amp;no_vehicles,&amp;current);
00140      
00141      <SPAN class=comment>//free all the space allocated</SPAN>
00142      count = 0;
00143      <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabulist_8c.html#a1">free_tabu_list</A> (present, count);
00144      
00145      
00146   <A class=code href="http://geminga.it.nuigalway.ie/~9709864p/html/tabu__search_2getspace_8c.html#a1">free_space</A>(&amp;size, &amp;no_vehicles, &amp;neighbourhood, &amp;aspirantlist, &amp;constraint, &amp;current, &amp;blank);
00147      fflush (stdout);
00148 
00149 }
</PRE></DIV></TD></TR></TBODY></TABLE><SMALL><A 
href="http://geminga.it.nuigalway.ie/~9709864p/">Ann Tighe 
</A></SMALL></P></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -