29 #ifndef _BGIP_SOLVERALTERNATINGMAXIMIZATION_H_
30 #define _BGIP_SOLVERALTERNATINGMAXIMIZATION_H_ 1
43 #define DEBUG_BGIP_SOLVER_AM_SOLVE 0
44 #define DEBUG_BGIP_SOLVER_AM_SOLVE_EXTRAVERBOSE 0
45 #define CHECK_NEW_BR 0
64 Index optimizingAgentI)
68 std::cout <<
"ComputeBestResponse called - current jpolBG:"<<std::endl;
70 std::cout <<
"value="<< this->
Evaluate(jpolBG) <<std::endl;
73 Index agI = optimizingAgentI;
74 std::vector< std::vector<double> > v (bgip->
GetNrTypes(agI), std::vector<double>(
81 Index type = types.at(agI);
83 Index jaI = jpolBG.GetJointActionIndex(jt);
89 v[type][acI] += jtProb * bgip->
GetUtility(jt, jaInew);
96 double v_t = -DBL_MAX;
100 double v_t_a = v[type][acI];
108 jpolBG.SetAction(agI, type, best_a);
120 unsigned int nrRestarts=10,
122 size_t nrSolutions=1) :
134 std::cout <<
"BGIP_SolverAlternatingMaximization::Solve() started"<<std::endl;
137 struct timeval start_time, cur_time;
138 if(gettimeofday(&start_time, NULL) != 0)
139 throw "Error with gettimeofday";
145 double vmax = -DBL_MAX;
150 std::cout <<
"AM: new restart"<<std::endl;
151 double v_thisAMrun = -DBL_MAX;
152 jpolBG.RandomInitialization();
158 Index optimizingAgentI = 0;
159 #if DEBUG_BGIP_SOLVER_AM_SOLVE
161 std::std::cout<<
"\n>new AM restart - initialized with v="<<
163 #if DEBUG_BGIP_SOLVER_AM_SOLVE_EXTRAVERBOSE
164 std::std::cout <<
" - pol:"<<std::std::endl;
167 std::std::cout << std::std::endl;
171 bool improving =
true;
172 size_t nr_non_improving_agents = 0;
177 while(nr_non_improving_agents < bgip->GetNrAgents() )
180 std::cout <<
"AM: computing new best response...";
185 std::cout <<
"v="<<v<<std::endl;
187 JP checkjpolBG = jpolBG;
189 ComputeBestResponseOld(checkjpolBG, optimizingAgentI);
190 if(jpolBG.GetIndex() != checkjpolBG.GetIndex())
192 std::cout <<
"Error best response computation failed!!!"<<std::endl;
193 std::cout <<
"v="<<v<<
", vcheck="<<vcheck<<std::endl;
194 std::cout <<
"jpolBG="<< jpolBG.SoftPrint();
195 std::cout <<
"checkjpolBG="<< jpolBG.SoftPrint();
198 #if DEBUG_BGIP_SOLVER_AM_SOLVE
200 std::std::cout<<
"best response achieves v="<< v ;
201 #if DEBUG_BGIP_SOLVER_AM_SOLVE_EXTRAVERBOSE
202 std::std::cout <<
" - pol:"<<std::std::endl;
205 std::std::cout << std::std::endl;
209 if(v > v_thisAMrun + 1e-9)
211 #if DEBUG_BGIP_SOLVER_AM_SOLVE
212 std::std::cout <<
"(improving)" <<std::std::endl;
220 nr_non_improving_agents = 0;
222 nr_non_improving_agents++;
224 optimizingAgentI = (optimizingAgentI+1) % bgip->
GetNrAgents();
227 std::cout <<
"AM run ended" <<std::endl;
229 size_t oldNrSolutionsFound=
237 != (oldNrSolutionsFound+1))
238 std::cout <<
"AM: computed policy not added to BGIPSolution, probably a duplicate" << std::endl;
240 if(v_thisAMrun > vmax)
245 std::cout <<
"(best solution)" <<std::endl;
265 std::cout <<
"BGIP_SolverAlternatingMaximization finished, first solution: " <<