diff --git a/src/solvers/hp/hp.cc b/src/solvers/hp/hp.cc index 9b71fdd07..6cdcaf83b 100644 --- a/src/solvers/hp/hp.cc +++ b/src/solvers/hp/hp.cc @@ -34,29 +34,33 @@ HPStrategySolve(const MixedStrategyProfile &p_prior) std::list> equilibria; HPEquationSystem system(p_prior); - Vector x = system.ComputeInitialPoint(); const PathTracer tracer; - double omega = 1.0; + Vector x; + double p_omega = 1.0; - auto termination_condition = [](const Vector &point) { return point[1] >= 1.5; }; - auto criterion_function = [](const Vector &point, - const Vector &tangent) -> double { return point[1] - 1.0; }; + const double t_target = 1.0; + const double t_tol = 0.5; + + auto criterion_function = [t_target](const Vector &point, + const Vector &tangent) -> double { + return point[1] - t_target; + }; + + x = system.ComputeInitialPoint(); + + auto termination_condition = [t_target, t_tol](const Vector &point) { + return (point[1] >= t_target + t_tol); + }; const TracePathResult result = tracer.TracePath( [&system](const Vector &point, Vector &lhs) { system.GetValue(point, lhs); }, [&system](const Vector &point, Matrix &jac) { system.GetJacobian(point, jac); }, - x, omega, termination_condition, + x, p_omega, termination_condition, [&system](const Vector &point) { - std::cout << "[Path Tracer Step] t = " << point[1]; - std::cout << " | Alfas: "; - for (size_t i = 2; i <= 5; ++i) { - std::cout << point[i] << " "; - } - std::cout << "| Mu: " << point[6] << " " << point[7] << std::endl; - + std::cout << "[Path Tracer Step] t = " << point[1] << std::endl; std::cout << "Full point vector in probabilities: "; Vector prob_vector = system.ExtractEquilibrium(point).GetProbVector(); for (size_t i = 1; i <= prob_vector.size(); ++i) { @@ -66,7 +70,23 @@ HPStrategySolve(const MixedStrategyProfile &p_prior) }, criterion_function); - equilibria.push_back(system.ExtractEquilibrium(x)); + const MixedStrategyProfile eq_profile = system.ExtractEquilibrium(x); + + equilibria.push_back(eq_profile); + + // Check that the profile is an equilibrium taking into account how far we are from the target t + // value + const double delta = std::abs(t_target - x[1]); + const double scale = p_prior.GetGame()->GetMaxPayoff() - p_prior.GetGame()->GetMinPayoff(); + const double max_regret = eq_profile.GetMaxRegret(); + // error tolerance <= delta * scale + const double error_tolerance = + (delta * scale) + 1e-6; // Add a small epsilon to account for numerical errors + + // If it is not an equilibrium, return an empty list + if (max_regret > error_tolerance) { + return {}; + } return equilibria; } } // namespace Gambit