📄 easylocaltemplates_cpp-source.html
字号:
00554 mv_cost = <a class="code" href="class_easylocal__NeighborhoodExplorer.html#a12">DeltaCostFunction</a>(st,mv);
00555 best_move = mv;
00556 fvalue best_delta = mv_cost;
00557 <font class="keywordflow">do</font> <font class="comment">// look for the best non prohibited move </font>
00558 { <font class="comment">// (if all moves are prohibited, then get the best)</font>
00559 tabu_move = p_pm->ProhibitedMove(mv,mv_cost,curr,best);
00560 <font class="keywordflow">if</font> ( (mv_cost < best_delta && !tabu_move)
00561 || (mv_cost < best_delta && all_moves_tabu)
00562 || (all_moves_tabu && !tabu_move))
00563 {
00564 best_move = mv;
00565 best_delta = mv_cost;
00566 }
00567 <font class="keywordflow">if</font> (!tabu_move)
00568 all_moves_tabu = <font class="keyword">false</font>;
00569 <a class="code" href="class_easylocal__NeighborhoodExplorer.html#a2">NextMove</a>(st,mv);
00570 mv_cost = <a class="code" href="class_easylocal__NeighborhoodExplorer.html#a12">DeltaCostFunction</a>(st,mv);
00571 }
00572 <font class="keywordflow">while</font> (!<a class="code" href="class_easylocal__NeighborhoodExplorer.html#a8">LastMoveDone</a>(mv));
00573 mv = best_move;
00574 <font class="keywordflow">return</font> best_delta;
00575 }
00576
00577
00589 template <class Input, class State, class Move>
<a name="l00590"></a><a class="code" href="class_easylocal__NeighborhoodExplorer.html#a7">00590</a> fvalue NeighborhoodExplorer<Input,State,Move>::SampleNonProhibitedMove(<font class="keyword">const</font> State &st, Move& mv, <font class="keywordtype">int</font> samples, fvalue curr, fvalue best)<font class="keyword"></font>
00591 <font class="keyword"> </font>{
00592 <font class="keywordtype">int</font> s = 1;
00593 fvalue mv_cost;
00594 <font class="keywordtype">bool</font> tabu_move;
00595 <font class="keywordtype">bool</font> all_moves_tabu = <font class="keyword">true</font>;
00596
00597 <a class="code" href="class_easylocal__NeighborhoodExplorer.html#a3">RandomMove</a>(st,mv);
00598 mv_cost = <a class="code" href="class_easylocal__NeighborhoodExplorer.html#a12">DeltaCostFunction</a>(st,mv);
00599 best_move = mv;
00600 fvalue best_delta = mv_cost;
00601 <font class="keywordflow">do</font>
00602 {
00603 tabu_move = p_pm->ProhibitedMove(mv,mv_cost,curr,best);
00604 <font class="keywordflow">if</font> ( (mv_cost < best_delta && !tabu_move)
00605 || (mv_cost < best_delta && all_moves_tabu)
00606 || (all_moves_tabu && !tabu_move))
00607 {
00608 best_move = mv;
00609 best_delta = mv_cost;
00610 }
00611 <font class="keywordflow">if</font> (!tabu_move)
00612 all_moves_tabu = <font class="keyword">false</font>;
00613 <a class="code" href="class_easylocal__NeighborhoodExplorer.html#a3">RandomMove</a>(st,mv);
00614 mv_cost = <a class="code" href="class_easylocal__NeighborhoodExplorer.html#a12">DeltaCostFunction</a>(st,mv);
00615 s++;
00616 }
00617 <font class="keywordflow">while</font> (s < samples);
00618 mv = best_move;
00619 <font class="keywordflow">return</font> best_delta;
00620 }
00621
00622
00630 template <class Input, class State, class Move>
<a name="l00631"></a><a class="code" href="class_easylocal__NeighborhoodExplorer.html#a14">00631</a> <font class="keywordtype">void</font> NeighborhoodExplorer<Input,State,Move>::PrintMoveInfo(<font class="keyword">const</font> State &st, <font class="keyword">const</font> Move& mv, std::ostream& os)<font class="keyword"></font>
00632 <font class="keyword"> </font>{
00633 os << <font class="stringliteral">"Move : "</font> << mv << std::endl;
00634 os << <font class="stringliteral">"Start state cost : "</font> << p_sm->CostFunction(st) << std::endl;
00635 os << <font class="stringliteral">"\tViolations : "</font> << p_sm->Violations(st) << std::endl;
00636 os << <font class="stringliteral">"\tObjective : "</font> << p_sm->Objective(st) << std::endl;
00637
00638 os << <font class="stringliteral">"Move cost : "</font> << <a class="code" href="class_easylocal__NeighborhoodExplorer.html#a12">DeltaCostFunction</a>(st,mv) << std::endl;
00639 os << <font class="stringliteral">"\tViolations : "</font> << <a class="code" href="class_easylocal__NeighborhoodExplorer.html#b3">DeltaViolations</a>(st,mv) << std::endl;
00640 os << <font class="stringliteral">"\tObjective : "</font> << <a class="code" href="class_easylocal__NeighborhoodExplorer.html#b2">DeltaObjective</a>(st,mv) << std::endl;
00641
00642 State st1 = st;
00643 <a class="code" href="class_easylocal__NeighborhoodExplorer.html#a11">MakeMove</a>(st1,mv);
00644 os << <font class="stringliteral">"Final state cost : "</font> << p_sm->CostFunction(st1) << std::endl;
00645 os << <font class="stringliteral">"\tViolations : "</font> << p_sm->Violations(st1) << std::endl;
00646 os << <font class="stringliteral">"\tObjective : "</font> << p_sm->Objective(st1) << std::endl;
00647
00648 os << <font class="stringliteral">"Error : "</font> << p_sm->CostFunction(st1) - <a class="code" href="class_easylocal__NeighborhoodExplorer.html#a12">DeltaCostFunction</a>(st,mv) - p_sm->CostFunction(st) << std::endl;
00649 }
00650
00656 template <class Input, class State, class Move>
<a name="l00657"></a><a class="code" href="class_easylocal__NeighborhoodExplorer.html#a16">00657</a> <font class="keywordtype">void</font> NeighborhoodExplorer<Input,State,Move>::SetInput(Input* in)<font class="keyword"> </font>
00658 <font class="keyword"> </font>{ p_in = in; }
00659
00665 template <class Input, class State, class Move>
<a name="l00666"></a><a class="code" href="class_easylocal__NeighborhoodExplorer.html#a17">00666</a> Input* NeighborhoodExplorer<Input,State,Move>::GetInput()<font class="keyword"> </font>
00667 <font class="keyword"> </font>{ <font class="keywordflow">return</font> p_in; }
00668
00673 template <class Input, class State, class Move>
<a name="l00674"></a><a class="code" href="class_easylocal__NeighborhoodExplorer.html#a18">00674</a> <font class="keywordtype">void</font> NeighborhoodExplorer<Input,State,Move>::Check()<font class="keyword"></font>
00675 <font class="keyword"> </font>{ assert(p_in != NULL && p_in == p_sm->GetInput()); }
00676
00688 template <class Input, class State, class Move>
<a name="l00689"></a><a class="code" href="class_easylocal__NeighborhoodExplorer.html#b3">00689</a> fvalue NeighborhoodExplorer<Input,State,Move>::DeltaViolations(<font class="keyword">const</font> State& st, <font class="keyword">const</font> Move & mv)<font class="keyword"></font>
00690 <font class="keyword"> </font>{
00691 State st1 = st;
00692 <a class="code" href="class_easylocal__NeighborhoodExplorer.html#a11">MakeMove</a>(st1,mv);
00693 <font class="keywordflow">return</font> p_sm->Violations(st1) - p_sm->Violations(st);
00694 }
00695
00707 template <class Input, class State, class Move>
<a name="l00708"></a><a class="code" href="class_easylocal__NeighborhoodExplorer.html#b2">00708</a> fvalue NeighborhoodExplorer<Input,State,Move>::DeltaObjective(<font class="keyword">const</font> State& st, <font class="keyword">const</font> Move & mv)<font class="keyword"></font>
00709 <font class="keyword"> </font>{
00710 State st1 = st;
00711 <a class="code" href="class_easylocal__NeighborhoodExplorer.html#a11">MakeMove</a>(st1,mv);
00712 <font class="keywordflow">return</font> p_sm->Objective(st1) - p_sm->Objective(st);
00713 }
00714
00723 template <class Input, class State, class Move>
<a name="l00724"></a><a class="code" href="class_easylocal__NeighborhoodExplorer.html#a8">00724</a> <font class="keywordtype">bool</font> NeighborhoodExplorer<Input,State,Move>::LastMoveDone(<font class="keyword">const</font> Move &mv)<font class="keyword"> </font>
00725 <font class="keyword"> </font>{ <font class="keywordflow">return</font> mv == start_move; }
00726
00727 <font class="comment">// Runner functions</font>
00728
00735 template <class Input, class State>
<a name="l00736"></a><a class="code" href="class_easylocal__Runner.html#a1">00736</a> Runner<Input,State>::Runner(std::string s, std::string t)
00737 : name(s), type(t)
00738 {}
00739
00745 template <class Input, class State>
<a name="l00746"></a><a class="code" href="class_easylocal__Runner.html#a14">00746</a> std::string Runner<Input,State>::Name()<font class="keyword"> </font>
00747 <font class="keyword"> </font>{ <font class="keywordflow">return</font> name; }
00748
00754 template <class Input, class State>
<a name="l00755"></a><a class="code" href="class_easylocal__Runner.html#a15">00755</a> std::string Runner<Input,State>::Type()<font class="keyword"></font>
00756 <font class="keyword"> </font>{ <font class="keywordflow">return</font> type; }
00757
00763 template <class Input, class State>
<a name="l00764"></a><a class="code" href="class_easylocal__Runner.html#a16">00764</a> <font class="keywordtype">void</font> Runner<Input,State>::SetName(std::string s)<font class="keyword"> </font>
00765 <font class="keyword"> </font>{ name = s; }
00766
00778 template <class Input, class State, class Move>
<a name="l00779"></a><a class="code" href="class_easylocal__MoveRunner.html#b0">00779</a> MoveRunner<Input,State,Move>::MoveRunner(StateManager<Input,State>* sm, NeighborhoodExplorer<Input,State,Move>* ne, Input* in, std::string name, std::string type)
00780 : Runner<Input,State>(name,type), p_in(in), p_sm(sm), p_nhe(ne)
00781 {
00782 <font class="keywordflow">if</font> (in != NULL)
00783 current_state.SetInput(in);
00784 number_of_iterations = 0;
00785 max_iteration = ULONG_MAX;
00786 current_state_set = <font class="keyword">false</font>;
00787 }
00788
00794 template <class Input, class State, class Move>
<a name="l00795"></a><a class="code" href="class_easylocal__MoveRunner.html#a13">00795</a> <font class="keywordtype">void</font> MoveRunner<Input,State,Move>::SetInput(Input* in)<font class="keyword"> </font>
00796 <font class="keyword"> </font>{
00797 p_in = in;
00798 current_state.SetInput(in);
00799 current_state_set = <font class="keyword">false</font>;
00800 p_nhe->SetInput(in);
00801 }
00802
00808 template <class Input, class State, class Move>
<a name="l00809"></a><a class="code" href="class_easylocal__MoveRunner.html#a14">00809</a> Input* MoveRunner<Input,State,Move>::GetInput()<font class="keyword"> </font>
00810 <font class="keyword"> </font>{ <font class="keywordflow">return</font> p_in; }
00811
00817 template <class Input, class State, class Move>
<a name="l00818"></a><a class="code" href="class_easylocal__MoveRunner.html#a15">00818</a> <font class="keywordtype">void</font> MoveRunner<Input,State,Move>::Print(std::ostream& os)<font class="keyword"> const</font>
00819 <font class="keyword"> </font>{ os << name << <font class="stringliteral">" : "</font> << type << std::endl; }
00820
00825 template <class Input, class State, class Move>
<a name="l00826"></a><a class="code" href="class_easylocal__MoveRunner.html#a18">00826</a> <font class="keywordtype">void</font> MoveRunner<Input,State,Move>::Check()<font class="keyword"> </font>
00827 <font class="keyword"> </font>{
00828 assert(p_in != NULL);
00829 assert(p_in == p_sm->GetInput());
00830 assert(p_in == p_nhe->GetInput());
00831 }
00832
00833
00839 template <class Input, class State, class Move>
<a name="l00840"></a><a class="code" href="class_easylocal__MoveRunner.html#a3">00840</a> <font class="keywordtype">void</font> MoveRunner<Input,State,Move>::SetCurrentState(<font class="keyword">const</font> State& s)<font class="keyword"> </font>
00841 <font class="keyword"> </font>{
00842 current_state = s;
00843 current_state_set = <font class="keyword">true</font>;
00844 current_state_cost = p_sm->CostFunction(current_state);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -