From ade7a6092d0758034271da34d198d7358d57c8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Fern=C3=A1ndez=20Cervell?= Date: Fri, 31 Jul 2026 18:36:01 +0200 Subject: [PATCH 1/4] Orientation-fix --- src/solvers/hp/hp.cc | 62 ++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/src/solvers/hp/hp.cc b/src/solvers/hp/hp.cc index 9b71fdd07..52725b9aa 100644 --- a/src/solvers/hp/hp.cc +++ b/src/solvers/hp/hp.cc @@ -34,37 +34,53 @@ HPStrategySolve(const MixedStrategyProfile &p_prior) std::list> equilibria; HPEquationSystem system(p_prior); - Vector x = system.ComputeInitialPoint(); const PathTracer tracer; + Vector x; double omega = 1.0; + bool wrong_orientation = false; - 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 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, - [&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; + for (int attemp = 0; attemp < 2; ++attemp) { + x = system.ComputeInitialPoint(); + wrong_orientation = false; - std::cout << "Full point vector in probabilities: "; - Vector prob_vector = system.ExtractEquilibrium(point).GetProbVector(); - for (size_t i = 1; i <= prob_vector.size(); ++i) { - std::cout << prob_vector[i] << " "; - } - std::cout << std::endl; - }, - criterion_function); + auto termination_condition = [&wrong_orientation](const Vector &point) { + const double wrong_orientation_tol = -1.0e-4; + if (point[1] < wrong_orientation_tol) { + wrong_orientation = true; + return true; + } + return point[1] >= 1.5; + }; + + 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, + [&system](const Vector &point) { + 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) { + std::cout << prob_vector[i] << " "; + } + std::cout << std::endl; + }, + criterion_function); + if (!wrong_orientation) { + break; + } + + // Direction was wrong, flip the orientation and try again + omega = -1.0; + } equilibria.push_back(system.ExtractEquilibrium(x)); return equilibria; From f390c433c0f4469d78a9d60164ac27569dc1f760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Fern=C3=A1ndez=20Cervell?= Date: Sun, 2 Aug 2026 20:24:01 +0200 Subject: [PATCH 2/4] Checking equilibrium --- src/solvers/hp/hp.cc | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/solvers/hp/hp.cc b/src/solvers/hp/hp.cc index 52725b9aa..f2c24ac01 100644 --- a/src/solvers/hp/hp.cc +++ b/src/solvers/hp/hp.cc @@ -40,20 +40,26 @@ HPStrategySolve(const MixedStrategyProfile &p_prior) double omega = 1.0; bool wrong_orientation = false; - 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; - for (int attemp = 0; attemp < 2; ++attemp) { + auto criterion_function = [t_target](const Vector &point, + const Vector &tangent) -> double { + return point[1] - t_target; + }; + + for (int attempt = 0; attempt < 2; ++attempt) { x = system.ComputeInitialPoint(); wrong_orientation = false; - auto termination_condition = [&wrong_orientation](const Vector &point) { + auto termination_condition = [&wrong_orientation, t_target, + t_tol](const Vector &point) { const double wrong_orientation_tol = -1.0e-4; if (point[1] < wrong_orientation_tol) { wrong_orientation = true; return true; } - return point[1] >= 1.5; + return (point[1] >= t_target + t_tol); }; const TracePathResult result = @@ -81,8 +87,23 @@ HPStrategySolve(const MixedStrategyProfile &p_prior) // Direction was wrong, flip the orientation and try again omega = -1.0; } + const MixedStrategyProfile eq_profile = system.ExtractEquilibrium(x); + + equilibria.push_back(eq_profile); - equilibria.push_back(system.ExtractEquilibrium(x)); + // 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 From 0507aca04ff92465903dfe039e0a9705770c238c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Fern=C3=A1ndez=20Cervell?= Date: Fri, 7 Aug 2026 14:33:57 +0200 Subject: [PATCH 3/4] Removing orientation logic --- src/solvers/hp/hp.cc | 59 ++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/src/solvers/hp/hp.cc b/src/solvers/hp/hp.cc index f2c24ac01..6e31a7357 100644 --- a/src/solvers/hp/hp.cc +++ b/src/solvers/hp/hp.cc @@ -37,8 +37,7 @@ HPStrategySolve(const MixedStrategyProfile &p_prior) const PathTracer tracer; Vector x; - double omega = 1.0; - bool wrong_orientation = false; + const double p_omega = 1.0; const double t_target = 1.0; const double t_tol = 0.5; @@ -48,45 +47,29 @@ HPStrategySolve(const MixedStrategyProfile &p_prior) return point[1] - t_target; }; - for (int attempt = 0; attempt < 2; ++attempt) { - x = system.ComputeInitialPoint(); - wrong_orientation = false; + x = system.ComputeInitialPoint(); - auto termination_condition = [&wrong_orientation, t_target, - t_tol](const Vector &point) { - const double wrong_orientation_tol = -1.0e-4; - if (point[1] < wrong_orientation_tol) { - wrong_orientation = true; - return true; - } - return (point[1] >= t_target + t_tol); - }; + 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, - [&system](const Vector &point) { - 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) { - std::cout << prob_vector[i] << " "; - } - std::cout << std::endl; - }, - criterion_function); - if (!wrong_orientation) { - break; - } + 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, p_omega, termination_condition, + [&system](const Vector &point) { + 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) { + std::cout << prob_vector[i] << " "; + } + std::cout << std::endl; + }, + criterion_function); - // Direction was wrong, flip the orientation and try again - omega = -1.0; - } const MixedStrategyProfile eq_profile = system.ExtractEquilibrium(x); equilibria.push_back(eq_profile); From 1095a89ee72f890a46921c9975b3f17742e9a44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Fern=C3=A1ndez=20Cervell?= Date: Fri, 7 Aug 2026 14:37:52 +0200 Subject: [PATCH 4/4] Fix --- src/solvers/hp/hp.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solvers/hp/hp.cc b/src/solvers/hp/hp.cc index 6e31a7357..6cdcaf83b 100644 --- a/src/solvers/hp/hp.cc +++ b/src/solvers/hp/hp.cc @@ -37,7 +37,7 @@ HPStrategySolve(const MixedStrategyProfile &p_prior) const PathTracer tracer; Vector x; - const double p_omega = 1.0; + double p_omega = 1.0; const double t_target = 1.0; const double t_tol = 0.5;