📄 easylocaltemplates_cpp-source.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>EasyLocal++ Documentation</title>
<link href="local.css" rel="stylesheet" type="text/css">
</head>
<body lang="en">
<table width="100%" border="0">
<tbody>
<tr>
<td colspan="2"><h1 class="nojustify">EasyLocal++ Documentation</h1>
<hr>
</td>
</tr>
<tr>
<td width="30" align="center"> </td>
<td>
<!-- Generated by Doxygen 1.2.5 on Sat Jun 9 18:59:15 2001 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> </center>
<hr><h1>EasyLocalTemplates.cpp</h1><a href="EasyLocalTemplates_cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00017 <font class="keyword">namespace </font>easylocal {
00018
00019 <font class="comment">// State Manager functions</font>
00020
00028 template <class Input, class State>
<a name="l00029"></a><a class="code" href="class_easylocal__StateManager.html#a2">00029</a> fvalue StateManager<Input,State>::SampleState(State &st, <font class="keywordtype">int</font> samples)<font class="keyword"></font>
00030 <font class="keyword"> </font>{
00031 <font class="keywordtype">int</font> s = 1;
00032 <a class="code" href="class_easylocal__StateManager.html#a0">RandomState</a>(st);
00033 fvalue cost = <a class="code" href="class_easylocal__StateManager.html#a4">CostFunction</a>(st);
00034 State best_state = st;
00035 fvalue best_cost = cost;
00036 <font class="keywordflow">while</font> (s < samples)
00037 {
00038 <a class="code" href="class_easylocal__StateManager.html#a0">RandomState</a>(st);
00039 cost = <a class="code" href="class_easylocal__StateManager.html#a4">CostFunction</a>(st);
00040 <font class="keywordflow">if</font> (cost < best_cost)
00041 {
00042 best_state = st;
00043 best_cost = cost;
00044 }
00045 s++;
00046 }
00047 st = best_state;
00048 <font class="keywordflow">return</font> best_cost;
00049 }
00050
00060 template <class Input, class State>
<a name="l00061"></a><a class="code" href="class_easylocal__StateManager.html#a3">00061</a> fvalue StateManager<Input,State>::ImprovedSampleState(State &st, <font class="keywordtype">int</font> samples, Runner<Input,State>* r)<font class="keyword"></font>
00062 <font class="keyword"> </font>{ <font class="comment">// same of SampleState, except that each sample is let run using r</font>
00063 <font class="comment">// before comparing its value</font>
00064 <font class="keywordtype">int</font> s = 1;
00065 <a class="code" href="class_easylocal__StateManager.html#a0">RandomState</a>(st);
00066 r->SetCurrentState(st);
00067 r->Go();
00068 st = r->GetCurrentState();
00069 fvalue cost = <a class="code" href="class_easylocal__StateManager.html#a4">CostFunction</a>(st);
00070 State best_state = st;
00071 fvalue best_cost = cost;
00072 <font class="keywordflow">do</font>
00073 {
00074 cost = <a class="code" href="class_easylocal__StateManager.html#a4">CostFunction</a>(st);
00075 <font class="keywordflow">if</font> (cost < best_cost)
00076 {
00077 best_state = st;
00078 best_cost = cost;
00079 }
00080 <a class="code" href="class_easylocal__StateManager.html#a0">RandomState</a>(st);
00081 r->SetCurrentState(st);
00082 r->Go();
00083 st = r->GetCurrentState();
00084 s++;
00085 }
00086 <font class="keywordflow">while</font> (s <= samples);
00087 st = best_state;
00088 <font class="keywordflow">return</font> best_cost;
00089 }
00090
00098 template <class Input, class State>
<a name="l00099"></a><a class="code" href="class_easylocal__StateManager.html#a4">00099</a> fvalue StateManager<Input,State>::CostFunction(<font class="keyword">const</font> State& st)<font class="keyword"> const </font>
00100 <font class="keyword"> </font>{ <font class="keywordflow">return</font> HARD_WEIGHT * <a class="code" href="class_easylocal__StateManager.html#a6">Violations</a>(st) + <a class="code" href="class_easylocal__StateManager.html#a5">Objective</a>(st); }
00101
00107 template <class Input, class State>
<a name="l00108"></a><a class="code" href="class_easylocal__StateManager.html#a7">00108</a> <font class="keywordtype">void</font> StateManager<Input,State>::PrintState(<font class="keyword">const</font> State& st)<font class="keyword"> const</font>
00109 <font class="keyword"> </font>{
00110 std::cout << st << std::endl;
00111 std::cout << <font class="stringliteral">"Total cost : "</font> << <a class="code" href="class_easylocal__StateManager.html#a4">CostFunction</a>(st) << std::endl;
00112 std::cout << <font class="stringliteral">" Violations : "</font> << <a class="code" href="class_easylocal__StateManager.html#a6">Violations</a>(st) << std::endl;
00113 std::cout << <font class="stringliteral">" Objective : "</font> << <a class="code" href="class_easylocal__StateManager.html#a5">Objective</a>(st) << std::endl;
00114 }
00115
00123 template <class Input, class State>
<a name="l00124"></a><a class="code" href="class_easylocal__StateManager.html#a6">00124</a> fvalue StateManager<Input,State>::Violations(<font class="keyword">const</font> State& st)<font class="keyword"> const</font>
00125 <font class="keyword"> </font>{
00126 std::cout << <font class="stringliteral">"Warning: violations function not implemented yet!"</font> << std::endl;
00127 <font class="keywordflow">return</font> 0;
00128 }
00129
00137 template <class Input, class State>
<a name="l00138"></a><a class="code" href="class_easylocal__StateManager.html#a5">00138</a> fvalue StateManager<Input,State>::Objective(<font class="keyword">const</font> State& st)<font class="keyword"> const</font>
00139 <font class="keyword"> </font>{
00140 std::cout << <font class="stringliteral">"Warning: violations function not implemented yet!"</font> << std::endl;
00141 <font class="keywordflow">return</font> 0;
00142 }
00143
00149 template <class Input, class State>
<a name="l00150"></a><a class="code" href="class_easylocal__StateManager.html#a9">00150</a> <font class="keywordtype">void</font> StateManager<Input,State>::SetInput(Input* in)<font class="keyword"> </font>
00151 <font class="keyword"> </font>{ p_in = in; }
00152
00158 template <class Input, class State>
<a name="l00159"></a><a class="code" href="class_easylocal__StateManager.html#a10">00159</a> Input* StateManager<Input,State>::GetInput()<font class="keyword"> </font>
00160 <font class="keyword"> </font>{ <font class="keywordflow">return</font> p_in; }
00161
00166 template <class Input, class State>
<a name="l00167"></a><a class="code" href="class_easylocal__StateManager.html#a8">00167</a> <font class="keywordtype">void</font> StateManager<Input,State>::Check()<font class="keyword"> const</font>
00168 <font class="keyword"> </font>{ assert(p_in != NULL); }
00169
00175 template <class Input, class State>
<a name="l00176"></a><a class="code" href="class_easylocal__StateManager.html#b0">00176</a> StateManager<Input,State>::StateManager(Input* in)
00177 : p_in(in)
00178 {}
00179
00180 <font class="comment">// Output Manager functions</font>
00181
00182
00189 template <class Input, class Output, class State>
<a name="l00190"></a><a class="code" href="class_easylocal__OutputManager.html#a2">00190</a> <font class="keywordtype">void</font> OutputManager<Input,Output,State>::ReadState(State &st, std::istream &is)<font class="keyword"> const</font>
00191 <font class="keyword"> </font>{
00192 Output out(p_in);
00193 is >> out;
00194 <a class="code" href="class_easylocal__OutputManager.html#a1">InputState</a>(st,out);
00195 }
00196
00203 template <class Input, class Output, class State>
<a name="l00204"></a><a class="code" href="class_easylocal__OutputManager.html#a3">00204</a> <font class="keywordtype">void</font> OutputManager<Input,Output,State>::WriteState(<font class="keyword">const</font> State &st, std::ostream &os)<font class="keyword"> const</font>
00205 <font class="keyword"> </font>{
00206 Output out(p_in);
00207 <a class="code" href="class_easylocal__OutputManager.html#a0">OutputState</a>(st,out);
00208 os << out;
00209 }
00210
00216 template <class Input, class Output, class State>
<a name="l00217"></a><a class="code" href="class_easylocal__OutputManager.html#a5">00217</a> <font class="keywordtype">void</font> OutputManager<Input,Output,State>::SetInput(Input* in)<font class="keyword"> </font>
00218 <font class="keyword"> </font>{ p_in = in; }
00219
00225 template <class Input, class Output, class State>
<a name="l00226"></a><a class="code" href="class_easylocal__OutputManager.html#a6">00226</a> Input* OutputManager<Input,Output,State>::GetInput()<font class="keyword"> </font>
00227 <font class="keyword"> </font>{ <font class="keywordflow">return</font> p_in; }
00228
00233 template <class Input, class Output, class State>
<a name="l00234"></a><a class="code" href="class_easylocal__OutputManager.html#a4">00234</a> <font class="keywordtype">void</font> OutputManager<Input,Output,State>::Check()<font class="keyword"> const</font>
00235 <font class="keyword"> </font>{
00236 assert(p_in != NULL && p_sm->GetInput() == p_in);
00237 }
00238
00239 <font class="comment">// Prohibition Manager functions</font>
00240 <font class="comment">// up to now, the only actual prohibition manager is the tabu list manager</font>
00241
00249 template <class Move>
<a name="l00250"></a><a class="code" href="class_easylocal__TabuListManager.html#b0">00250</a> TabuListManager<Move>::TabuListManager(<font class="keywordtype">int</font> min, <font class="keywordtype">int</font> max)
00251 : min_tenure(min), max_tenure(max), iter(0)
00252 { }
00253
00254
00262 template <class Move>
<a name="l00263"></a><a class="code" href="class_easylocal__TabuListManager.html#a0">00263</a> <font class="keywordtype">void</font> TabuListManager<Move>::InsertMove(<font class="keyword">const</font> Move& mv, fvalue mv_cost, fvalue curr, fvalue best)<font class="keyword"></font>
00264 <font class="keyword"> </font>{
00265 <a class="code" href="class_easylocal__TabuListManager.html#b3">InsertIntoList</a>(mv);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -